|
|
@@ -26,6 +26,7 @@ import co.elastic.clients.elasticsearch._types.*;
|
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.*;
|
|
|
import co.elastic.clients.elasticsearch.core.*;
|
|
|
+import co.elastic.clients.elasticsearch.core.search.FieldCollapse;
|
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
import co.elastic.clients.json.JsonData;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
@@ -159,21 +160,10 @@ public class EsService {
|
|
|
searchCondition = stringBuilder.toString();
|
|
|
}
|
|
|
//判断同族分组
|
|
|
- String str = "";
|
|
|
- if (StringUtils.isNotEmpty(groupField)) {
|
|
|
- switch (groupField) {
|
|
|
- case "simpleFamilyId":
|
|
|
- str = "simple_family_id";
|
|
|
- break;
|
|
|
- case "inpadocFamilyId":
|
|
|
- str = "inpadoc_family_id";
|
|
|
- break;
|
|
|
- case "patsnapFamilyId":
|
|
|
- str = "patsnap_family_id";
|
|
|
- break;
|
|
|
- }
|
|
|
+ String esField = "";
|
|
|
+ if (StringUtils.isNotEmpty(groupField) && !groupField.equals("0")) {
|
|
|
+ esField = this.getGroupField(groupField);
|
|
|
}
|
|
|
- String esField = str;
|
|
|
EsPatentCommonVO commonVO = new EsPatentCommonVO();
|
|
|
commonVO.setTaskId(taskId);
|
|
|
commonVO.setProjectId(projectId);
|
|
|
@@ -186,38 +176,23 @@ public class EsService {
|
|
|
commonVO.setCustomFields(queryRequest.getCustomFields());
|
|
|
commonVO.setOrderDTOList(queryRequest.getOrderDTOList());
|
|
|
SearchRequest.Builder builder = this.getCommonPatent(commonVO);
|
|
|
-
|
|
|
- //分页
|
|
|
- if (current != null && size != null && current > 0 && size > 0) {
|
|
|
- builder.from((current.intValue() - 1) * size.intValue()).size(size.intValue());
|
|
|
- } else {
|
|
|
- builder.from(0).size(99999);
|
|
|
- }
|
|
|
-
|
|
|
//解除最大条数限制
|
|
|
builder.trackTotalHits(i -> i.enabled(true));
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
List<PatentColumnDTO> list = new ArrayList<>();
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
long total = 0L;
|
|
|
if (StringUtils.isNotEmpty(esField)) {
|
|
|
- Aggregate statsAgg = response.aggregations().get("statsBucket");
|
|
|
- total = statsAgg.statsBucket().count();
|
|
|
- Aggregate agg = response.aggregations().get("Agg");
|
|
|
- List<StringTermsBucket> termsBuckets = agg.sterms().buckets().array();
|
|
|
- for (StringTermsBucket termsBucket : termsBuckets) {
|
|
|
- String key = termsBucket.key().stringValue();
|
|
|
- PatentColumnDTO columnDTO = this.getPatentColumnDTOByGroup(key, projectId, esField);
|
|
|
- list.add(columnDTO);
|
|
|
- }
|
|
|
+ Aggregate aggregate = response.aggregations().get("count");
|
|
|
+ total = aggregate.cardinality().value();
|
|
|
} else {
|
|
|
- List<Hit<Patent>> hits = response.hits().hits();
|
|
|
total = response.hits().total().value();
|
|
|
- for (Hit<Patent> hit : hits) {
|
|
|
- String id = hit.id();
|
|
|
- Patent esMess = hit.source();
|
|
|
- PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
|
|
|
- list.add(columnDTO);
|
|
|
- }
|
|
|
+ }
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+ String id = hit.id();
|
|
|
+ Patent esMess = hit.source();
|
|
|
+ PatentColumnDTO columnDTO = this.getPatentColumnDTO(esMess, projectId, id);
|
|
|
+ list.add(columnDTO);
|
|
|
}
|
|
|
this.loadCoulumnDTO(list);
|
|
|
dto.setTotal(total);
|
|
|
@@ -227,6 +202,26 @@ public class EsService {
|
|
|
return dto;
|
|
|
}
|
|
|
|
|
|
+ //获取分组字段栏位
|
|
|
+ public String getGroupField(String groupField) {
|
|
|
+ String esField = "";
|
|
|
+ switch (groupField) {
|
|
|
+ case "simpleFamilyId":
|
|
|
+ esField = "simple_family_id";
|
|
|
+ break;
|
|
|
+ case "inpadocFamilyId":
|
|
|
+ esField = "inpadoc_family_id";
|
|
|
+ break;
|
|
|
+ case "patsnapFamilyId":
|
|
|
+ esField = "patsnap_family_id";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ esField = "0";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return esField;
|
|
|
+ }
|
|
|
+
|
|
|
//获取通用检索专利方法--服务检索专利清单
|
|
|
public SearchRequest.Builder getCommonPatent(EsPatentCommonVO commonVO) throws Exception {
|
|
|
String esField = commonVO.getEsField();
|
|
|
@@ -253,28 +248,21 @@ public class EsService {
|
|
|
builder.index("patent");
|
|
|
|
|
|
Query reQuery = esPatentService.getEntireNotInQuery(commonVO);
|
|
|
- builder.query(reQuery);
|
|
|
+
|
|
|
//判断同族分组
|
|
|
if (StringUtils.isNotEmpty(esField)) {
|
|
|
- List<SortOptions> options = new ArrayList<>();
|
|
|
- SortOptions appDate = SortOptions.of(i -> i.field(j -> j.field("app_date").order(SortOrder.Asc)));
|
|
|
- options.add(appDate);
|
|
|
- Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from(pageFrom).size(pageSize));
|
|
|
- Aggregation aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
- .field(esField).size(100000).build())
|
|
|
- .aggregations(new HashMap() {{
|
|
|
- put("hitAgg", bucketSort);
|
|
|
- }}).build();
|
|
|
- builder.aggregations("Agg", aggregation);
|
|
|
- //对聚合结果统计出总数
|
|
|
- Aggregation terms = AggregationBuilders.terms(i -> i.field(esField).size(100000));
|
|
|
- builder.aggregations("termAgg", terms);
|
|
|
- BucketsPath bucketsPath = BucketsPath.of(i -> i.single("termAgg>_count"));
|
|
|
- Aggregation statsBucket = AggregationBuilders.statsBucket(i -> i.bucketsPath(bucketsPath));
|
|
|
- builder.aggregations("statsBucket", statsBucket);
|
|
|
+ Query existQ = QueryBuilders.exists(i -> i.field(esField));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(reQuery, existQ));
|
|
|
+ builder.query(bool);
|
|
|
+ FieldCollapse collapse = FieldCollapse.of(i -> i.field(esField));
|
|
|
+ builder.collapse(collapse);
|
|
|
+ //统计总数
|
|
|
+ Aggregation aggregation = AggregationBuilders.cardinality(i -> i.field(esField));
|
|
|
+ builder.aggregations("count", aggregation);
|
|
|
} else {
|
|
|
- builder.from(pageFrom).size(pageSize);
|
|
|
+ builder.query(reQuery);
|
|
|
}
|
|
|
+ builder.from(pageFrom).size(pageSize);
|
|
|
|
|
|
//排序
|
|
|
List<OrderDTO> dtoList = commonVO.getOrderDTOList();
|
|
|
@@ -286,28 +274,21 @@ public class EsService {
|
|
|
//获取通用检索专利方法--服务于批量删除、标引、查询价值曲线、导出excel、pdf首页
|
|
|
public SearchRequest.Builder getCommonPatentByGroup(EsPatentCommonVO commonVO) throws Exception {
|
|
|
String esField = commonVO.getEsField();
|
|
|
- Long current = commonVO.getCurrent();
|
|
|
- Long size = commonVO.getSize();
|
|
|
Query reQuery = esPatentService.getEntireNotInQuery(commonVO);
|
|
|
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
|
builder.index("patent");
|
|
|
- builder.query(reQuery);
|
|
|
//判断同族分组
|
|
|
if (StringUtils.isNotEmpty(esField)) {
|
|
|
- List<SortOptions> options = new ArrayList<>();
|
|
|
- SortOptions appDate = SortOptions.of(i -> i.field(j -> j.field("app_date").order(SortOrder.Asc)));
|
|
|
- options.add(appDate);
|
|
|
- Aggregation bucketSort = AggregationBuilders.bucketSort(i -> i.from(current.intValue() - 1).size(size.intValue()));
|
|
|
- Aggregation aggregation = new Aggregation.Builder().terms(new TermsAggregation.Builder()
|
|
|
- .field(esField).size(100000).build())
|
|
|
- .aggregations(new HashMap() {{
|
|
|
- put("hitAgg", bucketSort);
|
|
|
- }}).build();
|
|
|
- builder.aggregations("Agg", aggregation);
|
|
|
+ Query existQ = QueryBuilders.exists(i -> i.field(esField));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(reQuery, existQ));
|
|
|
+ builder.query(bool);
|
|
|
+ FieldCollapse collapse = FieldCollapse.of(i -> i.field(esField));
|
|
|
+ builder.collapse(collapse);
|
|
|
+ } else {
|
|
|
+ builder.query(reQuery);
|
|
|
}
|
|
|
-
|
|
|
//排序
|
|
|
List<OrderDTO> dtoList = commonVO.getOrderDTOList();
|
|
|
List<SortOptions> optionsList = this.getCommonSortMethod(dtoList);
|
|
|
@@ -315,28 +296,6 @@ public class EsService {
|
|
|
return builder;
|
|
|
}
|
|
|
|
|
|
- //封装专利清单的同族分组
|
|
|
- public PatentColumnDTO getPatentColumnDTOByGroup(String key, Integer projectId, String field) throws Exception {
|
|
|
- PatentColumnDTO dto = new PatentColumnDTO();
|
|
|
- SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
- //设置查询索引
|
|
|
- builder.index("patent");
|
|
|
- Query query = QueryBuilders.term(i -> i.field("project_id").value(projectId));
|
|
|
- Query q1 = QueryBuilders.hasChild(i -> i.type("project").query(query));
|
|
|
- Query q2 = QueryBuilders.term(i -> i.field(field).value(key));
|
|
|
- Query bool = QueryBuilders.bool(i -> i.must(q1, q2));
|
|
|
- builder.query(bool);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
- List<Hit<Patent>> hits = response.hits().hits();
|
|
|
- if (!CollectionUtils.isEmpty(hits)) {
|
|
|
- String id = hits.get(0).id();
|
|
|
- Patent patent = hits.get(0).source();
|
|
|
- dto = this.getPatentColumnDTO(patent, projectId, id);
|
|
|
- dto.setPatentId(id);
|
|
|
- }
|
|
|
- return dto;
|
|
|
- }
|
|
|
-
|
|
|
public PatentWithIdVO getPatentColumnDTOByGroup2(String key, Integer projectId, String field) throws Exception {
|
|
|
PatentWithIdVO dto = new PatentWithIdVO();
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|