diff --git a/packages/backend/src/core/SearchService.ts b/packages/backend/src/core/SearchService.ts index f410891fff..9dc53dafef 100644 --- a/packages/backend/src/core/SearchService.ts +++ b/packages/backend/src/core/SearchService.ts @@ -29,7 +29,6 @@ type Q = { op: 'is not null', k: K} | { op: 'and', qs: Q[] } | { op: 'or', qs: Q[] } | - { op: 'likefile', k: K, v: V } | { op: 'not', q: Q }; function compileValue(value: V): string { @@ -55,7 +54,6 @@ function compileQuery(q: Q): string { 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 'likefile': return `(${q.k}::varchar LIKE ${compileValue(q.v)}))`; case 'not': return `(NOT ${compileQuery(q.q)})`; default: throw new Error('unrecognized query operator'); } @@ -95,7 +93,6 @@ export class SearchService { 'userHost', 'channelId', 'tags', - 'attachedFileTypes', ], typoTolerance: { enabled: false, @@ -163,12 +160,13 @@ export class SearchService { host?: string | null; filetype?: string | null; order?: string | null; + disableMeili?: boolean | null; }, pagination: { untilId?: MiNote['id']; sinceId?: MiNote['id']; limit?: number; }): Promise { - if (this.meilisearch) { + if (this.meilisearch && !opts.disableMeili) { const filter: Q = { op: 'and', qs: [], @@ -177,7 +175,6 @@ 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.filetype) filter.qs.push({ op: 'likefile', k: 'attachedFileTypes', v: `%${opts.filetype}%` }); if (opts.host) { if (opts.host === '.') { filter.qs.push({ op: 'is null', k: 'userHost' }); @@ -222,6 +219,10 @@ export class SearchService { } } + if (opts.filetype) { + query.andWhere(`note."attachedFileTypes"::varchar LIKE '%${opts.filetype}%'`); + } + this.queryService.generateVisibilityQuery(query, me); if (me) this.queryService.generateMutedUserQuery(query, me); if (me) this.queryService.generateBlockedUserQuery(query, me); diff --git a/packages/backend/src/server/api/endpoints/notes/search.ts b/packages/backend/src/server/api/endpoints/notes/search.ts index 06efa3d951..f75249bfb0 100644 --- a/packages/backend/src/server/api/endpoints/notes/search.ts +++ b/packages/backend/src/server/api/endpoints/notes/search.ts @@ -75,6 +75,7 @@ export default class extends Endpoint { // eslint- host: ps.host, filetype: ps.filetype, order: ps.order, + disableMeili: ps.filetype ? true : false, }, { untilId: ps.untilId, sinceId: ps.sinceId, diff --git a/packages/frontend/src/pages/search.note.vue b/packages/frontend/src/pages/search.note.vue index deaa6cfb56..0b1740847d 100644 --- a/packages/frontend/src/pages/search.note.vue +++ b/packages/frontend/src/pages/search.note.vue @@ -74,7 +74,7 @@ let searchOrigin = $ref('combined'); let notePagination = $ref(); let user = $ref(null); let isLocalOnly = $ref(false); -let order = $ref(false); +let order = $ref(true); let filetype = $ref(null); function selectUser() { @@ -112,7 +112,7 @@ async function search() { params: { query: searchQuery, userId: user ? user.id : null, - order: !order ? 'desc' : 'asc', + order: order ? 'desc' : 'asc', filetype: filetype, }, };