From 9e330c9e38175012e4ca8f81ce9d3f05b7db7510 Mon Sep 17 00:00:00 2001 From: まっちゃとーにゅ <17376330+u1-liquid@users.noreply.github.com> Date: Sat, 15 Jul 2023 09:59:19 +0900 Subject: feat: MeilisearchにIndexするノートの範囲を設定できるように (#11282) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/config.ts | 1 + packages/backend/src/core/SearchService.ts | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'packages/backend/src') 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, -- cgit v1.2.3-freya