Pārlūkot izejas kodu

fixed es search

zero 1 gadu atpakaļ
vecāks
revīzija
a91c9c5376

+ 27 - 6
src/main/java/com/example/xiaoshiweixinback/service/common/EsDenseVectorService.java

@@ -35,9 +35,8 @@ import org.springframework.util.CollectionUtils;
 import java.io.File;
 import java.io.IOException;
 import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -167,17 +166,39 @@ public class EsDenseVectorService {
         return pictureNoVos.stream().sorted(Comparator.comparing(EsPictureNoVo::getImageIndex)).collect(Collectors.toList());
     }
 
-    public String appendCondition(Integer productId,String keyword) throws Exception {
+    /**
+     * 拼接检索条件
+     *
+     * @param productId
+     * @param keyword
+     * @return
+     * @throws Exception
+     */
+    public String appendCondition(Integer productId, String keyword) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
+        SimpleDateFormat format1 = new SimpleDateFormat("yyyy");
+
+
         String condition = "";
         String searchCondition = "";
         if (productId != null) {
             Product product = productMapper.selectById(productId);
             searchCondition = product.getSearchCondition();
+
+            Date now = new Date();
+            String nowFormat = format.format(now);
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(now);
+            calendar.add(Calendar.YEAR, -3);
+            Date beforeDate = calendar.getTime();
+            String agoFormat = format1.format(beforeDate) + "0101";
+            String s = agoFormat + "~" + nowFormat;
+            searchCondition = searchCondition + " AND " + "AD = " + "(" + s + ")";
         }
         if (StringUtils.isNotEmpty(searchCondition)) {
             if (StringUtils.isNotEmpty(keyword)) {
                 String key = keyword.replaceAll("[,。、;,./;]", " OR ");
-                condition = "TI = " + "(" + key + ")" +  " AND " + searchCondition;
+                condition = "TI = " + "(" + key + ")" + " AND " + searchCondition;
             } else {
                 condition = searchCondition;
             }
@@ -185,7 +206,7 @@ public class EsDenseVectorService {
             //获取关键词
             if (StringUtils.isNotEmpty(keyword)) {
 //        String key = dto.getKey().replaceAll("[,。、;,./;\\s]"," OR ");
-                String key = keyword.replaceAll("[,。、;,./;]"," OR ");
+                String key = keyword.replaceAll("[,。、;,./;]", " OR ");
                 condition = "TI = " + "(" + key + ")";
             }
         }

+ 2 - 44
src/main/resources/jsons/patentVector.json

@@ -93,53 +93,11 @@
     "ifSort": "true"
   },
   {
-    "name": "LOC分类号",
-    "type": "Object",
-    "value": "mloc",
-    "field": "MLOC",
-    "esField": "mloc",
-    "esClass": "prefixQueryBuilder",
-    "ifSearch": "true",
-    "ifGroup": "true",
-    "ifShow": "true",
-    "ifStats": "true",
-    "ifAsCondition": "true",
-    "groupBy": "classify",
-    "ifSort": "false",
-    "children": [
-      {
-        "label": "LOC大类",
-        "type": "1",
-        "group": "nos",
-        "value": "LOC1"
-      },
-      {
-        "label": "LOC",
-        "type": "1",
-        "group": "nos",
-        "value": "LOC"
-      }
-    ]
-  },
-  {
-    "name": "LOC大类",
-    "type": "String",
-    "value": "locLevel1",
-    "field": "LOC1",
-    "esField": "mloc.level1",
-    "esClass": "keyWordQueryBuilder",
-    "ifSearch": "false",
-    "ifGroup": "false",
-    "ifShow": "false",
-    "ifStats": "false",
-    "ifAsCondition": "true"
-  },
-  {
     "name": "LOC",
     "type": "String",
-    "value": "locLevel2",
+    "value": "locLevel1",
     "field": "LOC",
-    "esField": "mloc.level2",
+    "esField": "loc.level1",
     "esClass": "keyWordQueryBuilder",
     "ifSearch": "false",
     "ifGroup": "false",

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

@@ -6,6 +6,11 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.context.annotation.Lazy;
 
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
 
 
@@ -47,5 +52,32 @@ class XiaoshiWeixinbackApplicationTests {
 //        String value = StpUtil.getTokenValueByLoginId(2);
 //        System.out.println(tokenValue);
 //        System.out.println(value);
+
+        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
+        SimpleDateFormat format1 = new SimpleDateFormat("yyyy");
+        Date now = new Date();
+        String nowFormat = format.format(now);
+        System.out.println(nowFormat);
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(now);
+        calendar.add(Calendar.YEAR, -3);
+        Date beforeDate = calendar.getTime();
+        String threeYearsAgo = format1.format(beforeDate) + "0101";
+        System.out.println(threeYearsAgo);
+
+    }
+
+    @Test
+    public void test1() {
+        // 获取当前时间
+        LocalDateTime now = LocalDateTime.now();
+        now.format(DateTimeFormatter.ISO_DATE);
+        // 减去三年
+        LocalDateTime threeYearsAgo = now.minusYears(3);
+
+        // 打印结果
+        System.out.println("当前时间: " + now);
+        System.out.println("三年前的时间: " + threeYearsAgo);
     }
 }