浏览代码

fix(server): use current schema for search/explore (#2331)

Jason Rasmussen 2 年之前
父节点
当前提交
aa91b946fa
共有 1 个文件被更改,包括 4 次插入11 次删除
  1. 4 11
      server/libs/infra/src/repositories/typesense.repository.ts

+ 4 - 11
server/libs/infra/src/repositories/typesense.repository.ts

@@ -132,15 +132,13 @@ export class TypesenseRepository implements ISearchRepository {
   }
   }
 
 
   async explore(userId: string): Promise<SearchExploreItem<AssetEntity>[]> {
   async explore(userId: string): Promise<SearchExploreItem<AssetEntity>[]> {
-    const alias = await this.client.aliases(SearchCollection.ASSETS).retrieve();
-
     const common = {
     const common = {
       q: '*',
       q: '*',
       filter_by: this.buildFilterBy('ownerId', userId, true),
       filter_by: this.buildFilterBy('ownerId', userId, true),
       per_page: 100,
       per_page: 100,
     };
     };
 
 
-    const asset$ = this.client.collections<AssetEntity>(alias.collection_name).documents();
+    const asset$ = this.client.collections<AssetEntity>(assetSchema.name).documents();
 
 
     const { facet_counts: facets } = await asset$.search({
     const { facet_counts: facets } = await asset$.search({
       ...common,
       ...common,
@@ -208,10 +206,8 @@ export class TypesenseRepository implements ISearchRepository {
   }
   }
 
 
   async searchAlbums(query: string, filters: SearchFilter): Promise<SearchResult<AlbumEntity>> {
   async searchAlbums(query: string, filters: SearchFilter): Promise<SearchResult<AlbumEntity>> {
-    const alias = await this.client.aliases(SearchCollection.ALBUMS).retrieve();
-
     const results = await this.client
     const results = await this.client
-      .collections<AlbumEntity>(alias.collection_name)
+      .collections<AlbumEntity>(albumSchema.name)
       .documents()
       .documents()
       .search({
       .search({
         q: query,
         q: query,
@@ -223,9 +219,8 @@ export class TypesenseRepository implements ISearchRepository {
   }
   }
 
 
   async searchAssets(query: string, filters: SearchFilter): Promise<SearchResult<AssetEntity>> {
   async searchAssets(query: string, filters: SearchFilter): Promise<SearchResult<AssetEntity>> {
-    const alias = await this.client.aliases(SearchCollection.ASSETS).retrieve();
     const results = await this.client
     const results = await this.client
-      .collections<AssetEntity>(alias.collection_name)
+      .collections<AssetEntity>(assetSchema.name)
       .documents()
       .documents()
       .search({
       .search({
         q: query,
         q: query,
@@ -248,12 +243,10 @@ export class TypesenseRepository implements ISearchRepository {
   }
   }
 
 
   async vectorSearch(input: number[], filters: SearchFilter): Promise<SearchResult<AssetEntity>> {
   async vectorSearch(input: number[], filters: SearchFilter): Promise<SearchResult<AssetEntity>> {
-    const alias = await this.client.aliases(SearchCollection.ASSETS).retrieve();
-
     const { results } = await this.client.multiSearch.perform({
     const { results } = await this.client.multiSearch.perform({
       searches: [
       searches: [
         {
         {
-          collection: alias.collection_name,
+          collection: assetSchema.name,
           q: '*',
           q: '*',
           vector_query: `smartInfo.clipEmbedding:([${input.join(',')}], k:100)`,
           vector_query: `smartInfo.clipEmbedding:([${input.join(',')}], k:100)`,
           per_page: 250,
           per_page: 250,