|
@@ -2,12 +2,14 @@ package com.yoho.search.service.scene.shopbrand; |
|
@@ -2,12 +2,14 @@ package com.yoho.search.service.scene.shopbrand; |
2
|
|
2
|
|
3
|
import com.alibaba.fastjson.JSONArray;
|
3
|
import com.alibaba.fastjson.JSONArray;
|
4
|
import com.alibaba.fastjson.JSONObject;
|
4
|
import com.alibaba.fastjson.JSONObject;
|
5
|
-import com.yoho.search.cache.CacheTimeConstants;
|
5
|
+import com.yoho.search.base.utils.ISearchConstants;
|
6
|
import com.yoho.search.cache.beans.AbstractCacheComponent;
|
6
|
import com.yoho.search.cache.beans.AbstractCacheComponent;
|
|
|
7
|
+import com.yoho.search.common.SearchCommonService;
|
7
|
import com.yoho.search.common.SearchRequestParams;
|
8
|
import com.yoho.search.common.SearchRequestParams;
|
8
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
9
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
9
|
import com.yoho.search.core.es.agg.IAggregation;
|
10
|
import com.yoho.search.core.es.agg.IAggregation;
|
10
|
import com.yoho.search.core.es.model.SearchParam;
|
11
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
12
|
+import com.yoho.search.core.es.model.SearchResult;
|
11
|
import com.yoho.search.models.SearchApiResult;
|
13
|
import com.yoho.search.models.SearchApiResult;
|
12
|
import com.yoho.search.service.aggregations.AggregationsService;
|
14
|
import com.yoho.search.service.aggregations.AggregationsService;
|
13
|
import com.yoho.search.service.aggregations.impls.AggregationFactory;
|
15
|
import com.yoho.search.service.aggregations.impls.AggregationFactory;
|
|
@@ -15,6 +17,7 @@ import com.yoho.search.service.helper.UfoSearchQueryHelper; |
|
@@ -15,6 +17,7 @@ import com.yoho.search.service.helper.UfoSearchQueryHelper; |
15
|
import org.elasticsearch.common.Nullable;
|
17
|
import org.elasticsearch.common.Nullable;
|
16
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
18
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
17
|
import org.elasticsearch.index.query.QueryBuilder;
|
19
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
20
|
+import org.elasticsearch.search.aggregations.Aggregation;
|
18
|
import org.slf4j.Logger;
|
21
|
import org.slf4j.Logger;
|
19
|
import org.slf4j.LoggerFactory;
|
22
|
import org.slf4j.LoggerFactory;
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -37,12 +40,11 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
|
@@ -37,12 +40,11 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
37
|
private AggregationFactory aggregationFactory;
|
40
|
private AggregationFactory aggregationFactory;
|
38
|
@Autowired
|
41
|
@Autowired
|
39
|
private AggregationsService aggregationsService;
|
42
|
private AggregationsService aggregationsService;
|
|
|
43
|
+ @Autowired
|
|
|
44
|
+ private SearchCommonService searchCommonService;
|
40
|
|
45
|
|
41
|
- public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
|
|
|
42
|
- return this.aggAllBrandList(paramMap, null);
|
|
|
43
|
- }
|
|
|
44
|
|
46
|
|
45
|
- public SearchApiResult aggAllBrandList(Map<String, String> paramMap, BoolQueryBuilder mustFilter) {
|
47
|
+ public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
|
46
|
try {
|
48
|
try {
|
47
|
// 1、构造带filter和query的SearchParam
|
49
|
// 1、构造带filter和query的SearchParam
|
48
|
boolean needPreAggregation = "Y".equals(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "N")) ? false : true;
|
50
|
boolean needPreAggregation = "Y".equals(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "N")) ? false : true;
|
|
@@ -72,7 +74,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
|
@@ -72,7 +74,7 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
72
|
|
74
|
|
73
|
@Override
|
75
|
@Override
|
74
|
protected int cacheTimeInMinute() {
|
76
|
protected int cacheTimeInMinute() {
|
75
|
- return CacheTimeConstants.CACHE_30_MINUTE;
|
77
|
+ return 0;//CacheTimeConstants.CACHE_30_MINUTE;
|
76
|
}
|
78
|
}
|
77
|
|
79
|
|
78
|
@Override
|
80
|
@Override
|
|
@@ -81,7 +83,9 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
|
@@ -81,7 +83,9 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
81
|
IAggregation brandAggregation = (IAggregation) params[0];
|
83
|
IAggregation brandAggregation = (IAggregation) params[0];
|
82
|
|
84
|
|
83
|
// 2、从ES中获取
|
85
|
// 2、从ES中获取
|
84
|
- JSONObject jsonObject = aggregationsService.getAggNameAndResponse(brandAggregation, searchParam);
|
86
|
+ SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);//this.doSearchForAggregation(searchParam, AggregationServiceIndex);
|
|
|
87
|
+ Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
88
|
+ JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps);
|
85
|
|
89
|
|
86
|
// 3、生成结果
|
90
|
// 3、生成结果
|
87
|
JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|
91
|
JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|