yuchengwei 4 дней назад
Родитель
Сommit
76e88423aa
1 измененных файлов с 11 добавлено и 6 удалено
  1. 11 6
      src/knowledge/service/search_service.py

+ 11 - 6
src/knowledge/service/search_service.py

@@ -44,10 +44,6 @@ class SearchBusiness:
                 },
                 "sort": [{"_score": {"order": "desc"}}]
             }
-            if limit:
-                query["size"] = limit
-            if from_:
-                query["from"] = from_
 
             if name:
                 query["query"]["bool"]["must"].append({"match": {"public_kg_nodes_name": name}})
@@ -55,9 +51,16 @@ class SearchBusiness:
                 query["query"]["bool"]["must"].append({"term": {"public_kg_nodes_id": id}})
             if ids:
                 query["query"]["bool"]["must"].append({"terms": {"public_kg_nodes_id": ids}})
+                limit = 2000
+                from_ = None
             if type:
                 query["query"]["bool"]["must"].append({"match": {"public_kg_nodes_category": type}})
 
+            if limit:
+                query["size"] = limit
+            if from_:
+                query["from"] = from_
+
             results = self.search_nodes_and_edges(index="connector-postgresql-all", query=query)
             return results
         except exceptions.NotFoundError as e:
@@ -67,7 +70,7 @@ class SearchBusiness:
             logger.error(f"Search error: {e}")
             return None
 
-    def search_edges(self,name,src_id):
+    def search_edges(self,name=None,src_id=None,size=None):
         try:
             query = {
                 "query": {
@@ -83,6 +86,8 @@ class SearchBusiness:
                 query["query"]["bool"]["must"].append({"match": {"public_kg_edges_category": name}})
             if src_id:
                 query["query"]["bool"]["must"].append({"term": {"public_kg_edges_src_id": src_id}})
+            if size:
+                query["size"] = size
 
             results = self.search_nodes_and_edges(index="connector-postgresql-all", query=query)
             return results
@@ -222,7 +227,7 @@ class SearchBusiness:
         return {"concepts": concepts}
 
     def get_relations(self, src_id):
-        edges = self.search_edges(name=None, src_id=src_id)
+        edges = self.search_edges(src_id=src_id, size=2000)
         if not edges:
             return {"relations": []}