mirror of
https://github.com/immich-app/immich.git
synced 2026-02-09 19:29:27 +03:00
return distance in response
This commit is contained in:
@@ -130,6 +130,7 @@ export type MapAsset = {
|
||||
tags?: Tag[];
|
||||
thumbhash: Buffer<ArrayBufferLike> | null;
|
||||
type: AssetType;
|
||||
distance?: number;
|
||||
};
|
||||
|
||||
export class AssetStackResponseDto {
|
||||
|
||||
@@ -296,12 +296,16 @@ class SearchAlbumResponseDto {
|
||||
facets!: SearchFacetResponseDto[];
|
||||
}
|
||||
|
||||
class AssetSearchResponseDto extends AssetResponseDto {
|
||||
distance?: number;
|
||||
}
|
||||
|
||||
class SearchAssetResponseDto {
|
||||
@ApiProperty({ type: 'integer' })
|
||||
total!: number;
|
||||
@ApiProperty({ type: 'integer' })
|
||||
count!: number;
|
||||
items!: AssetResponseDto[];
|
||||
items!: AssetSearchResponseDto[];
|
||||
facets!: SearchFacetResponseDto[];
|
||||
nextPage!: string | null;
|
||||
}
|
||||
|
||||
@@ -284,8 +284,9 @@ export class SearchRepository {
|
||||
await sql`set local vchordrq.probes = ${sql.lit(probes[VectorIndex.Clip])}`.execute(trx);
|
||||
const items = await searchAssetBuilder(trx, options)
|
||||
.selectAll('asset')
|
||||
.select(sql<number>`smart_search.embedding <=> ${options.embedding}`.as('distance'))
|
||||
.innerJoin('smart_search', 'asset.id', 'smart_search.assetId')
|
||||
.orderBy(sql`smart_search.embedding <=> ${options.embedding}`)
|
||||
.orderBy('distance')
|
||||
.limit(pagination.size + 1)
|
||||
.offset((pagination.page - 1) * pagination.size)
|
||||
.execute();
|
||||
|
||||
@@ -198,7 +198,7 @@ export class SearchService extends BaseService {
|
||||
assets: {
|
||||
total: assets.length,
|
||||
count: assets.length,
|
||||
items: assets.map((asset) => mapAsset(asset, options)),
|
||||
items: assets.map((asset) => ({ ...mapAsset(asset, options), distance: asset.distance })),
|
||||
facets: [],
|
||||
nextPage,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user