From c6555c2cf2954dcf53194f2a6f020415de2bca17 Mon Sep 17 00:00:00 2001 From: FruitRiin Date: Sat, 26 Apr 2025 11:51:47 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=8E=E3=83=BC=E3=83=88=E6=A4=9C=E7=B4=A2?= =?UTF-8?q?=E5=BC=B7=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/SearchService.ts | 25 +++++++- .../src/server/api/endpoints/notes/search.ts | 2 + packages/frontend/src/pages/search.note.vue | 57 +++++++++++++++---- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 71dc718916..6c8aa2f846 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -38,6 +38,7 @@ export type SearchOpts = { userId?: MiNote['userId'] | null; channelId?: MiNote['channelId'] | null; host?: string | null; + searchFrom? : string | null; }; export type SearchPagination = { @@ -184,6 +185,7 @@ export class SearchService { case 'sqlPgroonga': { // ほとんど内容に差がないのでsqlLikeとsqlPgroongaを同じ処理にしている. // 今後の拡張で差が出る用であれば関数を分ける. + return this.searchNoteByLike(q, me, opts, pagination); } case 'meilisearch': { @@ -220,10 +222,27 @@ export class SearchService { .leftJoinAndSelect('renote.user', 'renoteUser'); if (this.config.fulltextSearch?.provider === 'sqlPgroonga') { - query.andWhere('note.text &@~ :q', { q }); + // pgroonga + if(opts.searchFrom === 'textWithCw'){ + // textWithCwオプション + query.andWhere('(coalesce(note.cw, \'\') || note.text) &@~ :q', { q }); + }else { + // 通常検索 + query.andWhere('note.text &@~ :q', { q }); + } + + } else { - query.andWhere('LOWER(note.text) LIKE :q', { q: `%${ sqlLikeEscape(q.toLowerCase()) }%` }); - } + // Postgresql 標準 + if(opts.searchFrom === 'textWithCw'){ + // textWithCwオプション + query.andWhere('LOWER((coalesce(note.cw, \'\') || note.text)) LIKE :q', { q: `%${ sqlLikeEscape(q.toLowerCase()) }%` }); + }else { + // 通常検索 + query.andWhere('LOWER(note.text) LIKE :q', { q: `%${ sqlLikeEscape(q.toLowerCase()) }%` }); + } + + } if (opts.host) { if (opts.host === '.') { diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index ab1bd934fb..c42475cb18 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -51,6 +51,7 @@ export const paramDef = { }, userId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, + searchFrom: { type: 'string', nullable: true, default: null }, }, required: ['query'], } as const; @@ -78,6 +79,7 @@ export default class extends Endpoint { // eslint- userId: ps.userId, channelId: ps.channelId, host: ps.host, + searchFrom: ps.searchFrom }, { untilId: untilId, sinceId: sinceId, diff --git a/packages/frontend/src/pages/search.note.vue b/packages/frontend/src/pages/search.note.vue index fb34d592a6..6692d89b36 100644 --- a/packages/frontend/src/pages/search.note.vue +++ b/packages/frontend/src/pages/search.note.vue @@ -15,8 +15,8 @@ SPDX-License-Identifier: AGPL-3.0-only > - - +
+
{{ i18n.ts.options }}
@@ -26,6 +26,11 @@ SPDX-License-Identifier: AGPL-3.0-only + + + + +
- +
{{ i18n.ts.search }} + +
- - +
+
{{ i18n.ts.searchResult }}
- +