test: more search options
This commit is contained in:
parent
4a90464f03
commit
d392edbc6b
3 changed files with 24 additions and 1 deletions
|
@ -29,6 +29,7 @@ type Q =
|
||||||
{ op: 'is not null', k: K} |
|
{ op: 'is not null', k: K} |
|
||||||
{ op: 'and', qs: Q[] } |
|
{ op: 'and', qs: Q[] } |
|
||||||
{ op: 'or', qs: Q[] } |
|
{ op: 'or', qs: Q[] } |
|
||||||
|
{ op: 'likefile', k: K, v: V } |
|
||||||
{ op: 'not', q: Q };
|
{ op: 'not', q: Q };
|
||||||
|
|
||||||
function compileValue(value: V): string {
|
function compileValue(value: V): string {
|
||||||
|
@ -54,6 +55,7 @@ function compileQuery(q: Q): string {
|
||||||
case 'or': return q.qs.length === 0 ? '' : `(${ q.qs.map(_q => compileQuery(_q)).join(' OR ') })`;
|
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 null': return `(${q.k} IS NULL)`;
|
||||||
case 'is not null': return `(${q.k} IS NOT 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)})`;
|
case 'not': return `(NOT ${compileQuery(q.q)})`;
|
||||||
default: throw new Error('unrecognized query operator');
|
default: throw new Error('unrecognized query operator');
|
||||||
}
|
}
|
||||||
|
@ -93,6 +95,7 @@ export class SearchService {
|
||||||
'userHost',
|
'userHost',
|
||||||
'channelId',
|
'channelId',
|
||||||
'tags',
|
'tags',
|
||||||
|
'attachedFileTypes',
|
||||||
],
|
],
|
||||||
typoTolerance: {
|
typoTolerance: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -158,6 +161,8 @@ export class SearchService {
|
||||||
userId?: MiNote['userId'] | null;
|
userId?: MiNote['userId'] | null;
|
||||||
channelId?: MiNote['channelId'] | null;
|
channelId?: MiNote['channelId'] | null;
|
||||||
host?: string | null;
|
host?: string | null;
|
||||||
|
filetype?: string | null;
|
||||||
|
order?: string | null;
|
||||||
}, pagination: {
|
}, pagination: {
|
||||||
untilId?: MiNote['id'];
|
untilId?: MiNote['id'];
|
||||||
sinceId?: MiNote['id'];
|
sinceId?: MiNote['id'];
|
||||||
|
@ -172,6 +177,7 @@ export class SearchService {
|
||||||
if (pagination.sinceId) filter.qs.push({ op: '>', k: 'createdAt', v: this.idService.parse(pagination.sinceId).date.getTime() });
|
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.userId) filter.qs.push({ op: '=', k: 'userId', v: opts.userId });
|
||||||
if (opts.channelId) filter.qs.push({ op: '=', k: 'channelId', v: opts.channelId });
|
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) {
|
||||||
if (opts.host === '.') {
|
if (opts.host === '.') {
|
||||||
filter.qs.push({ op: 'is null', k: 'userHost' });
|
filter.qs.push({ op: 'is null', k: 'userHost' });
|
||||||
|
@ -180,7 +186,7 @@ export class SearchService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const res = await this.meilisearchNoteIndex!.search(q, {
|
const res = await this.meilisearchNoteIndex!.search(q, {
|
||||||
sort: ['createdAt:desc'],
|
sort: [`createdAt:${opts.order}`],
|
||||||
matchingStrategy: 'all',
|
matchingStrategy: 'all',
|
||||||
attributesToRetrieve: ['id', 'createdAt'],
|
attributesToRetrieve: ['id', 'createdAt'],
|
||||||
filter: compileQuery(filter),
|
filter: compileQuery(filter),
|
||||||
|
|
|
@ -46,8 +46,10 @@ export const paramDef = {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'The local host is represented with `.`.',
|
description: 'The local host is represented with `.`.',
|
||||||
},
|
},
|
||||||
|
filetype: { type: 'string', nullable: true },
|
||||||
userId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
|
userId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
|
||||||
channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
|
channelId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
|
||||||
|
order: { type: 'string' },
|
||||||
},
|
},
|
||||||
required: ['query'],
|
required: ['query'],
|
||||||
} as const;
|
} as const;
|
||||||
|
@ -71,6 +73,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
userId: ps.userId,
|
userId: ps.userId,
|
||||||
channelId: ps.channelId,
|
channelId: ps.channelId,
|
||||||
host: ps.host,
|
host: ps.host,
|
||||||
|
filetype: ps.filetype,
|
||||||
|
order: ps.order,
|
||||||
}, {
|
}, {
|
||||||
untilId: ps.untilId,
|
untilId: ps.untilId,
|
||||||
sinceId: ps.sinceId,
|
sinceId: ps.sinceId,
|
||||||
|
|
|
@ -14,6 +14,14 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
<div class="_gaps_m">
|
<div class="_gaps_m">
|
||||||
<MkSwitch v-model="isLocalOnly">{{ i18n.ts.localOnly }}</MkSwitch>
|
<MkSwitch v-model="isLocalOnly">{{ i18n.ts.localOnly }}</MkSwitch>
|
||||||
|
<MkSwitch v-model="order">Sort by newest to oldest</MkSwitch>
|
||||||
|
<MkSelect v-model="filetype" small>
|
||||||
|
<template #label>File Type</template>
|
||||||
|
<option :value="null">None</option>
|
||||||
|
<option value="image">Images</option>
|
||||||
|
<option value="video">Videos</option>
|
||||||
|
<option value="audio">Audio</option>
|
||||||
|
</MkSelect>
|
||||||
|
|
||||||
<MkFolder>
|
<MkFolder>
|
||||||
<template #label>{{ i18n.ts.specifyUser }}</template>
|
<template #label>{{ i18n.ts.specifyUser }}</template>
|
||||||
|
@ -48,6 +56,7 @@ import MkInput from '@/components/MkInput.vue';
|
||||||
import MkRadios from '@/components/MkRadios.vue';
|
import MkRadios from '@/components/MkRadios.vue';
|
||||||
import MkButton from '@/components/MkButton.vue';
|
import MkButton from '@/components/MkButton.vue';
|
||||||
import MkSwitch from '@/components/MkSwitch.vue';
|
import MkSwitch from '@/components/MkSwitch.vue';
|
||||||
|
import MkSelect from '@/components/MkSelect.vue';
|
||||||
import { i18n } from '@/i18n.js';
|
import { i18n } from '@/i18n.js';
|
||||||
import * as os from '@/os.js';
|
import * as os from '@/os.js';
|
||||||
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
import MkFoldableSection from '@/components/MkFoldableSection.vue';
|
||||||
|
@ -65,6 +74,8 @@ let searchOrigin = $ref('combined');
|
||||||
let notePagination = $ref();
|
let notePagination = $ref();
|
||||||
let user = $ref(null);
|
let user = $ref(null);
|
||||||
let isLocalOnly = $ref(false);
|
let isLocalOnly = $ref(false);
|
||||||
|
let order = $ref(false);
|
||||||
|
let filetype = $ref(null);
|
||||||
|
|
||||||
function selectUser() {
|
function selectUser() {
|
||||||
os.selectUser().then(_user => {
|
os.selectUser().then(_user => {
|
||||||
|
@ -101,6 +112,8 @@ async function search() {
|
||||||
params: {
|
params: {
|
||||||
query: searchQuery,
|
query: searchQuery,
|
||||||
userId: user ? user.id : null,
|
userId: user ? user.id : null,
|
||||||
|
order: !order ? 'desc' : 'asc',
|
||||||
|
filetype: filetype,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue