ソースを参照

领域检索优化

xiaoqiao 2 ヶ月 前
コミット
9600e1d7d3

+ 0 - 1
src/main/java/com/bowintek/practice/services/impl/AnalyzeServiceImpl.java

@@ -86,7 +86,6 @@ public class AnalyzeServiceImpl implements AnalyzeService {
             System.out.println("timeString:" + timeString);
         }
         List<EsQueryKeyword> dbList = esQueryKeywordCQuery.getList(null, timeString);
-        if (dbList.size() == 0) return;
 
         for (int i = 0; i < dbList.size(); i++) {
             EsQueryKeyword keyword = dbList.get(i);

+ 13 - 3
src/main/java/com/bowintek/practice/services/impl/EsQueryServiceImpl.java

@@ -53,6 +53,7 @@ public class EsQueryServiceImpl implements EsQueryService {
     private static Object lockObject = new Object();
     private static List<String> indexCache = null;
     private static List<String> pathCache = null;
+    private static List<EsIndexfieldVo> indexFields = null;
     private static long cacheTime = 0;
 
     public void getCacheList() {
@@ -66,6 +67,9 @@ public class EsQueryServiceImpl implements EsQueryService {
                         .distinct().collect(Collectors.toList());
 
                 List<EsIndexfieldVo> list2 = esIndexCquery.getFieldList(null, null);
+
+                indexFields= list2.stream().filter(p -> !p.getDataType().equals("NESTED")).collect(Collectors.toList());
+
                 pathCache = list2.stream().filter(p -> p.getDataType().equals("NESTED"))
                         .map(m -> m.getFieldCode())
                         .distinct().collect(Collectors.toList());
@@ -318,9 +322,15 @@ public class EsQueryServiceImpl implements EsQueryService {
             query = QueryBuilders.rangeQuery(fieldString).lt(value);
         else if (opreation.equals("小于等于"))
             query = QueryBuilders.rangeQuery(fieldString).lte(value);
-        else if (opreation.equals("等于"))
-            query = QueryBuilders.termQuery(fieldString+".keyword", value);
-        else if (opreation.equals("包括IN")) {
+        else if (opreation.equals("等于")) {
+           //如果是字符串类型,则使用不分词查询
+            boolean isVarchar = indexFields.stream().anyMatch(x -> x.getFieldCode().equals(fieldString) && x.getDataType().equals("VARCHAR"));
+            if(isVarchar) {
+                query = QueryBuilders.termQuery(fieldString + ".keyword", value);
+            }else {
+                query = QueryBuilders.termQuery(fieldString, value);
+            }
+        }else if (opreation.equals("包括IN")) {
             String[] fls = value.split(",");
             query=QueryBuilders.termsQuery(fieldString, fls);
         }