mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-23 03:03:08 +02:00
upd: search filters
This commit is contained in:
parent
d392edbc6b
commit
a74c7f60b5
3 changed files with 9 additions and 7 deletions
|
@ -29,7 +29,6 @@ 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 {
|
||||||
|
@ -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 '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');
|
||||||
}
|
}
|
||||||
|
@ -95,7 +93,6 @@ export class SearchService {
|
||||||
'userHost',
|
'userHost',
|
||||||
'channelId',
|
'channelId',
|
||||||
'tags',
|
'tags',
|
||||||
'attachedFileTypes',
|
|
||||||
],
|
],
|
||||||
typoTolerance: {
|
typoTolerance: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
@ -163,12 +160,13 @@ export class SearchService {
|
||||||
host?: string | null;
|
host?: string | null;
|
||||||
filetype?: string | null;
|
filetype?: string | null;
|
||||||
order?: string | null;
|
order?: string | null;
|
||||||
|
disableMeili?: boolean | null;
|
||||||
}, pagination: {
|
}, pagination: {
|
||||||
untilId?: MiNote['id'];
|
untilId?: MiNote['id'];
|
||||||
sinceId?: MiNote['id'];
|
sinceId?: MiNote['id'];
|
||||||
limit?: number;
|
limit?: number;
|
||||||
}): Promise<MiNote[]> {
|
}): Promise<MiNote[]> {
|
||||||
if (this.meilisearch) {
|
if (this.meilisearch && !opts.disableMeili) {
|
||||||
const filter: Q = {
|
const filter: Q = {
|
||||||
op: 'and',
|
op: 'and',
|
||||||
qs: [],
|
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 (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' });
|
||||||
|
@ -222,6 +219,10 @@ export class SearchService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (opts.filetype) {
|
||||||
|
query.andWhere(`note."attachedFileTypes"::varchar LIKE '%${opts.filetype}%'`);
|
||||||
|
}
|
||||||
|
|
||||||
this.queryService.generateVisibilityQuery(query, me);
|
this.queryService.generateVisibilityQuery(query, me);
|
||||||
if (me) this.queryService.generateMutedUserQuery(query, me);
|
if (me) this.queryService.generateMutedUserQuery(query, me);
|
||||||
if (me) this.queryService.generateBlockedUserQuery(query, me);
|
if (me) this.queryService.generateBlockedUserQuery(query, me);
|
||||||
|
|
|
@ -75,6 +75,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
||||||
host: ps.host,
|
host: ps.host,
|
||||||
filetype: ps.filetype,
|
filetype: ps.filetype,
|
||||||
order: ps.order,
|
order: ps.order,
|
||||||
|
disableMeili: ps.filetype ? true : false,
|
||||||
}, {
|
}, {
|
||||||
untilId: ps.untilId,
|
untilId: ps.untilId,
|
||||||
sinceId: ps.sinceId,
|
sinceId: ps.sinceId,
|
||||||
|
|
|
@ -74,7 +74,7 @@ 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 order = $ref(true);
|
||||||
let filetype = $ref(null);
|
let filetype = $ref(null);
|
||||||
|
|
||||||
function selectUser() {
|
function selectUser() {
|
||||||
|
@ -112,7 +112,7 @@ async function search() {
|
||||||
params: {
|
params: {
|
||||||
query: searchQuery,
|
query: searchQuery,
|
||||||
userId: user ? user.id : null,
|
userId: user ? user.id : null,
|
||||||
order: !order ? 'desc' : 'asc',
|
order: order ? 'desc' : 'asc',
|
||||||
filetype: filetype,
|
filetype: filetype,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue