Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

nicer file type search #107

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/backend/src/core/SearchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,18 @@ export class SearchService {
}

if (opts.filetype) {
query.andWhere(`note."attachedFileTypes"::varchar LIKE '%${opts.filetype}%'`);
/* this is very ugly, but the "correct" solution would
be `and exists (select 1 from
unnest(note."attachedFileTypes") x(t) where t like
:type)` and I can't find a way to get TypeORM to
generate that; this hack works because `~*` is
"regexp match, ignoring case" and the stringified
version of an array of varchars (which is what
`attachedFileTypes` is) looks like `{foo,bar}`, so
we're looking for opts.filetype as the first half of
a MIME type, either at start of the array (after the
`{`) or later (after a `,`) */
query.andWhere(`note."attachedFileTypes"::varchar ~* :type`, { type: `[{,]${opts.filetype}/` });
}

this.queryService.generateVisibilityQuery(query, me);
Expand Down
Loading