From a51e18db331c6ddec86d8c2b1b0cca369625b360 Mon Sep 17 00:00:00 2001 From: taichanne30 Date: Thu, 3 Aug 2023 10:34:53 +0900 Subject: [PATCH] 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++; }