|
@@ -6,6 +6,7 @@ import com.winhc.phoenix.example.util.company.search.CompanyIndexUtils;
|
|
|
import com.winhc.phoenix.example.vo.judgment.JudgmentDocumentsSearchContent;
|
|
|
import com.winhc.phoenix.example.vo.judgment.JudgmentDocumentsSearchType;
|
|
|
import com.winhc.phoenix.example.vo.judgment.JudgmentDocumentsSortType;
|
|
|
+import com.winhc.phoenix.example.vo.judgment.QueryOrAgg;
|
|
|
import com.winhc.tool.bean.IpInfo;
|
|
|
import com.winhc.tool.component.WinhcIpParser;
|
|
|
import lombok.AllArgsConstructor;
|
|
@@ -14,6 +15,9 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.script.Script;
|
|
|
+import org.elasticsearch.search.aggregations.AggregationBuilder;
|
|
|
+import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
|
|
|
+import org.elasticsearch.search.aggregations.support.ValueType;
|
|
|
import org.elasticsearch.search.sort.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -31,9 +35,9 @@ import static org.elasticsearch.index.query.QueryBuilders.*;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class JudgmentDocumentsServiceImpl implements JudgmentDocumentsService {
|
|
|
- private WinhcIpParser winhcIpParser;
|
|
|
+ private final WinhcIpParser winhcIpParser;
|
|
|
|
|
|
- private SearchDao searchDao;
|
|
|
+ private final SearchDao searchDao;
|
|
|
public static final String index = "wenshu_detail4";
|
|
|
public static final String type = "wenshu_detail_type";
|
|
|
|
|
@@ -100,7 +104,7 @@ public class JudgmentDocumentsServiceImpl implements JudgmentDocumentsService {
|
|
|
List<SortBuilder> sortBuilders = new ArrayList<>();
|
|
|
if (sort == null && !searchContent.isNotSort()) {
|
|
|
String ip = searchContent.getIp();
|
|
|
- if(StringUtils.isNotBlank(ip)){
|
|
|
+ if (StringUtils.isNotBlank(ip)) {
|
|
|
IpInfo ipInfo = winhcIpParser.parseIp(ip);
|
|
|
if (ipInfo.getIpProvinceCode() != null) {
|
|
|
Map<String, Object> map = new HashMap<String, Object>(2);
|
|
@@ -120,12 +124,42 @@ public class JudgmentDocumentsServiceImpl implements JudgmentDocumentsService {
|
|
|
sortBuilders.add(order);
|
|
|
}
|
|
|
}
|
|
|
+ List<AggregationBuilder> aggList = null;
|
|
|
+ if (QueryOrAgg.AGG.equals(searchContent.getQueryOrAgg())) {
|
|
|
+ aggList = agg();
|
|
|
+ from = 0;
|
|
|
+ size = 0;
|
|
|
+ } else if (QueryOrAgg.QUERY_AND_AGG.equals(searchContent.getQueryOrAgg())) {
|
|
|
+ aggList = agg();
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
- Object search = searchDao.search(index, type, boolQuery, null, sortBuilders, null, from, size, preference, highlightField);
|
|
|
+ Object search = searchDao.search(index
|
|
|
+ , type
|
|
|
+ , boolQuery
|
|
|
+ , null
|
|
|
+ , sortBuilders
|
|
|
+ , null
|
|
|
+ , from
|
|
|
+ , size
|
|
|
+ , preference
|
|
|
+ , highlightField
|
|
|
+ , aggList
|
|
|
+ );
|
|
|
return search;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public List<AggregationBuilder> agg() {
|
|
|
+ ArrayList<AggregationBuilder> agg = new ArrayList<>();
|
|
|
+
|
|
|
+ agg.add(new TermsAggregationBuilder("court_level_agg", ValueType.STRING).field("court_level"));
|
|
|
+
|
|
|
+
|
|
|
+ return agg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
private static QueryBuilder getSearchContentQuery(JudgmentDocumentsSearchType searchScope, String content) {
|
|
|
BoolQueryBuilder boolQuery = boolQuery();
|
|
|
List<String> fields = searchScope.getFields();
|