|
@@ -8,6 +8,7 @@ import cn.cslg.pas.common.dto.PatentStarListDTO;
|
|
|
import cn.cslg.pas.common.dto.business.ContentDetailDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsPatentFamilyDTO;
|
|
|
import cn.cslg.pas.common.dto.business.SelectClaimDTO;
|
|
|
+import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
|
import cn.cslg.pas.common.model.request.MapRequest;
|
|
|
import cn.cslg.pas.common.model.request.OrderDTO;
|
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
@@ -119,7 +120,6 @@ public class EsService {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* Es检索
|
|
|
*
|
|
@@ -130,6 +130,10 @@ public class EsService {
|
|
|
PatentDTO dto = new PatentDTO();
|
|
|
|
|
|
String searchCondition = "";
|
|
|
+ List<EsCustomFieldValueDTO> customFields = queryRequest.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ searchCondition = this.parseCustomField(customFields);
|
|
|
+ }
|
|
|
Integer projectId = queryRequest.getProjectId();
|
|
|
Long current = queryRequest.getCurrent();
|
|
|
Long size = queryRequest.getSize();
|
|
@@ -221,6 +225,167 @@ public class EsService {
|
|
|
return dto;
|
|
|
}
|
|
|
|
|
|
+ public PatentDTO esSearch(QueryRequest queryRequest, List<EsCustomFieldValueDTO> customFields) throws Exception {
|
|
|
+ PatentDTO dto = new PatentDTO();
|
|
|
+
|
|
|
+ String searchCondition = "";
|
|
|
+// List<EsCustomFieldValueDTO> customFields = queryRequest.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ searchCondition = this.parseCustomField(customFields);
|
|
|
+ }
|
|
|
+ Integer projectId = queryRequest.getProjectId();
|
|
|
+ Long current = queryRequest.getCurrent();
|
|
|
+ Long size = queryRequest.getSize();
|
|
|
+ //判断表达式
|
|
|
+ if (queryRequest instanceof StringRequest) {
|
|
|
+ searchCondition = ((StringRequest) queryRequest).getSearchQuery();
|
|
|
+ } else if (queryRequest instanceof MapRequest) {
|
|
|
+ Map<String, Object> map = ((MapRequest) queryRequest).getSearchQuery();
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ for (String key : map.keySet()) {
|
|
|
+ Object value = map.get(key);
|
|
|
+ if (!"".contentEquals(stringBuilder)) {
|
|
|
+ stringBuilder = stringBuilder.append(" AND ").append(key).append("=").append(value);
|
|
|
+ } else {
|
|
|
+ stringBuilder = stringBuilder.append(key).append("=").append(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ searchCondition = stringBuilder.toString();
|
|
|
+ }
|
|
|
+ if (projectId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "projectId = " + projectId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "projectId = " + projectId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ //4. 返回数据
|
|
|
+ builder.query(q);
|
|
|
+ //排序
|
|
|
+ List<OrderDTO> dtoList = queryRequest.getOrderDTOList();
|
|
|
+ if (!CollectionUtils.isEmpty(dtoList)) {
|
|
|
+ for (OrderDTO orderDTO : dtoList) {
|
|
|
+ if (orderDTO.getOrderType().equals(IfConstant.NO)) {
|
|
|
+ builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
+ .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
+ .field(orderDTO.getOrderBy()).order(SortOrder.Asc)));
|
|
|
+ } else {
|
|
|
+ builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
+ .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
+ .field(orderDTO.getOrderBy()).order(SortOrder.Desc)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ builder.sort(sortOptionsBuilder -> sortOptionsBuilder
|
|
|
+ .field(fieldSortBuilder -> fieldSortBuilder
|
|
|
+ .field("patent_no.keyword").order(SortOrder.Desc)));
|
|
|
+ }
|
|
|
+
|
|
|
+ //分页
|
|
|
+ if (current > 0 && size > 0) {
|
|
|
+ builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ List<PatentColumnDTO> list = new ArrayList<>();
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ long total = response.hits().total().value();
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+ Patent esMess = hit.source();
|
|
|
+ PatentColumnDTO columnDTO = new PatentColumnDTO();
|
|
|
+// columnDTO.setPatentNo(esMess.getPatentNo());
|
|
|
+ BeanUtils.copyProperties(esMess, columnDTO);
|
|
|
+ ContentVO titleVO = new ContentVO();
|
|
|
+ String title = StringUtils.strip(JSON.toJSONString(esMess.getTitle()), "[]");
|
|
|
+ ContentDetailDTO titleContent = JSONObject.parseObject(title, ContentDetailDTO.class);
|
|
|
+ titleVO.setContent(titleContent.getTextContent());
|
|
|
+ columnDTO.setTitle(titleVO);
|
|
|
+ ContentVO abstractVO = new ContentVO();
|
|
|
+ String abstractStr = StringUtils.strip(JSON.toJSONString(esMess.getAbstractStr()), "[]");
|
|
|
+ ContentDetailDTO abstractContent = JSONObject.parseObject(abstractStr, ContentDetailDTO.class);
|
|
|
+ abstractVO.setContent(abstractContent.getTextContent());
|
|
|
+ columnDTO.setAbstractStr(abstractVO);
|
|
|
+ list.add(columnDTO);
|
|
|
+
|
|
|
+ }
|
|
|
+ this.loadCoulumnDTO(list);
|
|
|
+ dto.setTotal(total);
|
|
|
+ dto.setPatents(list);
|
|
|
+ dto.setPageNum(current);
|
|
|
+ dto.setPageSize(size);
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析自定义栏位和值
|
|
|
+ *
|
|
|
+ * @param customFields
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String parseCustomField(List<EsCustomFieldValueDTO> customFields) {
|
|
|
+ int m = 1;
|
|
|
+ int n = 0;
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ if (customFields.size() > m) {
|
|
|
+ builder.append("(");
|
|
|
+ for (int i = 0; i < customFields.size(); i++) {
|
|
|
+ EsCustomFieldValueDTO customField = customFields.get(i);
|
|
|
+ if (i != n) {
|
|
|
+ builder.append(" ").append("and").append(" ").append("(");
|
|
|
+ this.appendStr(customField, builder, m);
|
|
|
+ } else {
|
|
|
+ this.appendStr(customField, builder, m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (int i = 0; i < customFields.size(); i++) {
|
|
|
+ EsCustomFieldValueDTO customField = customFields.get(i);
|
|
|
+ int num = customFields.size() - m;
|
|
|
+ if (i != n) {
|
|
|
+ builder.append(" ").append("and").append(" ");
|
|
|
+ this.appendStr(customField, builder, m);
|
|
|
+ } else {
|
|
|
+ this.appendStr(customField, builder, m);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ System.out.println("耗时" + (end - start));
|
|
|
+ return builder.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void appendStr(EsCustomFieldValueDTO customField, StringBuilder builder, int m) {
|
|
|
+ List<String> values = customField.getFieldValue();
|
|
|
+ builder.append("field").append("=").append(customField.getFieldId());
|
|
|
+ builder.append(" ").append("and").append(" ");
|
|
|
+ builder.append("fieldValue").append("=");
|
|
|
+ if (values.size() > m) {
|
|
|
+ builder.append("(");
|
|
|
+ for (int j = 0; j < values.size(); j++) {
|
|
|
+ String s = values.get(j);
|
|
|
+ if (j != values.size() - m) {
|
|
|
+ builder.append(s).append(" ").append("or").append(" ");
|
|
|
+ } else {
|
|
|
+ builder.append(s).append(")").append(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for (String value : values) {
|
|
|
+ builder.append(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param key
|
|
|
* @param page
|
|
@@ -263,7 +428,6 @@ public class EsService {
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public Integer updatePatent(Patent patent, String id) {
|
|
|
UpdateRequest<Patent, Patent> req;
|
|
|
req = UpdateRequest.of(
|
|
@@ -750,6 +914,7 @@ public class EsService {
|
|
|
|
|
|
/**
|
|
|
* 查询权利要求
|
|
|
+ *
|
|
|
* @param patentNo
|
|
|
* @return
|
|
|
*/
|
|
@@ -767,7 +932,7 @@ public class EsService {
|
|
|
//授权号
|
|
|
Query q3 = QueryBuilders.term(t -> t.field("grant_no.keyword").value(patentNo));
|
|
|
Query query = QueryBuilders.bool(i -> i.should(q1, q2, q3));
|
|
|
- Query bool = QueryBuilders.bool(i -> i.must(q,query));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q, query));
|
|
|
builder.query(bool);
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
SelectClaimDTO dto = new SelectClaimDTO();
|
|
@@ -785,17 +950,43 @@ public class EsService {
|
|
|
return dto;
|
|
|
}
|
|
|
|
|
|
-public List<PatentColumnDTO> loadCoulumnDTO(List<PatentColumnDTO> patentColumnDTOS){
|
|
|
- patentColumnDTOS.forEach(item->{
|
|
|
+ public List<PatentColumnDTO> loadCoulumnDTO(List<PatentColumnDTO> patentColumnDTOS) {
|
|
|
+ patentColumnDTOS.forEach(item -> {
|
|
|
item.setPictureGuid(FormatUtil.getPictureFormat(item.getAppNo()));
|
|
|
|
|
|
});
|
|
|
|
|
|
-return patentColumnDTOS;
|
|
|
-}
|
|
|
-
|
|
|
+ return patentColumnDTOS;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 根据专利号查询出其他专利号
|
|
|
+ * @param patentNos
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public SelectClaimDTO selectPatentNo(List<String> patentNos) throws IOException {
|
|
|
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ List<Query> queryList = new ArrayList<>();
|
|
|
+ for (String patentNo : patentNos) {
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("patent_no.keyword").value(patentNo));
|
|
|
+ queryList.add(q1);
|
|
|
+ }
|
|
|
+ //申请号
|
|
|
+ Query query = QueryBuilders.bool(i -> i.mustNot(queryList));
|
|
|
+ builder.query(query);
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ SelectClaimDTO dto = new SelectClaimDTO();
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ long value = response.hits().total().value();
|
|
|
+ if (value > 1) {
|
|
|
+ System.out.println("====================" + value);
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|