From a51e18db331c6ddec86d8c2b1b0cca369625b360 Mon Sep 17 00:00:00 2001 From: taichanne30 Date: Thu, 3 Aug 2023 10:34:53 +0900 Subject: [PATCH 1/5] Add local search --- packages/backend/src/core/SearchService.ts | 13 ++++++++++ packages/frontend/src/pages/search.note.vue | 28 +++++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 88b368dd22..26fff87486 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -25,6 +25,8 @@ type Q = { op: '<', k: K, v: number } | { op: '>=', k: K, v: number } | { op: '<=', k: K, v: number } | + { op: 'is null', k: K} | + { op: 'is not null', k: K} | { op: 'and', qs: Q[] } | { op: 'or', qs: Q[] } | { op: 'not', q: Q }; @@ -50,6 +52,8 @@ function compileQuery(q: Q): string { case '<=': return `(${q.k} <= ${compileValue(q.v)})`; case 'and': return q.qs.length === 0 ? '' : `(${ q.qs.map(_q => compileQuery(_q)).join(' AND ') })`; case 'or': return q.qs.length === 0 ? '' : `(${ q.qs.map(_q => compileQuery(_q)).join(' OR ') })`; + case 'is null': return `(${q.k} IS NULL)`; + case 'is not null': return `(${q.k} IS NOT NULL)`; case 'not': return `(NOT ${compileQuery(q.q)})`; default: throw new Error('unrecognized query operator'); } @@ -171,6 +175,7 @@ export class SearchService { if (opts.host) { if (opts.host === '.') { // TODO: Meilisearchが2023/05/07現在値がNULLかどうかのクエリが書けない + filter.qs.push({op: 'is null', k: 'userHost'}) } else { filter.qs.push({ op: '=', k: 'userHost', v: opts.host }); } @@ -204,6 +209,14 @@ export class SearchService { .leftJoinAndSelect('reply.user', 'replyUser') .leftJoinAndSelect('renote.user', 'renoteUser'); + if (opts.host) { + if (opts.host === '.') { + query.andWhere('user.host IS NULL ') + } else { + query.andWhere('user.host = :host', { host: opts.host }) + } + } + this.queryService.generateVisibilityQuery(query, me); if (me) this.queryService.generateMutedUserQuery(query, me); if (me) this.queryService.generateBlockedUserQuery(query, me); diff --git a/packages/frontend/src/pages/search.note.vue b/packages/frontend/src/pages/search.note.vue index 799dac2096..f0a958d77b 100644 --- a/packages/frontend/src/pages/search.note.vue +++ b/packages/frontend/src/pages/search.note.vue @@ -12,18 +12,22 @@ SPDX-License-Identifier: AGPL-3.0-only - - - +
+ {{ i18n.ts.localOnly }} -
-
@{{ user.username }}
-
- {{ i18n.ts.selectUser }} - {{ i18n.ts.remove }} + + + + +
+
@{{ user.username }}
+
+ {{ i18n.ts.selectUser }} + {{ i18n.ts.remove }} +
-
- + +
{{ i18n.ts.search }} @@ -43,6 +47,7 @@ import MkNotes from '@/components/MkNotes.vue'; import MkInput from '@/components/MkInput.vue'; import MkRadios from '@/components/MkRadios.vue'; import MkButton from '@/components/MkButton.vue'; +import MkSwitch from '@/components/MkSwitch.vue'; import { i18n } from '@/i18n'; import * as os from '@/os'; import MkFoldableSection from '@/components/MkFoldableSection.vue'; @@ -59,6 +64,7 @@ let searchQuery = $ref(''); let searchOrigin = $ref('combined'); let notePagination = $ref(); let user = $ref(null); +let isLocalOnly = $ref(false); function selectUser() { os.selectUser().then(_user => { @@ -98,6 +104,8 @@ async function search() { }, }; + if (isLocalOnly) notePagination.params.host = '.' + key++; } From 791a0b133e38c74ee75ec6af919ab70bb66bc2e5 Mon Sep 17 00:00:00 2001 From: taichanne30 Date: Thu, 3 Aug 2023 11:03:54 +0900 Subject: [PATCH 2/5] Update CHANGELOG --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10ddc33d9d..c39d73b671 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,11 +21,12 @@ - メニューのスイッチの動作を改善 - Enhance: ユーザーメニューでスイッチでユーザーリストに追加・削除できるように - Enhance: 自分が押したリアクションのデザインを改善 +- Enhance: ノート検索にローカルのみ検索可能なオプションの追加 - Fix: サーバー情報画面(`/instance-info/{domain}`)でブロックができないのを修正 - Fix: 未読のお知らせの「わかった」をクリック・タップしてもその場で「わかった」が消えない問題を修正 ### Server -- +- Fix: ノート検索 `notes/search` にてhostを指定した際に検索結果に反映されるように ## 13.14.2 From 209bad9738e726b7b9b90cddfcf4691958ff71a2 Mon Sep 17 00:00:00 2001 From: taichanne30 Date: Thu, 3 Aug 2023 11:04:55 +0900 Subject: [PATCH 3/5] lint --- packages/backend/src/core/SearchService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 26fff87486..147239f514 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -175,7 +175,7 @@ export class SearchService { if (opts.host) { if (opts.host === '.') { // TODO: Meilisearchが2023/05/07現在値がNULLかどうかのクエリが書けない - filter.qs.push({op: 'is null', k: 'userHost'}) + filter.qs.push({ op: 'is null', k: 'userHost' }); } else { filter.qs.push({ op: '=', k: 'userHost', v: opts.host }); } @@ -211,9 +211,9 @@ export class SearchService { if (opts.host) { if (opts.host === '.') { - query.andWhere('user.host IS NULL ') + query.andWhere('user.host IS NULL '); } else { - query.andWhere('user.host = :host', { host: opts.host }) + query.andWhere('user.host = :host', { host: opts.host }); } } From f40f6b006b1ba4fda80c7719b18e34df6b794e29 Mon Sep 17 00:00:00 2001 From: taichanne30 Date: Thu, 3 Aug 2023 11:32:00 +0900 Subject: [PATCH 4/5] Remove TODO comment --- packages/backend/src/core/SearchService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index 147239f514..9cab9bf89e 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -174,7 +174,6 @@ export class SearchService { if (opts.channelId) filter.qs.push({ op: '=', k: 'channelId', v: opts.channelId }); if (opts.host) { if (opts.host === '.') { - // TODO: Meilisearchが2023/05/07現在値がNULLかどうかのクエリが書けない filter.qs.push({ op: 'is null', k: 'userHost' }); } else { filter.qs.push({ op: '=', k: 'userHost', v: opts.host }); From 76d71da42b564012ce56dd77f582ddbc5b226776 Mon Sep 17 00:00:00 2001 From: taichanne30 Date: Thu, 3 Aug 2023 11:36:38 +0900 Subject: [PATCH 5/5] lint --- packages/frontend/src/pages/search.note.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend/src/pages/search.note.vue b/packages/frontend/src/pages/search.note.vue index f0a958d77b..b0881fdedb 100644 --- a/packages/frontend/src/pages/search.note.vue +++ b/packages/frontend/src/pages/search.note.vue @@ -104,7 +104,7 @@ async function search() { }, }; - if (isLocalOnly) notePagination.params.host = '.' + if (isLocalOnly) notePagination.params.host = '.'; key++; }