|
@@ -2,10 +2,14 @@ package cn.cslg.pas.service.business.es;
|
|
|
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDTO;
|
|
|
import cn.cslg.pas.common.dto.business.EsCountDetailDTO;
|
|
|
+import cn.cslg.pas.common.dto.es.EsCustomFieldValueDTO;
|
|
|
+import cn.cslg.pas.common.model.request.MapRequest;
|
|
|
+import cn.cslg.pas.common.model.request.StringRequest;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.expressManager;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.operateNode;
|
|
|
import cn.cslg.pas.common.utils.parseQueryToTree.treeNode;
|
|
|
import cn.cslg.pas.common.vo.EsConfigVO;
|
|
|
+import cn.cslg.pas.common.vo.business.EsAllCountVO;
|
|
|
import cn.cslg.pas.common.vo.business.EsCountVO;
|
|
|
import cn.cslg.pas.domain.es.Patent;
|
|
|
import cn.cslg.pas.factorys.EsAnalysisBuilderFactory.EsAnalysisBuilderFactory;
|
|
@@ -49,39 +53,64 @@ public class EsCountService {
|
|
|
private EsAnalysisBuilderFactory esAnalysisBuilderFactory;
|
|
|
@Autowired
|
|
|
private FormatQueryService formatQueryService;
|
|
|
+ @Autowired
|
|
|
+ private EsService esService;
|
|
|
|
|
|
/**
|
|
|
* 查询专利库中的专利分组聚合统计
|
|
|
*
|
|
|
- * @param countVOS
|
|
|
+ * @param countVO
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public EsCountDTO esCountSearch(List<EsCountVO> countVOS) throws Exception {
|
|
|
+ public EsCountDTO esCountSearch(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();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ //1. 解析检索条件
|
|
|
+ treeNode tree = expressManager.getInstance().Parse(searchCondition, false);
|
|
|
+ //格式化检索式
|
|
|
+ //3. 从es中检索数据
|
|
|
+ Query query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
+
|
|
|
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();
|
|
|
- String condition = vo.getCondition();
|
|
|
+ String condition = searchCondition;
|
|
|
//查询es返回数据
|
|
|
- SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
Aggregation aggregation = this.selectAggregation(builder, vo);
|
|
|
- if (StringUtils.isNotEmpty(condition)) {
|
|
|
- //解析检索条件
|
|
|
- treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
- //从es中检索数据
|
|
|
- Query query = formatQueryService.EsQueryToQuery((operateNode) tree, "patent");
|
|
|
- Aggregation filtersAgg = null;
|
|
|
- if (aggregation != null) {
|
|
|
- filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
- .filters(i -> i.array(Arrays.asList(query))).build())
|
|
|
- .aggregations(new HashMap() {{
|
|
|
- put("filters_agg", aggregation);
|
|
|
- }}).build();
|
|
|
- } else {
|
|
|
- filtersAgg = AggregationBuilders.filter(i -> i.bool(j -> j.must(query)));
|
|
|
- }
|
|
|
+ if (query != null) {
|
|
|
+ Aggregation filtersAgg = new Aggregation.Builder().filters(new FiltersAggregation.Builder()
|
|
|
+ .filters(i -> i.array(Arrays.asList(query))).build())
|
|
|
+ .aggregations(new HashMap() {{
|
|
|
+ put("filters_agg", aggregation);
|
|
|
+ }}).build();
|
|
|
builder.aggregations("Agg", filtersAgg);
|
|
|
} else {
|
|
|
builder.aggregations("Agg", aggregation);
|
|
@@ -89,7 +118,7 @@ public class EsCountService {
|
|
|
SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
|
|
|
Aggregate agg = response.aggregations().get("Agg");
|
|
|
- if (StringUtils.isNotEmpty(condition)) {
|
|
|
+ if (query != null) {
|
|
|
if (StringUtils.isNotEmpty(field)) {
|
|
|
List<FiltersBucket> filtersBuckets = agg.filters().buckets().array();
|
|
|
if (dateList.contains(field)) {
|
|
@@ -139,13 +168,14 @@ public class EsCountService {
|
|
|
/**
|
|
|
* 专利的聚合分析
|
|
|
*
|
|
|
- * @param countVOS
|
|
|
+ * @param countVO
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public EsCountDTO esAnalysisSearch(List<EsCountVO> countVOS) throws Exception {
|
|
|
+ public EsCountDTO esAnalysisSearch(EsAllCountVO countVO) throws Exception {
|
|
|
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();
|