diff options
| author | まっちゃとーにゅ <17376330+u1-liquid@users.noreply.github.com> | 2023-07-15 09:59:19 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-15 09:59:19 +0900 |
| commit | 9e330c9e38175012e4ca8f81ce9d3f05b7db7510 (patch) | |
| tree | 456a5779ff76864745f16fea41f5f872e137b509 | |
| parent | enhance: 招待機能の改善 (#11195) (diff) | |
| download | sharkey-9e330c9e38175012e4ca8f81ce9d3f05b7db7510.tar.gz sharkey-9e330c9e38175012e4ca8f81ce9d3f05b7db7510.tar.bz2 sharkey-9e330c9e38175012e4ca8f81ce9d3f05b7db7510.zip | |
feat: MeilisearchにIndexするノートの範囲を設定できるように (#11282)
| -rw-r--r-- | .config/example.yml | 1 | ||||
| -rw-r--r-- | packages/backend/src/config.ts | 1 | ||||
| -rw-r--r-- | packages/backend/src/core/SearchService.ts | 22 |
3 files changed, 23 insertions, 1 deletions
diff --git a/.config/example.yml b/.config/example.yml index c179395966..c8735bf699 100644 --- a/.config/example.yml +++ b/.config/example.yml @@ -104,6 +104,7 @@ redis: # apiKey: '' # ssl: true # index: '' +# scope: local # ┌───────────────┐ #───┘ ID generation └─────────────────────────────────────────── diff --git a/packages/backend/src/config.ts b/packages/backend/src/config.ts index 9d1945e4d4..23ed6e59bc 100644 --- a/packages/backend/src/config.ts +++ b/packages/backend/src/config.ts @@ -63,6 +63,7 @@ export type Source = { apiKey: string; ssl?: boolean; index: string; + scope?: 'local' | 'global' | string[]; }; proxy?: string; diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 28b8ee8073..392799da75 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -52,6 +52,7 @@ function compileQuery(q: Q): string { @Injectable() export class SearchService { + private readonly meilisearchIndexScope: 'local' | 'global' | string[] = 'local'; private meilisearchNoteIndex: Index | null = null; constructor( @@ -92,6 +93,10 @@ export class SearchService { }, }); } + + if (config.meilisearch?.scope) { + this.meilisearchIndexScope = config.meilisearch.scope; + } } @bindThis @@ -100,7 +105,22 @@ export class SearchService { if (!['home', 'public'].includes(note.visibility)) return; if (this.meilisearch) { - this.meilisearchNoteIndex!.addDocuments([{ + switch (this.meilisearchIndexScope) { + case 'global': + break; + + case 'local': + if (note.userHost == null) break; + return; + + default: { + if (note.userHost == null) break; + if (this.meilisearchIndexScope.includes(note.userHost)) break; + return; + } + } + + await this.meilisearchNoteIndex?.addDocuments([{ id: note.id, createdAt: note.createdAt.getTime(), userId: note.userId, |