mirror of
https://github.com/immich-app/immich.git
synced 2026-03-08 02:57:48 +03:00
feat(server): search across own+partner assets (#5966)
* feat(server): search across own+partner assets * generate sql * fix sql parameter
This commit is contained in:
committed by
GitHub
parent
2688e05033
commit
cc7ba3c21a
@@ -7,6 +7,7 @@ import { PersonResponseDto } from '../person';
|
||||
import {
|
||||
IAssetRepository,
|
||||
IMachineLearningRepository,
|
||||
IPartnerRepository,
|
||||
IPersonRepository,
|
||||
ISmartInfoRepository,
|
||||
ISystemConfigRepository,
|
||||
@@ -28,6 +29,7 @@ export class SearchService {
|
||||
@Inject(IPersonRepository) private personRepository: IPersonRepository,
|
||||
@Inject(ISmartInfoRepository) private smartInfoRepository: ISmartInfoRepository,
|
||||
@Inject(IAssetRepository) private assetRepository: IAssetRepository,
|
||||
@Inject(IPartnerRepository) private partnerRepository: IPartnerRepository,
|
||||
) {
|
||||
this.configCore = SystemConfigCore.create(configRepository);
|
||||
}
|
||||
@@ -64,6 +66,7 @@ export class SearchService {
|
||||
throw new Error('CLIP is not enabled');
|
||||
}
|
||||
const strategy = dto.clip ? SearchStrategy.CLIP : SearchStrategy.TEXT;
|
||||
const userIds = await this.getUserIdsToSearch(auth);
|
||||
|
||||
let assets: AssetEntity[] = [];
|
||||
|
||||
@@ -74,10 +77,10 @@ export class SearchService {
|
||||
{ text: query },
|
||||
machineLearning.clip,
|
||||
);
|
||||
assets = await this.smartInfoRepository.searchCLIP({ ownerId: auth.user.id, embedding, numResults: 100 });
|
||||
assets = await this.smartInfoRepository.searchCLIP({ userIds: userIds, embedding, numResults: 100 });
|
||||
break;
|
||||
case SearchStrategy.TEXT:
|
||||
assets = await this.assetRepository.searchMetadata(query, auth.user.id, { numResults: 250 });
|
||||
assets = await this.assetRepository.searchMetadata(query, userIds, { numResults: 250 });
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -97,4 +100,14 @@ export class SearchService {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async getUserIdsToSearch(auth: AuthDto): Promise<string[]> {
|
||||
const userIds: string[] = [auth.user.id];
|
||||
const partners = await this.partnerRepository.getAll(auth.user.id);
|
||||
const partnersIds = partners
|
||||
.filter((partner) => partner.sharedBy && partner.inTimeline)
|
||||
.map((partner) => partner.sharedById);
|
||||
userIds.push(...partnersIds);
|
||||
return userIds;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user