mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
fix(server): filter out empty search suggestions (#27292)
* fix(server): filter out empty search suggestions * make sql
This commit is contained in:
@@ -254,6 +254,7 @@ where
|
|||||||
and "visibility" = $2
|
and "visibility" = $2
|
||||||
and "deletedAt" is null
|
and "deletedAt" is null
|
||||||
and "state" is not null
|
and "state" is not null
|
||||||
|
and "state" != $3
|
||||||
|
|
||||||
-- SearchRepository.getCities
|
-- SearchRepository.getCities
|
||||||
select distinct
|
select distinct
|
||||||
@@ -266,6 +267,7 @@ where
|
|||||||
and "visibility" = $2
|
and "visibility" = $2
|
||||||
and "deletedAt" is null
|
and "deletedAt" is null
|
||||||
and "city" is not null
|
and "city" is not null
|
||||||
|
and "city" != $3
|
||||||
|
|
||||||
-- SearchRepository.getCameraMakes
|
-- SearchRepository.getCameraMakes
|
||||||
select distinct
|
select distinct
|
||||||
@@ -278,6 +280,7 @@ where
|
|||||||
and "visibility" = $2
|
and "visibility" = $2
|
||||||
and "deletedAt" is null
|
and "deletedAt" is null
|
||||||
and "make" is not null
|
and "make" is not null
|
||||||
|
and "make" != $3
|
||||||
|
|
||||||
-- SearchRepository.getCameraModels
|
-- SearchRepository.getCameraModels
|
||||||
select distinct
|
select distinct
|
||||||
@@ -290,6 +293,7 @@ where
|
|||||||
and "visibility" = $2
|
and "visibility" = $2
|
||||||
and "deletedAt" is null
|
and "deletedAt" is null
|
||||||
and "model" is not null
|
and "model" is not null
|
||||||
|
and "model" != $3
|
||||||
|
|
||||||
-- SearchRepository.getCameraLensModels
|
-- SearchRepository.getCameraLensModels
|
||||||
select distinct
|
select distinct
|
||||||
@@ -302,3 +306,4 @@ where
|
|||||||
and "visibility" = $2
|
and "visibility" = $2
|
||||||
and "deletedAt" is null
|
and "deletedAt" is null
|
||||||
and "lensModel" is not null
|
and "lensModel" is not null
|
||||||
|
and "lensModel" != $3
|
||||||
|
|||||||
@@ -502,10 +502,7 @@ export class SearchRepository {
|
|||||||
return res.map((row) => row.lensModel!);
|
return res.map((row) => row.lensModel!);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getExifField<K extends 'city' | 'state' | 'country' | 'make' | 'model' | 'lensModel'>(
|
private getExifField(field: 'city' | 'state' | 'country' | 'make' | 'model' | 'lensModel', userIds: string[]) {
|
||||||
field: K,
|
|
||||||
userIds: string[],
|
|
||||||
) {
|
|
||||||
return this.db
|
return this.db
|
||||||
.selectFrom('asset_exif')
|
.selectFrom('asset_exif')
|
||||||
.select(field)
|
.select(field)
|
||||||
@@ -514,6 +511,7 @@ export class SearchRepository {
|
|||||||
.where('ownerId', '=', anyUuid(userIds))
|
.where('ownerId', '=', anyUuid(userIds))
|
||||||
.where('visibility', '=', AssetVisibility.Timeline)
|
.where('visibility', '=', AssetVisibility.Timeline)
|
||||||
.where('deletedAt', 'is', null)
|
.where('deletedAt', 'is', null)
|
||||||
.where(field, 'is not', null);
|
.where(field, 'is not', null)
|
||||||
|
.where(field, '!=', '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Kysely } from 'kysely';
|
import { Kysely } from 'kysely';
|
||||||
|
import { SearchSuggestionType } from 'src/dtos/search.dto';
|
||||||
import { AccessRepository } from 'src/repositories/access.repository';
|
import { AccessRepository } from 'src/repositories/access.repository';
|
||||||
import { AssetRepository } from 'src/repositories/asset.repository';
|
import { AssetRepository } from 'src/repositories/asset.repository';
|
||||||
import { DatabaseRepository } from 'src/repositories/database.repository';
|
import { DatabaseRepository } from 'src/repositories/database.repository';
|
||||||
@@ -108,4 +109,25 @@ describe(SearchService.name, () => {
|
|||||||
expect(response.assets.items[0].id).toBe(unstackedAsset.id);
|
expect(response.assets.items[0].id).toBe(unstackedAsset.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getSearchSuggestions', () => {
|
||||||
|
it('should filter out empty search suggestions', async () => {
|
||||||
|
const { sut, ctx } = setup();
|
||||||
|
const { user } = await ctx.newUser();
|
||||||
|
|
||||||
|
const { asset } = await ctx.newAsset({ ownerId: user.id });
|
||||||
|
await ctx.newExif({ assetId: asset.id, make: 'Canon' });
|
||||||
|
|
||||||
|
const { asset: assetWithEmptyMake } = await ctx.newAsset({ ownerId: user.id });
|
||||||
|
await ctx.newExif({ assetId: assetWithEmptyMake.id, make: '' });
|
||||||
|
|
||||||
|
const auth = factory.auth({ user: { id: user.id } });
|
||||||
|
const suggestions = await sut.getSearchSuggestions(auth, {
|
||||||
|
type: SearchSuggestionType.CAMERA_MAKE,
|
||||||
|
includeNull: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(suggestions).toEqual(['Canon', null]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user