diff --git a/mobile/openapi/lib/model/metadata_search_dto.dart b/mobile/openapi/lib/model/metadata_search_dto.dart index 7f1184467..520777a45 100644 Binary files a/mobile/openapi/lib/model/metadata_search_dto.dart and b/mobile/openapi/lib/model/metadata_search_dto.dart differ diff --git a/mobile/openapi/lib/model/random_search_dto.dart b/mobile/openapi/lib/model/random_search_dto.dart index 0284212ef..c5914f9fa 100644 Binary files a/mobile/openapi/lib/model/random_search_dto.dart and b/mobile/openapi/lib/model/random_search_dto.dart differ diff --git a/mobile/openapi/lib/model/smart_search_dto.dart b/mobile/openapi/lib/model/smart_search_dto.dart index a915d97b3..c22134055 100644 Binary files a/mobile/openapi/lib/model/smart_search_dto.dart and b/mobile/openapi/lib/model/smart_search_dto.dart differ diff --git a/mobile/openapi/lib/model/statistics_search_dto.dart b/mobile/openapi/lib/model/statistics_search_dto.dart index 0fe0770b6..55de23ba3 100644 Binary files a/mobile/openapi/lib/model/statistics_search_dto.dart and b/mobile/openapi/lib/model/statistics_search_dto.dart differ diff --git a/open-api/immich-openapi-specs.json b/open-api/immich-openapi-specs.json index 352fe768f..775fe117a 100644 --- a/open-api/immich-openapi-specs.json +++ b/open-api/immich-openapi-specs.json @@ -10866,6 +10866,13 @@ }, "MetadataSearchDto": { "properties": { + "albumIds": { + "items": { + "format": "uuid", + "type": "string" + }, + "type": "array" + }, "checksum": { "type": "string" }, @@ -11785,6 +11792,13 @@ }, "RandomSearchDto": { "properties": { + "albumIds": { + "items": { + "format": "uuid", + "type": "string" + }, + "type": "array" + }, "city": { "nullable": true, "type": "string" @@ -12833,6 +12847,13 @@ }, "SmartSearchDto": { "properties": { + "albumIds": { + "items": { + "format": "uuid", + "type": "string" + }, + "type": "array" + }, "city": { "nullable": true, "type": "string" @@ -13029,6 +13050,13 @@ }, "StatisticsSearchDto": { "properties": { + "albumIds": { + "items": { + "format": "uuid", + "type": "string" + }, + "type": "array" + }, "city": { "nullable": true, "type": "string" diff --git a/open-api/typescript-sdk/src/fetch-client.ts b/open-api/typescript-sdk/src/fetch-client.ts index 0308ecb9e..fee00acff 100644 --- a/open-api/typescript-sdk/src/fetch-client.ts +++ b/open-api/typescript-sdk/src/fetch-client.ts @@ -853,6 +853,7 @@ export type SearchExploreResponseDto = { items: SearchExploreItem[]; }; export type MetadataSearchDto = { + albumIds?: string[]; checksum?: string; city?: string | null; country?: string | null; @@ -929,6 +930,7 @@ export type PlacesResponseDto = { name: string; }; export type RandomSearchDto = { + albumIds?: string[]; city?: string | null; country?: string | null; createdAfter?: string; @@ -962,6 +964,7 @@ export type RandomSearchDto = { withStacked?: boolean; }; export type SmartSearchDto = { + albumIds?: string[]; city?: string | null; country?: string | null; createdAfter?: string; @@ -996,6 +999,7 @@ export type SmartSearchDto = { withExif?: boolean; }; export type StatisticsSearchDto = { + albumIds?: string[]; city?: string | null; country?: string | null; createdAfter?: string; diff --git a/server/src/dtos/search.dto.ts b/server/src/dtos/search.dto.ts index 81d74e0a7..d0427ef32 100644 --- a/server/src/dtos/search.dto.ts +++ b/server/src/dtos/search.dto.ts @@ -95,6 +95,9 @@ class BaseSearchDto { @ValidateUUID({ each: true, optional: true }) tagIds?: string[]; + @ValidateUUID({ each: true, optional: true }) + albumIds?: string[]; + @Optional() @IsInt() @Max(5) diff --git a/server/src/repositories/search.repository.ts b/server/src/repositories/search.repository.ts index 14150d424..068de1eb4 100644 --- a/server/src/repositories/search.repository.ts +++ b/server/src/repositories/search.repository.ts @@ -91,6 +91,10 @@ export interface SearchTagOptions { tagIds?: string[]; } +export interface SearchAlbumOptions { + albumIds?: string[]; +} + export interface SearchOrderOptions { orderDirection?: 'asc' | 'desc'; } @@ -108,7 +112,8 @@ type BaseAssetSearchOptions = SearchDateOptions & SearchStatusOptions & SearchUserIdOptions & SearchPeopleOptions & - SearchTagOptions; + SearchTagOptions & + SearchAlbumOptions; export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions; diff --git a/server/src/utils/database.ts b/server/src/utils/database.ts index d8171dc95..d7417becf 100644 --- a/server/src/utils/database.ts +++ b/server/src/utils/database.ts @@ -228,6 +228,20 @@ export function hasPeople(qb: SelectQueryBuilder, personIds: ); } +export function inAlbums(qb: SelectQueryBuilder, albumIds: string[]) { + return qb.innerJoin( + (eb) => + eb + .selectFrom('albums_assets_assets') + .select('assetsId') + .where('albumsId', '=', anyUuid(albumIds!)) + .groupBy('assetsId') + .having((eb) => eb.fn.count('albumsId').distinct(), '=', albumIds.length) + .as('has_album'), + (join) => join.onRef('has_album.assetsId', '=', 'assets.id'), + ); +} + export function hasTags(qb: SelectQueryBuilder, tagIds: string[]) { return qb.innerJoin( (eb) => @@ -292,6 +306,7 @@ export function searchAssetBuilder(kysely: Kysely, options: AssetSearchBuild .withPlugin(joinDeduplicationPlugin) .selectFrom('assets') .where('assets.visibility', '=', visibility) + .$if(!!options.albumIds && options.albumIds.length > 0, (qb) => inAlbums(qb, options.albumIds!)) .$if(!!options.tagIds && options.tagIds.length > 0, (qb) => hasTags(qb, options.tagIds!)) .$if(!!options.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!)) .$if(!!options.createdBefore, (qb) => qb.where('assets.createdAt', '<=', options.createdBefore!)) @@ -368,7 +383,7 @@ export function searchAssetBuilder(kysely: Kysely, options: AssetSearchBuild .$if(options.isMotion !== undefined, (qb) => qb.where('assets.livePhotoVideoId', options.isMotion ? 'is not' : 'is', null), ) - .$if(!!options.isNotInAlbum, (qb) => + .$if(!!options.isNotInAlbum && (!options.albumIds || options.albumIds.length === 0), (qb) => qb.where((eb) => eb.not(eb.exists((eb) => eb.selectFrom('albums_assets_assets').whereRef('assetsId', '=', 'assets.id'))), ),