瀏覽代碼

feat(server): Fallback to text search if machine-learning is disabled (#2015)

bo0tzz 2 年之前
父節點
當前提交
dd02f1025f
共有 1 個文件被更改,包括 5 次插入8 次删除
  1. 5 8
      server/libs/domain/src/search/search.service.ts

+ 5 - 8
server/libs/domain/src/search/search.service.ts

@@ -99,21 +99,18 @@ export class SearchService {
     this.assertEnabled();
 
     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 };
 
     let assets: SearchResult<AssetEntity>;
     switch (strategy) {
-      case SearchStrategy.TEXT:
-        assets = await this.searchRepository.searchAssets(query, filters);
-        break;
       case SearchStrategy.CLIP:
-      default:
-        if (!MACHINE_LEARNING_ENABLED) {
-          throw new BadRequestException('Machine Learning is disabled');
-        }
         const clip = await this.machineLearning.encodeText(query);
         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);