Skip to content

Commit

Permalink
use infix search for originalPath property
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Otto committed Aug 8, 2024
1 parent e567554 commit c7fb772
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions e2e/src/api/specs/search.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ describe('/search', () => {
should: 'should search by takenAfter (no results)',
deferred: () => ({ dto: { takenAfter: today.plus({ hour: 1 }).toJSDate() }, assets: [] }),
},
// Disabled:
// For uploaded files, the path is replaced by random UUIDs, which is why we cannot test accordingly:
// Before: /albums/nature/prairie_falcon.jpg
// After: upload/upload/3f2086a6-724a-4850-8718-e9fb27340473/d6/dc/d6dc2da1-7f90-4df0-9f32-e5de3612cc9e.jpg
// See server/src/middleware/file-upload.interceptor.ts:getFile()
// {
// should: 'should search by originalPath',
// deferred: () => ({
Expand Down
8 changes: 7 additions & 1 deletion server/src/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ export function searchAssetBuilder(
builder.andWhere(`${builder.alias}.ownerId IN (:...userIds)`, { userIds: options.userIds });
}

const path = _.pick(options, ['encodedVideoPath', 'originalPath', 'previewPath', 'thumbnailPath']);
const path = _.pick(options, ['encodedVideoPath', 'previewPath', 'thumbnailPath']);
builder.andWhere(_.omitBy(path, _.isUndefined));

if (options.originalPath) {
builder.andWhere(`f_unaccent(${builder.alias}.originalPath) ILIKE f_unaccent(:originalPath)`, {
originalPath: `%${options.originalPath}%`,
});
}

if (options.originalFileName) {
builder.andWhere(`f_unaccent(${builder.alias}.originalFileName) ILIKE f_unaccent(:originalFileName)`, {
originalFileName: `%${options.originalFileName}%`,
Expand Down

0 comments on commit c7fb772

Please sign in to comment.