mirror of
https://github.com/immich-app/immich.git
synced 2026-03-23 01:29:00 +03:00
feat: sort smart search
Smart search currently returns a list of assets by their score. It would be nice if we could instead filter assets, and then list them by date. This is the default behaviour of other platforms.
This commit is contained in:
@@ -237,6 +237,14 @@ export class SmartSearchDto extends BaseSearchWithResultsDto {
|
||||
@Type(() => Number)
|
||||
@Optional()
|
||||
page?: number;
|
||||
|
||||
@ValidateEnum({
|
||||
enum: AssetOrder,
|
||||
name: 'AssetOrder',
|
||||
optional: true,
|
||||
description: 'Sort order by date. If not provided, results are sorted by relevance.',
|
||||
})
|
||||
order?: AssetOrder;
|
||||
}
|
||||
|
||||
export class SearchPlacesDto {
|
||||
|
||||
@@ -129,6 +129,7 @@ export type SmartSearchOptions = SearchDateOptions &
|
||||
SearchEmbeddingOptions &
|
||||
SearchExifOptions &
|
||||
SearchOneToOneRelationOptions &
|
||||
SearchOrderOptions &
|
||||
SearchStatusOptions &
|
||||
SearchUserIdOptions &
|
||||
SearchPeopleOptions &
|
||||
@@ -300,7 +301,12 @@ export class SearchRepository {
|
||||
const items = await searchAssetBuilder(trx, options)
|
||||
.selectAll('asset')
|
||||
.innerJoin('smart_search', 'asset.id', 'smart_search.assetId')
|
||||
.orderBy(sql`smart_search.embedding <=> ${options.embedding}`)
|
||||
.$if(!options.orderDirection, (qb) => qb.orderBy(sql`smart_search.embedding <=> ${options.embedding}`))
|
||||
.$if(!!options.orderDirection, (qb) =>
|
||||
qb
|
||||
.where(sql`(smart_search.embedding <=> ${options.embedding}) <= 0.9`)
|
||||
.orderBy('asset.fileCreatedAt', options.orderDirection as OrderByDirection),
|
||||
)
|
||||
.limit(pagination.size + 1)
|
||||
.offset((pagination.page - 1) * pagination.size)
|
||||
.execute();
|
||||
|
||||
@@ -139,7 +139,7 @@ export class SearchService extends BaseService {
|
||||
const size = dto.size || 100;
|
||||
const { hasNextPage, items } = await this.searchRepository.searchSmart(
|
||||
{ page, size },
|
||||
{ ...dto, userIds: await userIds, embedding },
|
||||
{ ...dto, userIds: await userIds, embedding, orderDirection: dto.order },
|
||||
);
|
||||
|
||||
return this.mapResponse(items, hasNextPage ? (page + 1).toString() : null, { auth });
|
||||
|
||||
Reference in New Issue
Block a user