From 29a84230b0d3216442c955599485be5f6511aa78 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 7 May 2023 11:59:06 +0900 Subject: [PATCH] =?UTF-8?q?enhance(backend):=20SearchService.searchNote?= =?UTF-8?q?=E3=81=A7host=E6=8C=87=E5=AE=9A=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/SearchService.ts | 8 ++++++++ packages/backend/src/server/api/endpoints/notes/search.ts | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 1c18a52fae..e68fde088d 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -117,6 +117,7 @@ export class SearchService { public async searchNote(q: string, me: User | null, opts: { userId?: Note['userId'] | null; channelId?: Note['channelId'] | null; + host?: string | null; }, pagination: { untilId?: Note['id']; sinceId?: Note['id']; @@ -131,6 +132,13 @@ export class SearchService { if (pagination.sinceId) filter.qs.push({ op: '>', k: 'createdAt', v: this.idService.parse(pagination.sinceId).date.getTime() }); if (opts.userId) filter.qs.push({ op: '=', k: 'userId', v: opts.userId }); if (opts.channelId) filter.qs.push({ op: '=', k: 'channelId', v: opts.channelId }); + if (opts.host) { + if (opts.host === '.') { + // TODO: Meilisearchが2023/05/07現在値がNULLかどうかのクエリが書けない + } else { + filter.qs.push({ op: '=', k: 'userHost', v: opts.host }); + } + } const res = await this.meilisearchNoteIndex!.search(q, { sort: ['createdAt:desc'], matchingStrategy: 'all', diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index 990ba526d9..f6385400c3 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -42,8 +42,7 @@ export const paramDef = { offset: { type: 'integer', default: 0 }, host: { type: 'string', - nullable: true, - description: 'The local host is represented with `null`.', + description: 'The local host is represented with `.`.', }, userId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, @@ -73,6 +72,7 @@ export default class extends Endpoint { const notes = await this.searchService.searchNote(ps.query, me, { userId: ps.userId, channelId: ps.channelId, + host: ps.host, }, { untilId: ps.untilId, sinceId: ps.sinceId,