|
@@ -13,7 +13,6 @@ import com.yoho.search.core.es.model.SearchResult; |
|
@@ -13,7 +13,6 @@ import com.yoho.search.core.es.model.SearchResult; |
13
|
import com.yoho.search.models.SearchApiResult;
|
13
|
import com.yoho.search.models.SearchApiResult;
|
14
|
import com.yoho.search.service.aggregations.impls.AggregationFactory;
|
14
|
import com.yoho.search.service.aggregations.impls.AggregationFactory;
|
15
|
import com.yoho.search.service.helper.UfoSearchQueryHelper;
|
15
|
import com.yoho.search.service.helper.UfoSearchQueryHelper;
|
16
|
-import org.elasticsearch.common.Nullable;
|
|
|
17
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
16
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
18
|
import org.elasticsearch.index.query.QueryBuilder;
|
17
|
import org.elasticsearch.index.query.QueryBuilder;
|
19
|
import org.elasticsearch.search.aggregations.Aggregation;
|
18
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
@@ -25,10 +24,6 @@ import org.springframework.stereotype.Service; |
|
@@ -25,10 +24,6 @@ import org.springframework.stereotype.Service; |
25
|
import java.util.Arrays;
|
24
|
import java.util.Arrays;
|
26
|
import java.util.Map;
|
25
|
import java.util.Map;
|
27
|
|
26
|
|
28
|
-/**
|
|
|
29
|
- * @author wangnan
|
|
|
30
|
- * @version 2018/9/17
|
|
|
31
|
- */
|
|
|
32
|
@Service
|
27
|
@Service
|
33
|
public class UfoBrandListService {
|
28
|
public class UfoBrandListService {
|
34
|
private static final Logger logger = LoggerFactory.getLogger(UfoBrandListService.class);
|
29
|
private static final Logger logger = LoggerFactory.getLogger(UfoBrandListService.class);
|
|
@@ -41,7 +36,7 @@ public class UfoBrandListService { |
|
@@ -41,7 +36,7 @@ public class UfoBrandListService { |
41
|
private SearchCommonService searchCommonService;
|
36
|
private SearchCommonService searchCommonService;
|
42
|
|
37
|
|
43
|
@SearchCacheAble(cacheName = "UFO_BRAND_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
|
38
|
@SearchCacheAble(cacheName = "UFO_BRAND_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
|
44
|
- public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
|
39
|
+ public SearchApiResult ufoBrandList(Map<String, String> paramMap) {
|
45
|
try {
|
40
|
try {
|
46
|
// 1、构造带filter和query的SearchParam
|
41
|
// 1、构造带filter和query的SearchParam
|
47
|
SearchParam searchParam = new SearchParam();
|
42
|
SearchParam searchParam = new SearchParam();
|
|
@@ -55,8 +50,13 @@ public class UfoBrandListService { |
|
@@ -55,8 +50,13 @@ public class UfoBrandListService { |
55
|
IAggregation brandAggregation = aggregationFactory.getUfoBrandAggregation(paramMap);
|
50
|
IAggregation brandAggregation = aggregationFactory.getUfoBrandAggregation(paramMap);
|
56
|
searchParam.setAggregationBuilders(Arrays.asList(brandAggregation.getBuilder()));
|
51
|
searchParam.setAggregationBuilders(Arrays.asList(brandAggregation.getBuilder()));
|
57
|
|
52
|
|
58
|
- // 3、调父类方法执行查询
|
|
|
59
|
- JSONArray brandJSONArray = doRealQuery(searchParam, brandAggregation);
|
53
|
+ // 3、执行搜索
|
|
|
54
|
+ SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
|
|
|
55
|
+ Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
56
|
+ JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps);
|
|
|
57
|
+ JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|
|
|
58
|
+
|
|
|
59
|
+ // 4、返回结果
|
60
|
JSONObject dataMap = new JSONObject();
|
60
|
JSONObject dataMap = new JSONObject();
|
61
|
dataMap.put("brand_list", brandJSONArray);
|
61
|
dataMap.put("brand_list", brandJSONArray);
|
62
|
return new SearchApiResult().setData(dataMap);
|
62
|
return new SearchApiResult().setData(dataMap);
|
|
@@ -65,18 +65,4 @@ public class UfoBrandListService { |
|
@@ -65,18 +65,4 @@ public class UfoBrandListService { |
65
|
}
|
65
|
}
|
66
|
}
|
66
|
}
|
67
|
|
67
|
|
68
|
- private JSONArray doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
|
|
|
69
|
- // 1、从参数中获取IAggregation brandAggregation
|
|
|
70
|
- IAggregation brandAggregation = (IAggregation) params[0];
|
|
|
71
|
-
|
|
|
72
|
- // 2、从ES中获取
|
|
|
73
|
- SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
|
|
|
74
|
- Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
75
|
- JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps);
|
|
|
76
|
-
|
|
|
77
|
- // 3、生成结果
|
|
|
78
|
- JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|
|
|
79
|
- return brandJSONArray;
|
|
|
80
|
-
|
|
|
81
|
- }
|
|
|
82
|
} |
68
|
} |