feat(server): Add album filter to search (#18985)

* - updated dtos
- added inAlbums to search builder
- only check isNotInAlbum if albumIds is blank/empty

* - consider inAlbums as OR

* - make open-api-dart

* - lint & format

* - remove inAlbums groupBy clause

* - merge main open-api

* - make open-api

* - inAlbums filter AND instead of OR
This commit is contained in:
xCJPECKOVERx 2025-06-09 11:11:43 -04:00 committed by GitHub
parent 242817c49a
commit 14d785cec9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 57 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -10866,6 +10866,13 @@
}, },
"MetadataSearchDto": { "MetadataSearchDto": {
"properties": { "properties": {
"albumIds": {
"items": {
"format": "uuid",
"type": "string"
},
"type": "array"
},
"checksum": { "checksum": {
"type": "string" "type": "string"
}, },
@ -11785,6 +11792,13 @@
}, },
"RandomSearchDto": { "RandomSearchDto": {
"properties": { "properties": {
"albumIds": {
"items": {
"format": "uuid",
"type": "string"
},
"type": "array"
},
"city": { "city": {
"nullable": true, "nullable": true,
"type": "string" "type": "string"
@ -12833,6 +12847,13 @@
}, },
"SmartSearchDto": { "SmartSearchDto": {
"properties": { "properties": {
"albumIds": {
"items": {
"format": "uuid",
"type": "string"
},
"type": "array"
},
"city": { "city": {
"nullable": true, "nullable": true,
"type": "string" "type": "string"
@ -13029,6 +13050,13 @@
}, },
"StatisticsSearchDto": { "StatisticsSearchDto": {
"properties": { "properties": {
"albumIds": {
"items": {
"format": "uuid",
"type": "string"
},
"type": "array"
},
"city": { "city": {
"nullable": true, "nullable": true,
"type": "string" "type": "string"

View file

@ -853,6 +853,7 @@ export type SearchExploreResponseDto = {
items: SearchExploreItem[]; items: SearchExploreItem[];
}; };
export type MetadataSearchDto = { export type MetadataSearchDto = {
albumIds?: string[];
checksum?: string; checksum?: string;
city?: string | null; city?: string | null;
country?: string | null; country?: string | null;
@ -929,6 +930,7 @@ export type PlacesResponseDto = {
name: string; name: string;
}; };
export type RandomSearchDto = { export type RandomSearchDto = {
albumIds?: string[];
city?: string | null; city?: string | null;
country?: string | null; country?: string | null;
createdAfter?: string; createdAfter?: string;
@ -962,6 +964,7 @@ export type RandomSearchDto = {
withStacked?: boolean; withStacked?: boolean;
}; };
export type SmartSearchDto = { export type SmartSearchDto = {
albumIds?: string[];
city?: string | null; city?: string | null;
country?: string | null; country?: string | null;
createdAfter?: string; createdAfter?: string;
@ -996,6 +999,7 @@ export type SmartSearchDto = {
withExif?: boolean; withExif?: boolean;
}; };
export type StatisticsSearchDto = { export type StatisticsSearchDto = {
albumIds?: string[];
city?: string | null; city?: string | null;
country?: string | null; country?: string | null;
createdAfter?: string; createdAfter?: string;

View file

@ -95,6 +95,9 @@ class BaseSearchDto {
@ValidateUUID({ each: true, optional: true }) @ValidateUUID({ each: true, optional: true })
tagIds?: string[]; tagIds?: string[];
@ValidateUUID({ each: true, optional: true })
albumIds?: string[];
@Optional() @Optional()
@IsInt() @IsInt()
@Max(5) @Max(5)

View file

@ -91,6 +91,10 @@ export interface SearchTagOptions {
tagIds?: string[]; tagIds?: string[];
} }
export interface SearchAlbumOptions {
albumIds?: string[];
}
export interface SearchOrderOptions { export interface SearchOrderOptions {
orderDirection?: 'asc' | 'desc'; orderDirection?: 'asc' | 'desc';
} }
@ -108,7 +112,8 @@ type BaseAssetSearchOptions = SearchDateOptions &
SearchStatusOptions & SearchStatusOptions &
SearchUserIdOptions & SearchUserIdOptions &
SearchPeopleOptions & SearchPeopleOptions &
SearchTagOptions; SearchTagOptions &
SearchAlbumOptions;
export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions; export type AssetSearchOptions = BaseAssetSearchOptions & SearchRelationOptions;

View file

@ -228,6 +228,20 @@ export function hasPeople<O>(qb: SelectQueryBuilder<DB, 'assets', O>, personIds:
); );
} }
export function inAlbums<O>(qb: SelectQueryBuilder<DB, 'assets', O>, 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<O>(qb: SelectQueryBuilder<DB, 'assets', O>, tagIds: string[]) { export function hasTags<O>(qb: SelectQueryBuilder<DB, 'assets', O>, tagIds: string[]) {
return qb.innerJoin( return qb.innerJoin(
(eb) => (eb) =>
@ -292,6 +306,7 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
.withPlugin(joinDeduplicationPlugin) .withPlugin(joinDeduplicationPlugin)
.selectFrom('assets') .selectFrom('assets')
.where('assets.visibility', '=', visibility) .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.tagIds && options.tagIds.length > 0, (qb) => hasTags(qb, options.tagIds!))
.$if(!!options.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!)) .$if(!!options.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!))
.$if(!!options.createdBefore, (qb) => qb.where('assets.createdAt', '<=', options.createdBefore!)) .$if(!!options.createdBefore, (qb) => qb.where('assets.createdAt', '<=', options.createdBefore!))
@ -368,7 +383,7 @@ export function searchAssetBuilder(kysely: Kysely<DB>, options: AssetSearchBuild
.$if(options.isMotion !== undefined, (qb) => .$if(options.isMotion !== undefined, (qb) =>
qb.where('assets.livePhotoVideoId', options.isMotion ? 'is not' : 'is', null), 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) => qb.where((eb) =>
eb.not(eb.exists((eb) => eb.selectFrom('albums_assets_assets').whereRef('assetsId', '=', 'assets.id'))), eb.not(eb.exists((eb) => eb.selectFrom('albums_assets_assets').whereRef('assetsId', '=', 'assets.id'))),
), ),