forked from woem.men/forkey
fix(search): elasticsearchに登録されたノートが削除された場合にunindexされないのを修正 (MisskeyIO#718)
This commit is contained in:
commit
8692712ac4
1 changed files with 12 additions and 4 deletions
|
@ -172,6 +172,7 @@ export class SearchService {
|
||||||
if (note.text == null && note.cw == null) return;
|
if (note.text == null && note.cw == null) return;
|
||||||
if (!['home', 'public'].includes(note.visibility)) return;
|
if (!['home', 'public'].includes(note.visibility)) return;
|
||||||
|
|
||||||
|
const createdAt = this.idService.parse(note.id).date;
|
||||||
if (this.meilisearch) {
|
if (this.meilisearch) {
|
||||||
switch (this.meilisearchIndexScope) {
|
switch (this.meilisearchIndexScope) {
|
||||||
case 'global':
|
case 'global':
|
||||||
|
@ -190,7 +191,7 @@ export class SearchService {
|
||||||
|
|
||||||
await this.meilisearchNoteIndex?.addDocuments([{
|
await this.meilisearchNoteIndex?.addDocuments([{
|
||||||
id: note.id,
|
id: note.id,
|
||||||
createdAt: this.idService.parse(note.id).date.getTime(),
|
createdAt: createdAt.getTime(),
|
||||||
userId: note.userId,
|
userId: note.userId,
|
||||||
userHost: note.userHost,
|
userHost: note.userHost,
|
||||||
channelId: note.channelId,
|
channelId: note.channelId,
|
||||||
|
@ -202,7 +203,7 @@ export class SearchService {
|
||||||
});
|
});
|
||||||
} else if (this.elasticsearch) {
|
} else if (this.elasticsearch) {
|
||||||
const body = {
|
const body = {
|
||||||
createdAt: this.idService.parse(note.id).date.getTime(),
|
createdAt: createdAt.getTime(),
|
||||||
userId: note.userId,
|
userId: note.userId,
|
||||||
userHost: note.userHost,
|
userHost: note.userHost,
|
||||||
channelId: note.channelId,
|
channelId: note.channelId,
|
||||||
|
@ -211,11 +212,11 @@ export class SearchService {
|
||||||
tags: note.tags,
|
tags: note.tags,
|
||||||
};
|
};
|
||||||
await this.elasticsearch.index({
|
await this.elasticsearch.index({
|
||||||
index: this.elasticsearchNoteIndex + `-${new Date().toISOString().slice(0, 7).replace(/-/g, '')}` as string,
|
index: `${this.elasticsearchNoteIndex}-${createdAt.toISOString().slice(0, 7).replace(/-/g, '')}`,
|
||||||
id: note.id,
|
id: note.id,
|
||||||
body: body,
|
body: body,
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
console.error(error);
|
this.logger.error(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,6 +227,13 @@ export class SearchService {
|
||||||
|
|
||||||
if (this.meilisearch) {
|
if (this.meilisearch) {
|
||||||
this.meilisearchNoteIndex!.deleteDocument(note.id);
|
this.meilisearchNoteIndex!.deleteDocument(note.id);
|
||||||
|
} else if (this.elasticsearch) {
|
||||||
|
await this.elasticsearch.delete({
|
||||||
|
index: `${this.elasticsearchNoteIndex}-${this.idService.parse(note.id).date.toISOString().slice(0, 7).replace(/-/g, '')}`,
|
||||||
|
id: note.id,
|
||||||
|
}).catch((error) => {
|
||||||
|
this.logger.error(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue