|
@@ -16,11 +16,14 @@ import com.example.xiaoshiweixinback.business.utils.ToolUtil;
|
|
import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.expressManager;
|
|
import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.expressManager;
|
|
import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.operateNode;
|
|
import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.operateNode;
|
|
import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.treeNode;
|
|
import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.treeNode;
|
|
|
|
+import com.example.xiaoshiweixinback.domain.Product;
|
|
import com.example.xiaoshiweixinback.domain.es.PatentVector;
|
|
import com.example.xiaoshiweixinback.domain.es.PatentVector;
|
|
import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
|
|
import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPictureNoDTO;
|
|
import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPatentVectorDTO;
|
|
import com.example.xiaoshiweixinback.entity.dto.esPicture.EsPatentVectorDTO;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.product.ProductIdDTO;
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPictureNoVo;
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPatentVectorVo;
|
|
import com.example.xiaoshiweixinback.entity.vo.esPicture.EsPatentVectorVo;
|
|
|
|
+import com.example.xiaoshiweixinback.mapper.ProductMapper;
|
|
import com.example.xiaoshiweixinback.service.importPatent.FormatQueryService;
|
|
import com.example.xiaoshiweixinback.service.importPatent.FormatQueryService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -31,6 +34,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
+import java.text.ParseException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -48,6 +52,9 @@ public class EsDenseVectorService {
|
|
@Autowired
|
|
@Autowired
|
|
private GetVectorService getVectorService;
|
|
private GetVectorService getVectorService;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ProductMapper productMapper;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 根据图片排序获取列表
|
|
* 根据图片排序获取列表
|
|
*
|
|
*
|
|
@@ -63,18 +70,13 @@ public class EsDenseVectorService {
|
|
//设置查询索引
|
|
//设置查询索引
|
|
builder.index("patent_vector");
|
|
builder.index("patent_vector");
|
|
Query q = null;
|
|
Query q = null;
|
|
- //获取关键词
|
|
|
|
- if (StringUtils.isNotEmpty(dto.getKey())) {
|
|
|
|
-// String key = dto.getKey().replaceAll("[,。、;,./;\\s]"," OR ");
|
|
|
|
- String key = dto.getKey().replaceAll("[,。、;,./;]"," OR ");
|
|
|
|
- String condition = "TI = " + "(" + key + ")";
|
|
|
|
|
|
+ String condition = this.appendCondition(dto.getProductId(), dto.getKey());
|
|
|
|
+ if (StringUtils.isNotEmpty(condition)) {
|
|
//1. 解析检索条件
|
|
//1. 解析检索条件
|
|
treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
- //3. 从es中检索数据
|
|
|
|
|
|
+ //2. 从es中检索数据
|
|
q = formatQueryService.EsQueryToQuery((operateNode) tree, "patentVector", null);
|
|
q = formatQueryService.EsQueryToQuery((operateNode) tree, "patentVector", null);
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
//获取图片向量
|
|
//获取图片向量
|
|
List<Float> imageList = new ArrayList<>();
|
|
List<Float> imageList = new ArrayList<>();
|
|
List<String> stringList = new ArrayList<>();
|
|
List<String> stringList = new ArrayList<>();
|
|
@@ -164,4 +166,29 @@ public class EsDenseVectorService {
|
|
}
|
|
}
|
|
return pictureNoVos.stream().sorted(Comparator.comparing(EsPictureNoVo::getImageIndex)).collect(Collectors.toList());
|
|
return pictureNoVos.stream().sorted(Comparator.comparing(EsPictureNoVo::getImageIndex)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public String appendCondition(Integer productId,String keyword) throws Exception {
|
|
|
|
+ String condition = "";
|
|
|
|
+ String searchCondition = "";
|
|
|
|
+ if (productId != null) {
|
|
|
|
+ Product product = productMapper.selectById(productId);
|
|
|
|
+ searchCondition = product.getSearchCondition();
|
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
}
|
|
}
|