|
@@ -14,6 +14,8 @@ import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
import cn.cslg.pas.factorys.EsAnalysisBuilderFactory.EsAnalysisBuilderFactory;
|
|
|
import cn.cslg.pas.factorys.EsAnalysisBuilderFactory.IEsAnalysisBuilder;
|
|
|
+import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.EsCountAnalysisBuilderFactory;
|
|
|
+import cn.cslg.pas.factorys.EsCountAnalyseBuilderFactory.IEsCountAnalysisBuilder;
|
|
|
import cn.cslg.pas.factorys.EsCountBuilderFactory.EsCountBuilderFactory;
|
|
|
import cn.cslg.pas.factorys.EsCountBuilderFactory.IEsCountBuilder;
|
|
|
import cn.cslg.pas.service.business.CommonService;
|
|
@@ -52,6 +54,8 @@ public class EsCountService {
|
|
|
@Autowired
|
|
|
private EsAnalysisBuilderFactory esAnalysisBuilderFactory;
|
|
|
@Autowired
|
|
|
+ private EsCountAnalysisBuilderFactory esCountAnalysisBuilderFactory;
|
|
|
+ @Autowired
|
|
|
private FormatQueryService formatQueryService;
|
|
|
@Autowired
|
|
|
private EsService esService;
|
|
@@ -71,7 +75,7 @@ public class EsCountService {
|
|
|
}
|
|
|
Integer taskId = countVO.getTaskId();
|
|
|
Integer projectId = countVO.getProjectId();
|
|
|
- if( taskId != null){
|
|
|
+ if (taskId != null) {
|
|
|
if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
searchCondition = "taskId = " + taskId + " AND " + searchCondition;
|
|
|
} else {
|
|
@@ -89,12 +93,15 @@ public class EsCountService {
|
|
|
|
|
|
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");
|
|
|
+ Query query = null;
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
@@ -106,8 +113,9 @@ public class EsCountService {
|
|
|
//查询es返回数据
|
|
|
Aggregation aggregation = this.selectAggregation(builder, vo);
|
|
|
if (query != null) {
|
|
|
+ Query finalQuery = query;
|
|
|
Aggregation filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
- .filters(i -> i.array(Arrays.asList(query))).build())
|
|
|
+ .filters(i -> i.array(Arrays.asList(finalQuery))).build())
|
|
|
.aggregations(new HashMap() {{
|
|
|
put("filters_agg", aggregation);
|
|
|
}}).build();
|
|
@@ -173,6 +181,40 @@ public class EsCountService {
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public EsCountDTO esAnalysisSearch(EsAllCountVO countVO) throws Exception {
|
|
|
+ String searchCondition = countVO.getCondition();
|
|
|
+ List<EsCustomFieldValueDTO> customFields = countVO.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ searchCondition = esService.parseCustomField(customFields);
|
|
|
+ }
|
|
|
+ Integer taskId = countVO.getTaskId();
|
|
|
+ Integer projectId = countVO.getProjectId();
|
|
|
+ if (taskId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "taskId = " + taskId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "taskId = " + taskId;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (projectId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "projectId = " + projectId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "projectId = " + projectId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ Query query = null;
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ }
|
|
|
+
|
|
|
EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
List<EsCountVO> countVOS = countVO.getCountVOS();
|
|
@@ -184,7 +226,6 @@ public class EsCountService {
|
|
|
List<String> values = vo.getValues();
|
|
|
|
|
|
//查询es返回数据
|
|
|
- SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
builder.index("patent");
|
|
|
IEsAnalysisBuilder iEsAnalysisBuilder = null;
|
|
|
String json = CommonService.readJsonFile("esAnalysis.json");
|
|
@@ -204,6 +245,19 @@ public class EsCountService {
|
|
|
iEsAnalysisBuilder.setValues(values);
|
|
|
|
|
|
Aggregation aggregation = iEsAnalysisBuilder.createAnalyseAgg();
|
|
|
+
|
|
|
+ if (query != null) {
|
|
|
+ Query finalQuery = query;
|
|
|
+ Aggregation filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
+ .filters(i -> i.array(Arrays.asList(finalQuery))).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filters_agg", aggregation);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", filtersAgg);
|
|
|
+ } else {
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+ }
|
|
|
+
|
|
|
builder.aggregations("Agg", aggregation);
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
|
@@ -215,7 +269,7 @@ public class EsCountService {
|
|
|
} else if (childList.contains(field)) {
|
|
|
this.getChildAnalysisDTOS(agg, field, detailDTOS);
|
|
|
} else if (numberList.contains(field)) {
|
|
|
- this.getNumberAnalysisDTOS(agg, field,detailDTOS);
|
|
|
+ this.getNumberAnalysisDTOS(agg, field, detailDTOS);
|
|
|
} else {
|
|
|
this.getTermCountDTOS(agg, field, detailDTOS);
|
|
|
}
|
|
@@ -226,50 +280,99 @@ public class EsCountService {
|
|
|
}
|
|
|
|
|
|
//测试用的
|
|
|
- public EsCountDTO esAnalysis(EsCountVO vo) throws Exception {
|
|
|
- EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
- List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
- String field = vo.getField();
|
|
|
- Integer topN = vo.getTopN();
|
|
|
- Boolean ifHaveChild = vo.getIfHaveChild();
|
|
|
- String fieldId = vo.getFieldId();
|
|
|
- List<String> values = vo.getValues();
|
|
|
+ public EsCountDTO esAnalysis(EsAllCountVO countVO) throws Exception {
|
|
|
+ String searchCondition = countVO.getCondition();
|
|
|
+ List<EsCustomFieldValueDTO> customFields = countVO.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ searchCondition = esService.parseCustomField(customFields);
|
|
|
+ }
|
|
|
+ Integer taskId = countVO.getTaskId();
|
|
|
+ Integer projectId = countVO.getProjectId();
|
|
|
+ if (taskId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "taskId = " + taskId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "taskId = " + taskId;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (projectId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "projectId = " + projectId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "projectId = " + projectId;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //查询es返回数据
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
builder.index("patent");
|
|
|
- IEsAnalysisBuilder iEsAnalysisBuilder = null;
|
|
|
- String json = CommonService.readJsonFile("esAnalysis.json");
|
|
|
- List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
- EsConfigVO esConfigVO = esConfigVOS.stream().filter(item -> item.getField().equals(field))
|
|
|
- .findFirst().orElse(null);
|
|
|
- if (esConfigVO != null) {
|
|
|
- iEsAnalysisBuilder = esAnalysisBuilderFactory.getClass(esConfigVO.getEsClass());
|
|
|
- iEsAnalysisBuilder.setField(esConfigVO.getEsField());
|
|
|
- iEsAnalysisBuilder.setTopN(topN);
|
|
|
- iEsAnalysisBuilder.setIfHaveChild(ifHaveChild);
|
|
|
- iEsAnalysisBuilder.setFieldValue(fieldId);
|
|
|
- if (iEsAnalysisBuilder.getField().contains(".")) {
|
|
|
- String path = iEsAnalysisBuilder.getField().substring(0, iEsAnalysisBuilder.getField().indexOf("."));
|
|
|
- iEsAnalysisBuilder.setPath(path);
|
|
|
- }
|
|
|
- iEsAnalysisBuilder.setValues(values);
|
|
|
+ Query query = null;
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ }
|
|
|
|
|
|
- Aggregation aggregation = iEsAnalysisBuilder.createAnalyseAgg();
|
|
|
- builder.aggregations("Agg", aggregation);
|
|
|
- SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
+ List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
+ List<EsCountVO> countVOS = countVO.getCountVOS();
|
|
|
+ for (EsCountVO vo : countVOS) {
|
|
|
+ String field = vo.getField();
|
|
|
+ Integer topN = vo.getTopN();
|
|
|
+ Boolean ifHaveChild = vo.getIfHaveChild();
|
|
|
+ String fieldId = vo.getFieldId();
|
|
|
+ List<String> values = vo.getValues();
|
|
|
|
|
|
- Aggregate agg = response.aggregations().get("Agg");
|
|
|
- if (dateList.contains(field)) {
|
|
|
- this.getDateAnalysisDTOS(agg, field, topN, detailDTOS);
|
|
|
- } else if (nestedList.contains(field)) {
|
|
|
- this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
- } else if (childList.contains(field)) {
|
|
|
- this.getChildAnalysisDTOS(agg, field, detailDTOS);
|
|
|
- } else if (numberList.contains(field)) {
|
|
|
- this.getNumberAnalysisDTOS(agg, field,detailDTOS);
|
|
|
- } else {
|
|
|
- this.getTermCountDTOS(agg, field, detailDTOS);
|
|
|
+ //查询es返回数据
|
|
|
+ builder.index("patent");
|
|
|
+ IEsAnalysisBuilder iEsAnalysisBuilder = null;
|
|
|
+ String json = CommonService.readJsonFile("esAnalysis.json");
|
|
|
+ List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
+ EsConfigVO esConfigVO = esConfigVOS.stream().filter(item -> item.getField().equals(field))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+ if (esConfigVO != null) {
|
|
|
+ iEsAnalysisBuilder = esAnalysisBuilderFactory.getClass(esConfigVO.getEsClass());
|
|
|
+ iEsAnalysisBuilder.setField(esConfigVO.getEsField());
|
|
|
+ iEsAnalysisBuilder.setTopN(topN);
|
|
|
+ iEsAnalysisBuilder.setIfHaveChild(ifHaveChild);
|
|
|
+ iEsAnalysisBuilder.setFieldValue(fieldId);
|
|
|
+ if (iEsAnalysisBuilder.getField().contains(".")) {
|
|
|
+ String path = iEsAnalysisBuilder.getField().substring(0, iEsAnalysisBuilder.getField().indexOf("."));
|
|
|
+ iEsAnalysisBuilder.setPath(path);
|
|
|
+ }
|
|
|
+ iEsAnalysisBuilder.setValues(values);
|
|
|
+
|
|
|
+ Aggregation aggregation = iEsAnalysisBuilder.createAnalyseAgg();
|
|
|
+
|
|
|
+ if (query != null) {
|
|
|
+ Query finalQuery = query;
|
|
|
+ Aggregation filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
+ .filters(i -> i.array(Arrays.asList(finalQuery))).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filters_agg", aggregation);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", filtersAgg);
|
|
|
+ } else {
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+ }
|
|
|
+
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+
|
|
|
+ Aggregate agg = response.aggregations().get("Agg");
|
|
|
+ if (dateList.contains(field)) {
|
|
|
+ this.getDateAnalysisDTOS(agg, field, topN, detailDTOS);
|
|
|
+ } else if (nestedList.contains(field)) {
|
|
|
+ this.getNestedCountDTOS(agg, field, detailDTOS);
|
|
|
+ } else if (childList.contains(field)) {
|
|
|
+ this.getChildAnalysisDTOS(agg, field, detailDTOS);
|
|
|
+ } else if (numberList.contains(field)) {
|
|
|
+ this.getNumberAnalysisDTOS(agg, field, detailDTOS);
|
|
|
+ } else {
|
|
|
+ this.getTermCountDTOS(agg, field, detailDTOS);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
esCountDTO.setDetailDTOS(detailDTOS);
|
|
@@ -447,7 +550,7 @@ public class EsCountService {
|
|
|
* @param field
|
|
|
* @param detailDTOS
|
|
|
*/
|
|
|
- public void getNumberAnalysisDTOS(Aggregate agg, String field,List<EsCountDetailDTO> detailDTOS) {
|
|
|
+ public void getNumberAnalysisDTOS(Aggregate agg, String field, List<EsCountDetailDTO> detailDTOS) {
|
|
|
List<RangeBucket> list = agg.range().buckets().array();
|
|
|
for (RangeBucket bucket : list) {
|
|
|
EsCountDetailDTO dto = new EsCountDetailDTO();
|
|
@@ -541,4 +644,88 @@ public class EsCountService {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public EsCountDTO esCountAnalysis(EsAllCountVO vo) throws Exception {
|
|
|
+ String searchCondition = vo.getCondition();
|
|
|
+ List<EsCustomFieldValueDTO> customFields = vo.getCustomFields();
|
|
|
+ if (!CollectionUtils.isEmpty(customFields)) {
|
|
|
+ searchCondition = esService.parseCustomField(customFields);
|
|
|
+ }
|
|
|
+ Integer taskId = vo.getTaskId();
|
|
|
+ Integer projectId = vo.getProjectId();
|
|
|
+
|
|
|
+ if (taskId != null) {
|
|
|
+ if (searchCondition != null && !"".equals(searchCondition.trim())) {
|
|
|
+ searchCondition = "taskId = " + taskId + " AND " + searchCondition;
|
|
|
+ } else {
|
|
|
+ searchCondition = "taskId = " + taskId;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ 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");
|
|
|
+ //设置查询索引
|
|
|
+ Query query = null;
|
|
|
+ if (StringUtils.isNotEmpty(searchCondition)) {
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+ }
|
|
|
+
|
|
|
+ EsCountDTO esCountDTO = new EsCountDTO();
|
|
|
+ List<EsCountDetailDTO> detailDTOS = new ArrayList<>();
|
|
|
+ List<EsCountVO> countVOS = vo.getCountVOS();
|
|
|
+ for (EsCountVO countVO : countVOS) {
|
|
|
+ String field = countVO.getField();
|
|
|
+ Integer topN = countVO.getTopN();
|
|
|
+ String condition = searchCondition;
|
|
|
+ String filterCondition = countVO.getFilterCondition();
|
|
|
+ String valueOne = countVO.getValueOne();
|
|
|
+ String valueTwo = countVO.getValueTwo();
|
|
|
+ List<String> values = countVO.getValues();
|
|
|
+
|
|
|
+ IEsCountAnalysisBuilder iEsCountAnalysisBuilder = null;
|
|
|
+ String json = CommonService.readJsonFile("esAnalysis.json");
|
|
|
+ List<EsConfigVO> esConfigVOS = JSON.parseArray(json, EsConfigVO.class);
|
|
|
+ EsConfigVO esConfigVO = esConfigVOS.stream().filter(item -> item.getField().equals(field))
|
|
|
+ .findFirst().orElse(null);
|
|
|
+
|
|
|
+ Aggregation aggregation = null;
|
|
|
+ if (esConfigVO != null) {
|
|
|
+ iEsCountAnalysisBuilder = esCountAnalysisBuilderFactory.getClass(esConfigVO.getEsClass());
|
|
|
+ if (StringUtils.isNotEmpty(valueOne) || StringUtils.isNotEmpty(valueTwo)) {
|
|
|
+
|
|
|
+ } else if (!CollectionUtils.isEmpty(values)) {
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (query != null) {
|
|
|
+ Query finalQuery = query;
|
|
|
+ Aggregation filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
+ .filters(i -> i.array(Arrays.asList(finalQuery))).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filters_agg", aggregation);
|
|
|
+ }}).build();
|
|
|
+ builder.aggregations("Agg", filtersAgg);
|
|
|
+ } else {
|
|
|
+ builder.aggregations("Agg", aggregation);
|
|
|
+ }
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|