|
@@ -29,6 +29,7 @@ import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
@@ -48,7 +49,10 @@ public class EsService {
|
|
|
|
|
|
@Autowired
|
|
|
private PatentStarApiService patentStarApiService;
|
|
|
-
|
|
|
+ @Value("${ES.patentVector}")
|
|
|
+ private String patentVectorName;
|
|
|
+ @Value("${ES.patent}")
|
|
|
+ private String patentMapName;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -57,7 +61,7 @@ public class EsService {
|
|
|
*/
|
|
|
public String addPatent(Patent patent) throws Exception {
|
|
|
IndexResponse indexResponse = client.index(i -> i
|
|
|
- .index("wxpatent")
|
|
|
+ .index(patentMapName)
|
|
|
//传入user对象
|
|
|
.document(patent)
|
|
|
);
|
|
@@ -66,7 +70,7 @@ public class EsService {
|
|
|
|
|
|
public String addPatentVector(PatentVector patentVector) throws Exception {
|
|
|
IndexResponse indexResponse = client.index(i -> i
|
|
|
- .index("patent_vector")
|
|
|
+ .index(patentVectorName)
|
|
|
//传入user对象
|
|
|
.document(patentVector)
|
|
|
);
|
|
@@ -79,7 +83,7 @@ public class EsService {
|
|
|
*/
|
|
|
public String addChildPatent(Patent patent, String id) throws Exception {
|
|
|
IndexResponse indexResponse = client.index(i -> i
|
|
|
- .index("wxpatent")
|
|
|
+ .index(patentMapName)
|
|
|
.routing(id)
|
|
|
//传入user对象
|
|
|
.document(patent).refresh(Refresh.True).waitForActiveShards(WaitForActiveShards.of(t -> t.count(1)))
|
|
@@ -94,7 +98,7 @@ public class EsService {
|
|
|
*/
|
|
|
public Integer deleteWxPatent(List<String> ids) {
|
|
|
Query query = QueryBuilders.ids(n -> n.values(ids));
|
|
|
- DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index("wxpatent").query(query));
|
|
|
+ DeleteByQueryRequest request = DeleteByQueryRequest.of(i -> i.index(patentMapName).query(query));
|
|
|
try {
|
|
|
client.deleteByQuery(request);
|
|
|
return 1;
|
|
@@ -113,7 +117,7 @@ public class EsService {
|
|
|
public PatentWithIdVO getIdByPatentNo(String patentNo) throws Exception {
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
//设置查询索引
|
|
|
- builder.index("wxpatent");
|
|
|
+ builder.index(patentMapName);
|
|
|
PatentWithIdVO patentWithIdVO = null;
|
|
|
String id = null;
|
|
|
Query q1 = QueryBuilders.term(t -> t.field("app_no.keyword").value(patentNo));
|
|
@@ -197,7 +201,7 @@ public class EsService {
|
|
|
UpdateRequest<Patent, Patent> req;
|
|
|
|
|
|
req = UpdateRequest.of(
|
|
|
- b -> b.index("wxpatent").id(id)
|
|
|
+ b -> b.index(patentMapName).id(id)
|
|
|
.doc(patent)
|
|
|
);
|
|
|
|
|
@@ -227,123 +231,6 @@ 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;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
* 根据专利号获取专利id
|
|
|
*
|
|
|
* @param patentNo
|