forked from Cutlery/immich
		
	feat(server): Fallback to text search if machine-learning is disabled (#2015)
This commit is contained in:
		
							parent
							
								
									d7bfab7b13
								
							
						
					
					
						commit
						dd02f1025f
					
				@ -99,21 +99,18 @@ export class SearchService {
 | 
				
			|||||||
    this.assertEnabled();
 | 
					    this.assertEnabled();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const query = dto.q || dto.query || '*';
 | 
					    const query = dto.q || dto.query || '*';
 | 
				
			||||||
    const strategy = dto.clip ? SearchStrategy.CLIP : SearchStrategy.TEXT;
 | 
					    const strategy = dto.clip && MACHINE_LEARNING_ENABLED ? SearchStrategy.CLIP : SearchStrategy.TEXT;
 | 
				
			||||||
    const filters = { userId: authUser.id, ...dto };
 | 
					    const filters = { userId: authUser.id, ...dto };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let assets: SearchResult<AssetEntity>;
 | 
					    let assets: SearchResult<AssetEntity>;
 | 
				
			||||||
    switch (strategy) {
 | 
					    switch (strategy) {
 | 
				
			||||||
      case SearchStrategy.TEXT:
 | 
					 | 
				
			||||||
        assets = await this.searchRepository.searchAssets(query, filters);
 | 
					 | 
				
			||||||
        break;
 | 
					 | 
				
			||||||
      case SearchStrategy.CLIP:
 | 
					      case SearchStrategy.CLIP:
 | 
				
			||||||
      default:
 | 
					 | 
				
			||||||
        if (!MACHINE_LEARNING_ENABLED) {
 | 
					 | 
				
			||||||
          throw new BadRequestException('Machine Learning is disabled');
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        const clip = await this.machineLearning.encodeText(query);
 | 
					        const clip = await this.machineLearning.encodeText(query);
 | 
				
			||||||
        assets = await this.searchRepository.vectorSearch(clip, filters);
 | 
					        assets = await this.searchRepository.vectorSearch(clip, filters);
 | 
				
			||||||
 | 
					      case SearchStrategy.TEXT:
 | 
				
			||||||
 | 
					      default:
 | 
				
			||||||
 | 
					        assets = await this.searchRepository.searchAssets(query, filters);
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const albums = await this.searchRepository.searchAlbums(query, filters);
 | 
					    const albums = await this.searchRepository.searchAlbums(query, filters);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user