Skip to content

feat: Implement fuzzy username search using Elasticsearch#10876

Open
Appleple47 wants to merge 17 commits intofeat/179909-username-fuzzy-searchfrom
feat/179909-180048-implement-fuzzy-auditlog-search
Open

feat: Implement fuzzy username search using Elasticsearch#10876
Appleple47 wants to merge 17 commits intofeat/179909-username-fuzzy-searchfrom
feat/179909-180048-implement-fuzzy-auditlog-search

Conversation

@Appleple47
Copy link
Copy Markdown
Contributor

@Appleple47 Appleple47 commented Mar 18, 2026

@Appleple47 Appleple47 force-pushed the feat/179909-username-fuzzy-search branch from 57f3b51 to 42ab20a Compare March 18, 2026 09:47
@Appleple47 Appleple47 force-pushed the feat/179909-180048-implement-fuzzy-auditlog-search branch from 01922a7 to e3de2a0 Compare March 18, 2026 09:47
@Appleple47 Appleple47 force-pushed the feat/179909-180048-implement-fuzzy-auditlog-search branch from e3de2a0 to 78cc663 Compare March 19, 2026 05:35
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API route は activiry ディレクトリ側にあるはずだからそっちに定義した方が良さそうです

loginRequiredStrictly,
adminRequired,
async (req: Request, res: ApiV3Response) => {
const { q = '', offset = 0, limit = 5 } = req.query;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • express-validator による validation をしてください
  • 他の API の実装も参考に req.query から取り出した値に型がつくようにしてください

Comment on lines +780 to +781
(result.aggregations?.unique_usernames as any)?.buckets ?? [];
const usernames = buckets.map((bucket) => bucket.key as string);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここら辺 type safe にできませんか? TS の恩恵がなくなるので as any はなるべく避けたいです。


const body = activities.flatMap((activity) => {
const username = activity.snapshot?.username;
if (!username) return [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +410 to +412
const indexName = 'auditlogs';
const tmpIndexName = 'auditlogs-tmp';
const aliasName = 'auditlogs-alias';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別のメソッドでも使い回す系のて定数はインスタンス変数とかに定義しておいた方が良さそう

<span className="input-group-text">
<span className="material-symbols-outlined">person</span>
</span>
<AsyncTypeahead
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変更理由を書いておいて欲しいです

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AsyncTypeahead のクライアント側フィルタリングがfuzzy検索の結果を除外していると勘違いして Typeahead に変更しましたが、filterBy={() => true} を追加すれば AsyncTypeahead のままでも動くことが発覚したので元に戻しました。

Comment on lines +338 to +342
const q = req.query.q != null ? (req.query.q as string) : '';
const offset =
req.query.offset != null ? parseInt(req.query.offset as string, 10) : 0;
const limit =
req.query.limit != null ? parseInt(req.query.limit as string, 10) : 5;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request を extends した型を使ってみてください。assertion もなるべく使いたくないです。

参考

interface IListPagesRequest
extends Request<undefined, undefined, undefined, LsxApiParams> {
user: IUser;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// biome-ignore lint/suspicious/noTsIgnore: Suppress auto fix by lefthook
// @ts-ignore - Scope type causes "Type instantiation is excessively deep" with tsgo

get-recent-threads.ts では上のコメントをつけて運用しているみたい

Comment thread apps/app/src/server/service/search.ts Outdated
limit,
);

const User = mongoose.model('User');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こんな感じに書くと型がつけられるのでやってみてください

参考

Comment on lines +38 to +43
query('offset').optional().isInt().withMessage('offset must be a number'),
query('limit')
.optional()
.isInt({ max: 100 })
.withMessage('limit must be a number less than or equal to 100'),
],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • .toInt() をつければ req.query.{hoge} で取り出した時に数値に変換された状態で受け取れる
  • parseInt が不要になる

Comment on lines +338 to +342
const q = req.query.q != null ? (req.query.q as string) : '';
const offset =
req.query.offset != null ? parseInt(req.query.offset as string, 10) : 0;
const limit =
req.query.limit != null ? parseInt(req.query.limit as string, 10) : 5;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// biome-ignore lint/suspicious/noTsIgnore: Suppress auto fix by lefthook
// @ts-ignore - Scope type causes "Type instantiation is excessively deep" with tsgo

get-recent-threads.ts では上のコメントをつけて運用しているみたい

@mergify mergify Bot added the queued label Mar 24, 2026
mergify Bot added a commit that referenced this pull request Mar 24, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Mar 24, 2026

Merge Queue Status

This pull request spent 1 minute 3 seconds in the queue, with no time running CI.

Required conditions to merge
  • check-success = test-prod-node24 / build-prod
  • check-success ~= ci-app-launch-dev
  • check-success ~= ci-app-lint
  • check-success ~= ci-app-test
  • check-success ~= test-prod-node24 / launch-prod
  • check-success ~= test-prod-node24 / run-playwright
  • -check-failure ~= ci-app-
  • -check-failure ~= ci-slackbot-
  • -check-failure ~= test-prod-node24 /

Reason

The pull request #10876 has been manually updated

Hint

If you want to requeue this pull request, you can post a @mergifyio queue comment.

@mergify mergify Bot added queued and removed queued labels Mar 24, 2026
mergify Bot added a commit that referenced this pull request Mar 24, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Mar 24, 2026

Merge Queue Status

This pull request spent 4 minutes 57 seconds in the queue, including 4 minutes 39 seconds running CI.

Required conditions to merge
  • -check-failure ~= test-prod-node24 /
  • check-success = test-prod-node24 / build-prod
  • check-success ~= ci-app-launch-dev
  • check-success ~= ci-app-lint
  • check-success ~= ci-app-test
  • check-success ~= test-prod-node24 / launch-prod
  • check-success ~= test-prod-node24 / run-playwright
  • -check-failure ~= ci-app-
  • -check-failure ~= ci-slackbot-

Reason

The merge conditions cannot be satisfied due to failing checks

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

@mergify mergify Bot added dequeued and removed queued labels Mar 24, 2026
@mergify mergify Bot removed the dequeued label Mar 24, 2026
@mergify mergify Bot added the queued label Mar 24, 2026
mergify Bot added a commit that referenced this pull request Mar 24, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Mar 24, 2026

Merge Queue Status

This pull request spent 4 minutes 46 seconds in the queue, including 4 minutes 36 seconds running CI.

Required conditions to merge
  • -check-failure ~= test-prod-node24 /
  • check-success = test-prod-node24 / build-prod
  • check-success ~= ci-app-launch-dev
  • check-success ~= ci-app-lint
  • check-success ~= ci-app-test
  • check-success ~= test-prod-node24 / launch-prod
  • check-success ~= test-prod-node24 / run-playwright
  • -check-failure ~= ci-app-
  • -check-failure ~= ci-slackbot-

Reason

The merge conditions cannot be satisfied due to failing checks

Failing checks:

Hint

You may have to fix your CI before adding the pull request to the queue again.
If you update this pull request, to fix the CI, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

@mergify mergify Bot added dequeued and removed queued labels Mar 24, 2026
@miya miya requested a review from yuki-takei March 24, 2026 15:07
@mergify mergify Bot removed the dequeued label Mar 26, 2026
@yuki-takei
Copy link
Copy Markdown
Contributor

yuki-takei commented Mar 27, 2026

@Appleple47
Activity Log は mongodb に永続化されるデータだが、 ttl を利用して時間ベースでデータを削除する仕組みになっている
expireAfterSeconds でリポジトリ内を検索してほしい

そのため、今のままではMongoDB の TTL によって古いドキュメントが削除された場合に、対応する ES 側のドキュメントが削除されないという問題がある

ES 側にも ILM (Index Lifecycle Management) を設定する必要があるのではないか?

MongoDB v8.2 も一応選択肢ではあるが、現時点では ES による実装の方針は正しいと思う

);

router.get(
'/usernames',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slack で相談を受けている UI 案を見ると、username だけのエンドポイントを作るのは全体設計に対してずれがあるんじゃないか?

あと REST API の設計として GET /api/v3/activity/usernames というエンドポイントから検索する挙動は想像できない
エンドポイントURLを工夫してほしい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants