High performance self-hosted photo and video management solution.
TypeScript backup-toolfluttergoogle-photosgoogle-photos-alternativejavascriptmobile-appnestjsnodejsphoto-galleryphotosphotos-managementself-hostedsveltesveltekittypescriptvideos
fix(server): filter out empty search suggestions (#27292)
Michel Heusschenb36911a16b6c
diff --git a/server/src/queries/search.repository.sql b/server/src/queries/search.repository.sqlindex ef5fbe09be..099b7f4ee2 100644--- a/server/src/queries/search.repository.sql+++ b/server/src/queries/search.repository.sql@@ -254,6 +254,7 @@ whereand "visibility" = $2and "deletedAt" is nulland "state" is not null+ and "state" != $3-- SearchRepository.getCitiesselect distinct@@ -266,6 +267,7 @@ whereand "visibility" = $2and "deletedAt" is nulland "city" is not null+ and "city" != $3-- SearchRepository.getCameraMakesselect distinct@@ -278,6 +280,7 @@ whereand "visibility" = $2and "deletedAt" is nulland "make" is not null+ and "make" != $3-- SearchRepository.getCameraModelsselect distinct@@ -290,6 +293,7 @@ whereand "visibility" = $2and "deletedAt" is nulland "model" is not null+ and "model" != $3-- SearchRepository.getCameraLensModelsselect distinct@@ -302,3 +306,4 @@ whereand "visibility" = $2and "deletedAt" is nulland "lensModel" is not null+ and "lensModel" != $3diff --git a/server/src/repositories/search.repository.ts b/server/src/repositories/search.repository.tsindex 13ac254654..ba72a70fdb 100644--- a/server/src/repositories/search.repository.ts+++ b/server/src/repositories/search.repository.ts@@ -502,10 +502,7 @@ export class SearchRepository {return res.map((row) => row.lensModel!);}- private getExifField<K extends 'city' | 'state' | 'country' | 'make' | 'model' | 'lensModel'>(- field: K,- userIds: string[],- ) {+ private getExifField(field: 'city' | 'state' | 'country' | 'make' | 'model' | 'lensModel', userIds: string[]) {return this.db.selectFrom('asset_exif').select(field)@@ -514,6 +511,7 @@ export class SearchRepository {.where('ownerId', '=', anyUuid(userIds)).where('visibility', '=', AssetVisibility.Timeline).where('deletedAt', 'is', null)- .where(field, 'is not', null);+ .where(field, 'is not', null)+ .where(field, '!=', '');}}diff --git a/server/test/medium/specs/services/search.service.spec.ts b/server/test/medium/specs/services/search.service.spec.tsindex c20b64ca7c..18e03b2e48 100644--- a/server/test/medium/specs/services/search.service.spec.ts+++ b/server/test/medium/specs/services/search.service.spec.ts@@ -1,4 +1,5 @@import { Kysely } from 'kysely';+import { SearchSuggestionType } from 'src/dtos/search.dto';import { AccessRepository } from 'src/repositories/access.repository';import { AssetRepository } from 'src/repositories/asset.repository';import { DatabaseRepository } from 'src/repositories/database.repository';@@ -108,4 +109,25 @@ describe(SearchService.name, () => {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]);+ });+ });});