Selaa lähdekoodia

fixed esSearch

zero 1 vuosi sitten
vanhempi
commit
c1bd348ec7

+ 1 - 1
src/main/java/com/example/xiaoshiweixinback/business/utils/FileUtils.java

@@ -125,7 +125,7 @@ public class FileUtils {
     }
     public static File multipartFileToFile(MultipartFile file) throws Exception {
         File toFile = null;
-        if (file.equals("") || file.getSize() <= 0) {
+        if (file == null ||file.equals("") || file.getSize() <= 0) {
             file = null;
         } else {
             InputStream ins = null;

+ 10 - 2
src/main/java/com/example/xiaoshiweixinback/controller/PatentController.java

@@ -4,6 +4,8 @@ import com.alibaba.fastjson2.JSONObject;
 import com.example.xiaoshiweixinback.business.common.Constants;
 import com.example.xiaoshiweixinback.business.common.Response;
 import com.example.xiaoshiweixinback.business.common.base.Records;
+import com.example.xiaoshiweixinback.business.utils.FileUtil;
+import com.example.xiaoshiweixinback.business.utils.FileUtils;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
 import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPatentVectorDTO;
 import com.example.xiaoshiweixinback.entity.dto.patent.ImportTaskAMVO;
@@ -14,8 +16,10 @@ import com.example.xiaoshiweixinback.service.common.FileManagerService;
 import com.example.xiaoshiweixinback.service.importPatent.GetPatentFromExcelService;
 import com.example.xiaoshiweixinback.service.importPatent.ImportFromWebToEsService;
 import io.swagger.v3.oas.annotations.Operation;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
 import java.util.List;
@@ -48,8 +52,12 @@ public class PatentController {
 
     @Operation(summary = "根据关键词获取列表(图片用于排序)--zero")
     @PostMapping(value = "/getPatentVectors")
-    public Response getPatentVectors(String vectorDTO, File file) throws Exception {
-        EsPatentVectorDTO esPatentVectorDTO = JSONObject.parseObject(vectorDTO, EsPatentVectorDTO.class);
+    public Response getPatentVectors(@RequestParam(value = "vectorDTO", required = false) String vectorDTO, @RequestParam(value = "multipartFile", required = false) MultipartFile multipartFile) throws Exception {
+        File file = FileUtils.multipartFileToFile(multipartFile);
+        EsPatentVectorDTO esPatentVectorDTO = new EsPatentVectorDTO();
+        if (StringUtils.isNotEmpty(vectorDTO)) {
+            esPatentVectorDTO = JSONObject.parseObject(vectorDTO, EsPatentVectorDTO.class);
+        }
         Records records = esDenseVectorService.getPatentVectors(esPatentVectorDTO, file);
         return Response.success(records);
     }

+ 2 - 2
src/main/java/com/example/xiaoshiweixinback/entity/dto/esPicture/EsPatentVectorDTO.java

@@ -13,7 +13,7 @@ public class EsPatentVectorDTO {
 
     private String description;
 
-    private Long pageNum;
+    private Long pageNum = 1l;
 
-    private Long pageSize;
+    private Long pageSize = 10l;
 }

+ 5 - 2
src/main/java/com/example/xiaoshiweixinback/service/LoginService.java

@@ -256,7 +256,8 @@ public class LoginService {
         if (ToolUtil.isEmpty(token)) {
             throw new BusinessException(ExceptionEnum.THE_LOG_OUT);
         }
-        PersonnelVO personnelVO = cacheUtil.getLoginUser(token);
+        String usedToken = token.substring(token.indexOf("=") + 1);
+        PersonnelVO personnelVO = cacheUtil.getLoginUser(usedToken);
         if (ToolUtil.isEmpty(personnelVO)) {
             throw new BusinessException(ExceptionEnum.THE_LOG_OUT);
         }
@@ -296,7 +297,9 @@ public class LoginService {
      * @author: gck
      */
     public boolean logout(PersonIdDTO dto) {
-        redisService.delete(LoginUtils.getToken());
+        String token = LoginUtils.getToken();
+        String usedToken = token.substring(token.indexOf("=") + 1);
+        redisService.delete(usedToken);
         return true;
     }
 

+ 5 - 15
src/main/java/com/example/xiaoshiweixinback/service/common/EsDenseVectorService.java

@@ -91,7 +91,6 @@ public class EsDenseVectorService {
             Float a = Float.parseFloat(item);
             imageList.add(a);
         });
-        System.out.println(imageList);
         if (!CollectionUtils.isEmpty(imageList)) {
             String source = "cosineSimilarity(params.queryVector, 'my_vector') + 1.0";
             InlineScript inlineScript = InlineScript.of(i -> i.lang("painless").params("queryVector", JsonData.of(imageList)).source(source));
@@ -126,24 +125,15 @@ public class EsDenseVectorService {
         SearchResponse<PatentVector> response = client.search(builder.build(), PatentVector.class);
         List<Hit<PatentVector>> hits = response.hits().hits();
         List<EsPatentVectorVo> vectorVos = new ArrayList<>();
-        Double fixedScore = 1.8d;
-        if (hits.size() < 10) {
-            for (Hit<PatentVector> hit : hits) {
+        Double fixedScore = 1.7d;
+        for (Hit<PatentVector> hit : hits) {
+            Double score = hit.score();
+            if (score > fixedScore) {
                 PatentVector vector = hit.source();
                 EsPatentVectorVo vectorVo = new EsPatentVectorVo();
                 BeanUtil.copy(vector, vectorVo);
                 vectorVos.add(vectorVo);
             }
-        } else {
-            for (Hit<PatentVector> hit : hits) {
-                Double score = hit.score();
-                if (score > fixedScore) {
-                    PatentVector vector = hit.source();
-                    EsPatentVectorVo vectorVo = new EsPatentVectorVo();
-                    BeanUtil.copy(vector, vectorVo);
-                    vectorVos.add(vectorVo);
-                }
-            }
         }
 
         Aggregate aggregate = response.aggregations().get("count");
@@ -152,7 +142,7 @@ public class EsDenseVectorService {
         records.setCurrent(pageNum);
         records.setSize(pageSize);
         records.setData(vectorVos);
-        records.setTotal(total);
+        records.setTotal(total <= vectorVos.size() ? total : vectorVos.size());
         return records;
     }