Browse Source

fixed essearch

zero 1 năm trước cách đây
mục cha
commit
9a0b766d91

+ 45 - 13
src/main/java/com/example/xiaoshiweixinback/service/importPatent/EsDenseVectorService.java

@@ -249,27 +249,59 @@ public class EsDenseVectorService {
             }
         }
         if (StringUtils.isNotEmpty(companyName)) {
+            String s1 = this.appendStr(companyName);
             if (StringUtils.isEmpty(searchCondition)) {
-                searchCondition = "PE = " + "(" + companyName + ")";
+                searchCondition = "PE = " + "(" + s1 + ")";
             } else {
-                searchCondition = searchCondition + " AND " + "PE = " + "(" + "\"" + companyName + "\"" + ")";
+                searchCondition = searchCondition + " AND " + "PE = " + "(" + s1 + ")";
             }
         }
-        if (StringUtils.isNotEmpty(searchCondition)) {
-            if (StringUtils.isNotEmpty(keyword)) {
-                String key = keyword.replaceAll("[,。、;,./;]", " OR ");
-                condition = "TI = " + "(" + "\"" + key + "\"" + ")" + " AND " + searchCondition;
+        if (StringUtils.isNotEmpty(keyword)) {
+            String s = this.appendStr(keyword);
+            if (StringUtils.isEmpty(searchCondition)) {
+                condition = "TI = " + "(" + s + ")";
             } else {
-                condition = searchCondition;
+                condition = searchCondition + " AND " + "TI = " + "(" + s + ")";
             }
         } else {
-            //获取关键词
-            if (StringUtils.isNotEmpty(keyword)) {
-//        String key = dto.getKey().replaceAll("[,。、;,./;\\s]"," OR ");
-                String key = keyword.replaceAll("[,。、;,./;]", " OR ");
-                condition = "TI = " + "(" + "\"" + key + "\"" + ")";
-            }
+            condition = searchCondition;
         }
+//        if (StringUtils.isNotEmpty(searchCondition)) {
+//            if (StringUtils.isNotEmpty(keyword)) {
+//                String key = keyword.replaceAll("[,。、;,./;]", " OR ");
+//                condition = "TI = " + "(" + "\"" + key + "\"" + ")" + " AND " + searchCondition;
+//            } else {
+//                condition = searchCondition;
+//            }
+//        } else {
+//            //获取关键词
+//            if (StringUtils.isNotEmpty(keyword)) {
+////        String key = dto.getKey().replaceAll("[,。、;,./;\\s]"," OR ");
+//                String key = keyword.replaceAll("[,。、;,./;]", " OR ");
+//                condition = "TI = " + "(" + "\"" + key + "\"" + ")";
+//            }
+//        }
         return condition;
     }
+
+    public String appendStr(String str) {
+        String needStr = "";
+        String cName = str.replaceAll("[,。、;,./;]", "OR");
+        if (cName.contains("OR")) {
+            String[] split = cName.split("OR");
+            String ccName = "";
+            for (int i = 0; i < split.length; i++) {
+                String s = split[i];
+                if (split.length -1 != i) {
+                    ccName = ccName + "\"" + s + "\"" + " OR ";
+                } else {
+                    ccName = ccName + "\"" + s + "\"";
+                }
+            }
+            needStr = ccName;
+        } else {
+            needStr = "\"" + str + "\"";
+        }
+        return needStr;
+    }
 }

+ 30 - 0
src/test/java/com/example/xiaoshiweixinback/XiaoshiWeixinbackApplicationTests.java

@@ -1,6 +1,7 @@
 package com.example.xiaoshiweixinback;
 
 import com.example.xiaoshiweixinback.service.importPatent.EsDenseVectorService;
+import org.apache.commons.lang3.StringUtils;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -98,4 +99,33 @@ class XiaoshiWeixinbackApplicationTests {
             ttlSeconds = 0; // 或者你可以设置为其他逻辑,比如下一个天的零点
         }
     }
+
+    @Test
+    public void test2() {
+        String companyName = "CN,AD,AP";
+        String searchCondition = "";
+//        String cName = companyName.replaceAll("[,。、;,./;]", "OR");
+//        if (cName.contains("OR")) {
+//            String[] split = cName.split("OR");
+//            String ccName = "";
+//            for (int i = 0; i < split.length; i++) {
+//                String s = split[i];
+//                if (split.length -1 != i) {
+//                    ccName = ccName + "\"" + s + "\"" + " OR ";
+//                } else {
+//                    ccName = ccName + "\"" + s + "\"";
+//                }
+//            }
+//            companyName = ccName;
+//        } else {
+//            companyName = "\"" + companyName + "\"";
+//        }
+        String key = denseVectorService.appendStr(companyName);
+        if (StringUtils.isEmpty(searchCondition)) {
+            searchCondition = "PE = " + "(" + key + ")";
+        } else {
+            searchCondition = searchCondition + " AND " + "PE = " + "(" + key + ")";
+        }
+        System.out.println(searchCondition);
+    }
 }