|
@@ -7,6 +7,7 @@ import cn.cslg.pas.common.dto.PatentDTO;
|
|
import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
|
|
import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
|
|
import cn.cslg.pas.common.dto.business.SelectClaimDTO;
|
|
import cn.cslg.pas.common.dto.business.SelectClaimDTO;
|
|
import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
|
|
+import cn.cslg.pas.common.model.es.GetVectorVO;
|
|
import cn.cslg.pas.common.model.request.MapRequest;
|
|
import cn.cslg.pas.common.model.request.MapRequest;
|
|
import cn.cslg.pas.common.model.request.OrderDTO;
|
|
import cn.cslg.pas.common.model.request.OrderDTO;
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
@@ -22,6 +23,7 @@ import cn.cslg.pas.exception.XiaoShiException;
|
|
import cn.cslg.pas.service.business.AssoProjectPersonService;
|
|
import cn.cslg.pas.service.business.AssoProjectPersonService;
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
import cn.cslg.pas.service.common.PatentStarApiService;
|
|
import cn.cslg.pas.service.common.PatentStarApiService;
|
|
|
|
+import cn.cslg.pas.service.common.PythonApiService;
|
|
import cn.cslg.pas.service.importPatent.WebVOTransformService;
|
|
import cn.cslg.pas.service.importPatent.WebVOTransformService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
@@ -57,7 +59,7 @@ import static org.springframework.data.elasticsearch.annotations.TermVector.no;
|
|
public class EsService {
|
|
public class EsService {
|
|
public final List<String> dateList = Arrays.asList("AD", "PD", "GD", "EXD", "PAD", "PED", "PPD", "EPD");
|
|
public final List<String> dateList = Arrays.asList("AD", "PD", "GD", "EXD", "PAD", "PED", "PPD", "EPD");
|
|
private final ElasticsearchClient client;
|
|
private final ElasticsearchClient client;
|
|
-
|
|
|
|
|
|
+ private final PythonApiService pythonApiService;
|
|
@Autowired
|
|
@Autowired
|
|
private EsFamilyService esFamilyService;
|
|
private EsFamilyService esFamilyService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -69,8 +71,9 @@ public class EsService {
|
|
private EsCountService esCountService;
|
|
private EsCountService esCountService;
|
|
@Autowired
|
|
@Autowired
|
|
private EsCustomFieldService esCustomFieldService;
|
|
private EsCustomFieldService esCustomFieldService;
|
|
- @Autowired
|
|
|
|
- private AssoProjectPersonService assoProjectPersonService;
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private AssoProjectPersonService assoProjectPersonService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param patent
|
|
* @param patent
|
|
* @throws Exception
|
|
* @throws Exception
|
|
@@ -189,6 +192,7 @@ public class EsService {
|
|
commonVO.setEsField(esField);
|
|
commonVO.setEsField(esField);
|
|
commonVO.setCustomFields(queryRequest.getCustomFields());
|
|
commonVO.setCustomFields(queryRequest.getCustomFields());
|
|
commonVO.setOrderDTOList(queryRequest.getOrderDTOList());
|
|
commonVO.setOrderDTOList(queryRequest.getOrderDTOList());
|
|
|
|
+ commonVO.setSemanteme(queryRequest.getSemanteme());
|
|
SearchRequest.Builder builder = this.getCommonPatent(commonVO);
|
|
SearchRequest.Builder builder = this.getCommonPatent(commonVO);
|
|
//解除最大条数限制
|
|
//解除最大条数限制
|
|
builder.trackTotalHits(i -> i.enabled(true));
|
|
builder.trackTotalHits(i -> i.enabled(true));
|
|
@@ -196,6 +200,7 @@ public class EsService {
|
|
try {
|
|
try {
|
|
response = client.search(builder.build(), Patent.class);
|
|
response = client.search(builder.build(), Patent.class);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
throw new XiaoShiException("检索错误,请检查检索式");
|
|
throw new XiaoShiException("检索错误,请检查检索式");
|
|
}
|
|
}
|
|
List<PatentColumnDTO> list = new ArrayList<>();
|
|
List<PatentColumnDTO> list = new ArrayList<>();
|
|
@@ -208,9 +213,14 @@ public class EsService {
|
|
total = response.hits().total().value();
|
|
total = response.hits().total().value();
|
|
}
|
|
}
|
|
for (Hit<Patent> hit : hits) {
|
|
for (Hit<Patent> hit : hits) {
|
|
|
|
+ Double score= hit.score();
|
|
|
|
+
|
|
|
|
+ String str = String.format("%.4f",score);
|
|
|
|
+ double four = Double.parseDouble(str);
|
|
String id = hit.id();
|
|
String id = hit.id();
|
|
Patent esMess = hit.source();
|
|
Patent esMess = hit.source();
|
|
PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
|
|
PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
|
|
|
|
+ columnDTO.setScore(four);
|
|
list.add(columnDTO);
|
|
list.add(columnDTO);
|
|
}
|
|
}
|
|
this.loadCoulumnDTO(list);
|
|
this.loadCoulumnDTO(list);
|
|
@@ -250,6 +260,7 @@ public class EsService {
|
|
Long size = commonVO.getSize();
|
|
Long size = commonVO.getSize();
|
|
Long startNum = commonVO.getStartNum();
|
|
Long startNum = commonVO.getStartNum();
|
|
Long endNum = commonVO.getEndNum();
|
|
Long endNum = commonVO.getEndNum();
|
|
|
|
+ String semanteme = commonVO.getSemanteme();
|
|
Integer temPageFrom = 0;
|
|
Integer temPageFrom = 0;
|
|
Integer temPageSize = 100000;
|
|
Integer temPageSize = 100000;
|
|
if (current != null && size != null) {
|
|
if (current != null && size != null) {
|
|
@@ -266,8 +277,8 @@ public class EsService {
|
|
//设置查询索引
|
|
//设置查询索引
|
|
builder.index("patent");
|
|
builder.index("patent");
|
|
|
|
|
|
- Query reQuery = esPatentService.getEntireNotInQuery(commonVO);
|
|
|
|
-
|
|
|
|
|
|
+ Query reTmQuery = esPatentService.getEntireNotInQuery(commonVO);
|
|
|
|
+ Query reQuery = this.getMeanSearch(reTmQuery, semanteme);
|
|
//判断同族分组
|
|
//判断同族分组
|
|
if (StringUtils.isNotEmpty(esField)) {
|
|
if (StringUtils.isNotEmpty(esField)) {
|
|
Query existQ = QueryBuilders.exists(i -> i.field(esField));
|
|
Query existQ = QueryBuilders.exists(i -> i.field(esField));
|
|
@@ -284,9 +295,11 @@ public class EsService {
|
|
builder.from(pageFrom).size(pageSize);
|
|
builder.from(pageFrom).size(pageSize);
|
|
|
|
|
|
//排序
|
|
//排序
|
|
- List<OrderDTO> dtoList = commonVO.getOrderDTOList();
|
|
|
|
- List<SortOptions> optionsList = this.getCommonSortMethod(dtoList);
|
|
|
|
- builder.sort(optionsList);
|
|
|
|
|
|
+ if (semanteme == null || semanteme.trim().equals("")) {
|
|
|
|
+ List<OrderDTO> dtoList = commonVO.getOrderDTOList();
|
|
|
|
+ List<SortOptions> optionsList = this.getCommonSortMethod(dtoList);
|
|
|
|
+ builder.sort(optionsList);
|
|
|
|
+ }
|
|
return builder;
|
|
return builder;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1483,19 +1496,40 @@ public class EsService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- public void judgeQueryPatentRoot(QueryRequest queryRequest){
|
|
|
|
|
|
+ public void judgeQueryPatentRoot(QueryRequest queryRequest) {
|
|
|
|
|
|
Integer projectId = queryRequest.getProjectId();
|
|
Integer projectId = queryRequest.getProjectId();
|
|
Integer productId = queryRequest.getProductId();
|
|
Integer productId = queryRequest.getProductId();
|
|
String productFrom = queryRequest.getFrom();
|
|
String productFrom = queryRequest.getFrom();
|
|
- if(projectId!=null) {
|
|
|
|
|
|
+ if (projectId != null) {
|
|
List<Integer> ids = assoProjectPersonService.getRootProjectIds();
|
|
List<Integer> ids = assoProjectPersonService.getRootProjectIds();
|
|
- if (ids!=null&&(ids.size() == 0||!ids.contains(projectId))) {
|
|
|
|
- throw new XiaoShiException(ExceptionEnum.PERMISSION_ERROR,"无法查询此专题库专利");
|
|
|
|
|
|
+ if (ids != null && (ids.size() == 0 || !ids.contains(projectId))) {
|
|
|
|
+ throw new XiaoShiException(ExceptionEnum.PERMISSION_ERROR, "无法查询此专题库专利");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public Query getMeanSearch(Query query, String mean) {
|
|
|
|
+
|
|
|
|
+ if (mean != null && !mean.trim().equals("")) {
|
|
|
|
+ GetVectorVO getVectorVO = new GetVectorVO();
|
|
|
|
+ getVectorVO.setText(mean);
|
|
|
|
+ List<Float> floatList = pythonApiService.getStrVector(getVectorVO);
|
|
|
|
+ JsonData b = JsonData.of(floatList);
|
|
|
|
+ System.out.println(b);
|
|
|
|
+ String source = "if (!doc['abstract_vector'].isEmpty()) {return cosineSimilarity(params.queryVector,'abstract_vector');} else {return 0.1; }";
|
|
|
|
+ InlineScript inlineScript = InlineScript.of(i -> i.source(source).lang("painless").params("queryVector", JsonData.of(floatList)));
|
|
|
|
+ Script script = Script.of(i -> i.inline(inlineScript));
|
|
|
|
+ Query newQuery = QueryBuilders.scriptScore(i -> i.script(script)
|
|
|
|
+ .query(query));
|
|
|
|
+ String a = newQuery.toString();
|
|
|
|
+ System.out.println(a);
|
|
|
|
+ return newQuery;
|
|
|
|
+ }
|
|
|
|
+ return query;
|
|
|
|
+
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|