|
@@ -11,8 +11,15 @@ import co.elastic.clients.elasticsearch.core.*;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
import co.elastic.clients.json.JsonData;
|
|
import co.elastic.clients.json.JsonData;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.expressManager;
|
|
|
|
+import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.operateNode;
|
|
|
|
+import com.example.xiaoshiweixinback.business.utils.parseQueryToTree.treeNode;
|
|
import com.example.xiaoshiweixinback.domain.es.Patent;
|
|
import com.example.xiaoshiweixinback.domain.es.Patent;
|
|
import com.example.xiaoshiweixinback.domain.es.PatentVector;
|
|
import com.example.xiaoshiweixinback.domain.es.PatentVector;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.dto.patent.PatentDTO;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.patent.MapRequest;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.patent.QueryRequest;
|
|
|
|
+import com.example.xiaoshiweixinback.entity.patent.StringRequest;
|
|
import com.example.xiaoshiweixinback.entity.vo.patent.PatentWithIdVO;
|
|
import com.example.xiaoshiweixinback.entity.vo.patent.PatentWithIdVO;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
@@ -186,7 +193,120 @@ public class EsService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Es检索
|
|
|
|
+ *
|
|
|
|
+ * @param queryRequest 检索条件
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public PatentDTO esSearch(QueryRequest queryRequest) throws Exception {
|
|
|
|
+// PatentDTO dto = new PatentDTO();
|
|
|
|
+// String searchCondition = "";
|
|
|
|
+// Integer productId = queryRequest.getProductId();
|
|
|
|
+// String productFrom = queryRequest.getFrom();
|
|
|
|
+// Long current = queryRequest.getCurrent();
|
|
|
|
+// Long size = queryRequest.getSize();
|
|
|
|
+// String groupField = queryRequest.getGroupField();
|
|
|
|
+// //判断表达式
|
|
|
|
+// 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();
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
|
+// //设置查询索引
|
|
|
|
+// builder.index("patent");
|
|
|
|
+// //1. 解析检索条件
|
|
|
|
+// treeNode tree = expressManager.getInstance().Parse(condition, false);
|
|
|
|
+// //3. 从es中检索数据
|
|
|
|
+// Query q = formatQueryService.EsQueryToQuery((operateNode) tree, "patent",projectId);
|
|
|
|
+// builder.query(q);
|
|
|
|
+// //判断同族分组
|
|
|
|
+// 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 = str;
|
|
|
|
+// 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.intValue()).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);
|
|
|
|
+// //对聚合结果统计出总数
|
|
|
|
+// 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);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// //分页
|
|
|
|
+// 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<>();
|
|
|
|
+// 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.getPatentColumnDTO(key, projectId,esField);
|
|
|
|
+// list.add(columnDTO);
|
|
|
|
+// }
|
|
|
|
+// } 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);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// this.loadCoulumnDTO(list);
|
|
|
|
+// dto.setTotal(total);
|
|
|
|
+// dto.setPatents(list);
|
|
|
|
+// dto.setPageNum(current);
|
|
|
|
+// dto.setPageSize(size);
|
|
|
|
+// return dto;
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|