summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/SearchService.ts
diff options
context:
space:
mode:
authortaichan <40626578+taichanNE30@users.noreply.github.com>2023-08-20 13:39:37 +0900
committerGitHub <noreply@github.com>2023-08-20 13:39:37 +0900
commitaf806352a1c3701b5d8b2088dcf2154732b00152 (patch)
treefa57d824a837013c00ae71ee2a4669c7cee6880b /packages/backend/src/core/SearchService.ts
parentFix: DB CONSTRAINT of RenoteMuting (#11724) (diff)
downloadsharkey-af806352a1c3701b5d8b2088dcf2154732b00152.tar.gz
sharkey-af806352a1c3701b5d8b2088dcf2154732b00152.tar.bz2
sharkey-af806352a1c3701b5d8b2088dcf2154732b00152.zip
feat: ローカルのみノート検索 (#11451)
* Add local search * Update CHANGELOG * lint * Remove TODO comment * lint * Update packages/backend/src/core/SearchService.ts --------- Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
Diffstat (limited to 'packages/backend/src/core/SearchService.ts')
-rw-r--r--packages/backend/src/core/SearchService.ts14
1 files changed, 13 insertions, 1 deletions
diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts
index ce80744c6d..f21bd790be 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');
}
@@ -170,7 +174,7 @@ 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 });
}
@@ -204,6 +208,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);