|
@@ -1,6 +1,7 @@
|
|
|
package cn.cslg.pas.service.business.es;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.GetUnselectedDTO;
|
|
|
+import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDetailDTO;
|
|
|
import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
@@ -18,6 +19,8 @@ import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.IEsCountAnalysisBuilder
|
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
+import co.elastic.clients.elasticsearch._types.SortOptions;
|
|
|
+import co.elastic.clients.elasticsearch._types.SortOrder;
|
|
|
import co.elastic.clients.elasticsearch._types.aggregations.*;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
@@ -71,6 +74,7 @@ public class EsCountService {
|
|
|
List<EsCustomFieldValueDTO> customFields = vo.getCustomFields();
|
|
|
Integer taskId = vo.getTaskId();
|
|
|
Integer projectId = vo.getProjectId();
|
|
|
+ String groupField = vo.getGroupField();
|
|
|
EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
HashMap<String, List<EsCountDetailDTO>> map = new HashMap<>();
|
|
|
List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
@@ -88,7 +92,7 @@ public class EsCountService {
|
|
|
valueDTO.setFieldValue(Arrays.asList("\""+value+"\""));
|
|
|
customFields.add(valueDTO);
|
|
|
this.getDatas(searchCondition, "",customFields, taskId, projectId,
|
|
|
- esCountVOS, detailDTOS, esCountDTO, value, map);
|
|
|
+ esCountVOS, detailDTOS, esCountDTO, value, map,groupField);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -100,12 +104,12 @@ public class EsCountService {
|
|
|
condition = countVO.getField() + " = " + "\""+value+"\"";
|
|
|
}
|
|
|
this.getDatas(searchCondition, condition, customFields, taskId, projectId,
|
|
|
- esCountVOS, detailDTOS, esCountDTO, value, map);
|
|
|
+ esCountVOS, detailDTOS, esCountDTO, value, map,groupField);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
this.getDatas(searchCondition, "", customFields, taskId, projectId, countVOS,
|
|
|
- detailDTOS, esCountDTO, "", map);
|
|
|
+ detailDTOS, esCountDTO, "", map,groupField);
|
|
|
}
|
|
|
esCountDTO.setDetailDTOS(detailDTOS);
|
|
|
return esCountDTO;
|
|
@@ -113,7 +117,7 @@ public class EsCountService {
|
|
|
|
|
|
public void getDatas(String searchCondition,String condition, List<EsCustomFieldValueDTO> customFields, Integer taskId,
|
|
|
Integer projectId, List<EsCountVO> countVOS, List<EsCountDetailDTO> detailDTOS,
|
|
|
- EsCountDTO esCountDTO, String firstName, Map<String, List<EsCountDetailDTO>> map) throws Exception {
|
|
|
+ EsCountDTO esCountDTO, String firstName, Map<String, List<EsCountDetailDTO>> map,String groupField) throws Exception {
|
|
|
|
|
|
if (StringUtils.isNotEmpty(condition)) {
|
|
|
if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
@@ -132,6 +136,16 @@ public class EsCountService {
|
|
|
}
|
|
|
}
|
|
|
searchCondition = this.getCondition(searchCondition, taskId, projectId);
|
|
|
+ if (StringUtils.isNotEmpty(groupField) && !groupField.equals("0")) {
|
|
|
+ String groupIdsStr = this.getGroupIds(searchCondition, groupField, projectId);
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ if (StringUtils.isNotEmpty(groupIdsStr) && !groupIdsStr.equals("ids = ")) {
|
|
|
+ searchCondition = searchCondition + " AND " + groupIdsStr;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ searchCondition = groupIdsStr;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
@@ -145,77 +159,133 @@ public class EsCountService {
|
|
|
query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",projectId);
|
|
|
builder.query(query);
|
|
|
}
|
|
|
+ if (query != null) {
|
|
|
+ for (EsCountVO countVO : countVOS) {
|
|
|
+ String field = countVO.getField();
|
|
|
+ String fieldId = countVO.getFieldId();
|
|
|
+ Integer topN = countVO.getTopN();
|
|
|
+ String valueOne = countVO.getValueOne();
|
|
|
+ String valueTwo = countVO.getValueTwo();
|
|
|
+ Integer fieldType = null;
|
|
|
+ String type = countVO.getFieldType();
|
|
|
+ if (StringUtils.isNotEmpty(type) && type.equals("tree")) {
|
|
|
+ fieldType = 6;
|
|
|
+ }
|
|
|
+ String format = countVO.getFormat();
|
|
|
+ List<String> values = countVO.getValues();
|
|
|
+ Aggregation aggregation = this.getAggregation(countVO, projectId, taskId);
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+ //解除最大条数限制
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
|
|
|
- for (EsCountVO countVO : countVOS) {
|
|
|
- String field = countVO.getField();
|
|
|
- String fieldId = countVO.getFieldId();
|
|
|
- Integer topN = countVO.getTopN();
|
|
|
- String valueOne = countVO.getValueOne();
|
|
|
- String valueTwo = countVO.getValueTwo();
|
|
|
- Integer fieldType = null;
|
|
|
- String type = countVO.getFieldType();
|
|
|
- if (StringUtils.isNotEmpty(type) && type.equals("tree")) {
|
|
|
- fieldType = 6;
|
|
|
- }
|
|
|
- String format = countVO.getFormat();
|
|
|
- List<String> values = countVO.getValues();
|
|
|
- Aggregation aggregation = this.getAggregation(countVO, projectId, taskId);
|
|
|
- builder.aggregations("Agg", aggregation);
|
|
|
- //解除最大条数限制
|
|
|
- builder.trackTotalHits(i -> i.enabled(true));
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
- Aggregate agg = response.aggregations().get("Agg");
|
|
|
-
|
|
|
- if (StringUtils.isNotEmpty(field)) {
|
|
|
- if (dateList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getDateCountDTOS(agg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
- } else {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
- }
|
|
|
- } else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
- if (!CollectionUtils.isEmpty(values)) {
|
|
|
- esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
- }
|
|
|
- } else if (nestDateList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
- Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
- this.getDateCountDTOS(termsAgg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
- } else {
|
|
|
- Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
- this.getDateAnalysisDTOS(termsAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
- }
|
|
|
- } else if (nestChildList.contains(field)) {
|
|
|
- Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
- this.getNestedCountDTOS(childAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
- if (!CollectionUtils.isEmpty(values)) {
|
|
|
- esCountDTO.setAllNumber(childAgg.nested().docCount());
|
|
|
- }
|
|
|
- } else if (childList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
- this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query);
|
|
|
- } else {
|
|
|
- this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
|
- detailDTOS, esCountDTO, firstName, map, values);
|
|
|
- }
|
|
|
- } else if (numberList.contains(field)) {
|
|
|
- if (CollectionUtils.isEmpty(values)) {
|
|
|
+ if (StringUtils.isNotEmpty(field)) {
|
|
|
+ if (dateList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ this.getDateCountDTOS(agg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
+ } else {
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
+ } else if (nestedList.contains(field)) {
|
|
|
+ this.getNestedCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ esCountDTO.setAllNumber(agg.nested().docCount());
|
|
|
+ }
|
|
|
+ } else if (nestDateList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
+ this.getDateCountDTOS(termsAgg, field, topN, format, detailDTOS, esCountDTO,valueOne,valueTwo);
|
|
|
+ } else {
|
|
|
+ Aggregate termsAgg = agg.nested().aggregations().get("terms_agg");
|
|
|
+ this.getDateAnalysisDTOS(termsAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
+ } else if (nestChildList.contains(field)) {
|
|
|
+ Aggregate childAgg = agg.children().aggregations().get("childAgg");
|
|
|
+ this.getNestedCountDTOS(childAgg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
+ if (!CollectionUtils.isEmpty(values)) {
|
|
|
+ esCountDTO.setAllNumber(childAgg.nested().docCount());
|
|
|
+ }
|
|
|
+ } else if (childList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
+ this.getChildCountDTOS(agg, field, fieldType, topN, detailDTOS, esCountDTO,projectId,fieldId,query);
|
|
|
+ } else {
|
|
|
+ this.getChildAnalysisDTOS(agg, field, fieldType, topN,
|
|
|
+ detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
+ } else if (numberList.contains(field)) {
|
|
|
+ if (CollectionUtils.isEmpty(values)) {
|
|
|
|
|
|
+ } else {
|
|
|
+ this.getNumberAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ }
|
|
|
} else {
|
|
|
- this.getNumberAnalysisDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values);
|
|
|
+ this.getTermCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
}
|
|
|
} else {
|
|
|
- this.getTermCountDTOS(agg, field, topN, detailDTOS, esCountDTO, firstName, map, values,valueOne);
|
|
|
+ this.getFilterCountDTO(agg, searchCondition, detailDTOS);
|
|
|
}
|
|
|
- } else {
|
|
|
- this.getFilterCountDTO(agg, searchCondition, detailDTOS);
|
|
|
+ esCountDTO.setCondition(searchCondition);
|
|
|
+ esCountDTO.setAnalyseMap(map);
|
|
|
}
|
|
|
- esCountDTO.setCondition(searchCondition);
|
|
|
- esCountDTO.setAnalyseMap(map);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public String getGroupIds(String searchCondition, String groupField, Integer projectId) throws Exception {
|
|
|
+ String result = "";
|
|
|
+ //判断同族分组
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ Query query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent", projectId);
|
|
|
+ builder.query(query);
|
|
|
+ //判断同族分组
|
|
|
+ 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(0).size(9999999));
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ builder.size(100);
|
|
|
+ //解除最大条数限制
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
+ List<StringTermsBucket> termsBuckets = agg.sterms().buckets().array();
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (StringTermsBucket termsBucket : termsBuckets) {
|
|
|
+ String key = termsBucket.key().stringValue();
|
|
|
+ PatentColumnDTO columnDTO = esService.getPatentColumnDTO(key, projectId, esField);
|
|
|
+ list.add(columnDTO.getPatentId());
|
|
|
+ }
|
|
|
+ result = esService.appendIds(list);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
public EsDateRangeDTO getFieldRange(EsDateRangeVO rangeVO) throws Exception {
|
|
|
String searchCondition = rangeVO.getCondition();
|
|
|
String field = rangeVO.getField();
|