mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 15:34:13 +00: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: '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<MiNote[]> {
 | 
			
		||||
		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);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,6 +75,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
 | 
			
		|||
				host: ps.host,
 | 
			
		||||
				filetype: ps.filetype,
 | 
			
		||||
				order: ps.order,
 | 
			
		||||
				disableMeili: ps.filetype ? true : false,
 | 
			
		||||
			}, {
 | 
			
		||||
				untilId: ps.untilId,
 | 
			
		||||
				sinceId: ps.sinceId,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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,
 | 
			
		||||
		},
 | 
			
		||||
	};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue