Skip to content

Commit

Permalink
Fixed searching by with tags and actors
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyBoo6 committed Jan 12, 2024
1 parent 922564b commit a3b8050
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions server/src/database/sqlite/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,16 @@ export interface QueryObj {
values: unknown[];
}

export interface HavingQuery {
join: QueryObj;
having: QueryObj;
}

function buildArrayFilter(table: string, field: string, filter: ArrayFilter | undefined): QueryObj | undefined {
if (filter === undefined) {
return undefined;
}
const joinBase =
'LEFT JOIN ' + table + ' ON `media`.`hash` = ' + table + '.`media_hash` GROUP BY `media`.`hash` HAVING ';

const havings: string[] = [];
const values: unknown[] = [];
if (filter.equalsAny) {
Expand All @@ -312,7 +316,20 @@ function buildArrayFilter(table: string, field: string, filter: ArrayFilter | un
if (havings.length === 0) {
return undefined;
}
return { query: joinBase + havings.join(' AND '), values };

const innerSelect =
'SELECT `media`.`hash` FROM `media` LEFT JOIN ' +
table +
' ON `media`.`hash` = ' +
table +
'.`media_hash` GROUP BY `media`.`hash` HAVING ' +
havings.join(' AND ');

return {
// Doesn't work because still matches equalsNone when it has them.
query: 'INNER JOIN (' + innerSelect + ') AS ' + table + ' ON ' + table + '.`hash` = `media`.`hash`',
values,
};
}

function joinQueries(queries: QueryObj[], operator: 'AND' | 'OR'): QueryObj | undefined {
Expand Down

0 comments on commit a3b8050

Please sign in to comment.