mirror of
https://github.com/MisskeyIO/misskey
synced 2024-11-27 14:28:49 +09:00
feat: MeilisearchにIndexするノートの範囲を設定できるように (#11282)
This commit is contained in:
parent
02957a1b5d
commit
9e330c9e38
@ -104,6 +104,7 @@ redis:
|
|||||||
# apiKey: ''
|
# apiKey: ''
|
||||||
# ssl: true
|
# ssl: true
|
||||||
# index: ''
|
# index: ''
|
||||||
|
# scope: local
|
||||||
|
|
||||||
# ┌───────────────┐
|
# ┌───────────────┐
|
||||||
#───┘ ID generation └───────────────────────────────────────────
|
#───┘ ID generation └───────────────────────────────────────────
|
||||||
|
@ -63,6 +63,7 @@ export type Source = {
|
|||||||
apiKey: string;
|
apiKey: string;
|
||||||
ssl?: boolean;
|
ssl?: boolean;
|
||||||
index: string;
|
index: string;
|
||||||
|
scope?: 'local' | 'global' | string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
proxy?: string;
|
proxy?: string;
|
||||||
|
@ -52,6 +52,7 @@ function compileQuery(q: Q): string {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SearchService {
|
export class SearchService {
|
||||||
|
private readonly meilisearchIndexScope: 'local' | 'global' | string[] = 'local';
|
||||||
private meilisearchNoteIndex: Index | null = null;
|
private meilisearchNoteIndex: Index | null = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -92,6 +93,10 @@ export class SearchService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.meilisearch?.scope) {
|
||||||
|
this.meilisearchIndexScope = config.meilisearch.scope;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
@ -100,7 +105,22 @@ export class SearchService {
|
|||||||
if (!['home', 'public'].includes(note.visibility)) return;
|
if (!['home', 'public'].includes(note.visibility)) return;
|
||||||
|
|
||||||
if (this.meilisearch) {
|
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,
|
id: note.id,
|
||||||
createdAt: note.createdAt.getTime(),
|
createdAt: note.createdAt.getTime(),
|
||||||
userId: note.userId,
|
userId: note.userId,
|
||||||
|
Loading…
Reference in New Issue
Block a user