mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 03:17:38 -07:00
[backend] Improve postgres FTS filters
This commit is contained in:
parent
5d1bb36be3
commit
e1ae37dbdb
1 changed files with 17 additions and 9 deletions
|
@ -16,10 +16,12 @@ const filters = {
|
||||||
"until": beforeFilter,
|
"until": beforeFilter,
|
||||||
"after": afterFilter,
|
"after": afterFilter,
|
||||||
"since": afterFilter,
|
"since": afterFilter,
|
||||||
"domain": domainFilter,
|
"instance": instanceFilter,
|
||||||
"-domain": domainFilterInverse,
|
"-instance": instanceFilterInverse,
|
||||||
"host": domainFilter,
|
"domain": instanceFilter,
|
||||||
"-host": domainFilterInverse,
|
"-domain": instanceFilterInverse,
|
||||||
|
"host": instanceFilter,
|
||||||
|
"-host": instanceFilterInverse,
|
||||||
"filter": miscFilter,
|
"filter": miscFilter,
|
||||||
"-filter": miscFilterInverse,
|
"-filter": miscFilterInverse,
|
||||||
"has": attachmentFilter,
|
"has": attachmentFilter,
|
||||||
|
@ -131,12 +133,14 @@ function afterFilter(query: SelectQueryBuilder<any>, filter: string) {
|
||||||
query.andWhere('note.createdAt > :after', { after: filter });
|
query.andWhere('note.createdAt > :after', { after: filter });
|
||||||
}
|
}
|
||||||
|
|
||||||
function domainFilter(query: SelectQueryBuilder<any>, filter: string) {
|
function instanceFilter(query: SelectQueryBuilder<any>, filter: string, id: number) {
|
||||||
query.andWhere('note.userHost = :domain', { domain: filter });
|
query.andWhere(`note.userHost = :instance_${id}`);
|
||||||
|
query.setParameter(`instance_${id}`, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
function domainFilterInverse(query: SelectQueryBuilder<any>, filter: string) {
|
function instanceFilterInverse(query: SelectQueryBuilder<any>, filter: string, id: number) {
|
||||||
query.andWhere('note.userHost <> :domain', { domain: filter });
|
query.andWhere(`note.userHost <> :instance_${id}`);
|
||||||
|
query.setParameter(`instance_${id}`, filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
function miscFilter(query: SelectQueryBuilder<any>, filter: string) {
|
function miscFilter(query: SelectQueryBuilder<any>, filter: string) {
|
||||||
|
@ -180,9 +184,13 @@ function miscFilterInverse(query: SelectQueryBuilder<any>, filter: string) {
|
||||||
function attachmentFilter(query: SelectQueryBuilder<any>, filter: string) {
|
function attachmentFilter(query: SelectQueryBuilder<any>, filter: string) {
|
||||||
switch(filter) {
|
switch(filter) {
|
||||||
case 'image':
|
case 'image':
|
||||||
|
query.andWhere(`note."attachedFileTypes"::varchar ILIKE '%image/%'`);
|
||||||
|
break;
|
||||||
case 'video':
|
case 'video':
|
||||||
|
query.andWhere(`note."attachedFileTypes"::varchar ILIKE '%video/%'`);
|
||||||
|
break;
|
||||||
case 'audio':
|
case 'audio':
|
||||||
query.andWhere(`note."attachedFileTypes"::varchar ILIKE :type`, { type: `%${sqlLikeEscape(filter)}/%` });
|
query.andWhere(`note."attachedFileTypes"::varchar ILIKE '%audio/%'`);
|
||||||
break;
|
break;
|
||||||
case 'file':
|
case 'file':
|
||||||
query.andWhere(`note."attachedFileTypes" <> '{}'`);
|
query.andWhere(`note."attachedFileTypes" <> '{}'`);
|
||||||
|
|
Loading…
Reference in a new issue