Skip to content

Commit

Permalink
feat: MeilisearchにIndexするノートの範囲を設定できるように
Browse files Browse the repository at this point in the history
  • Loading branch information
u1-liquid committed Jul 8, 2023
1 parent b77e736 commit 064a63e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions .config/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ redis:
# apiKey: ''
# ssl: true
# index: ''
# scope: local

# ┌───────────────┐
#───┘ ID generation └───────────────────────────────────────────
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export type Source = {
apiKey: string;
ssl?: boolean;
index: string;
scope?: 'local' | 'global' | string[];
};

proxy?: string;
Expand Down
22 changes: 21 additions & 1 deletion packages/backend/src/core/SearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -92,6 +93,10 @@ export class SearchService {
},
});
}

if (config.meilisearch?.scope) {
this.meilisearchIndexScope = config.meilisearch.scope;
}
}

@bindThis
Expand All @@ -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,
Expand Down

0 comments on commit 064a63e

Please sign in to comment.