feat(server): provide the ability to search archived photos (#6332)

* Feat: provide the ability to search archived photos

Adds a query parameter (`searchArchived`) to the search URL parameters
to allow the results to contain archived photos.

* chore: rename includeArchived => withArchived

* chore: open api

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Steven Carter
2024-01-17 21:08:00 -05:00
committed by GitHub
parent f0b328fb6b
commit d4146e3e6d
11 changed files with 100 additions and 16 deletions

View File

@@ -43,7 +43,7 @@ export class SmartInfoRepository implements ISmartInfoRepository {
@GenerateSql({
params: [{ userIds: [DummyValue.UUID], embedding: Array.from({ length: 512 }, Math.random), numResults: 100 }],
})
async searchCLIP({ userIds, embedding, numResults }: EmbeddingSearch): Promise<AssetEntity[]> {
async searchCLIP({ userIds, embedding, numResults, withArchived }: EmbeddingSearch): Promise<AssetEntity[]> {
if (!isValidInteger(numResults, { min: 1 })) {
throw new Error(`Invalid value for 'numResults': ${numResults}`);
}
@@ -52,12 +52,18 @@ export class SmartInfoRepository implements ISmartInfoRepository {
await this.assetRepository.manager.transaction(async (manager) => {
await manager.query(`SET LOCAL vectors.k = '${numResults}'`);
await manager.query(`SET LOCAL vectors.enable_prefilter = on`);
results = await manager
const query = manager
.createQueryBuilder(AssetEntity, 'a')
.innerJoin('a.smartSearch', 's')
.where('a.ownerId IN (:...userIds )')
.andWhere('a.isVisible = true')
.andWhere('a.isArchived = false')
.andWhere('a.isVisible = true');
if (!withArchived) {
query.andWhere('a.isArchived = false');
}
results = await query
.andWhere('a.fileCreatedAt < NOW()')
.leftJoinAndSelect('a.exifInfo', 'e')
.orderBy('s.embedding <=> :embedding')