Authored by wangnan9279

ufo

@@ -21,7 +21,7 @@ import java.util.Map; @@ -21,7 +21,7 @@ import java.util.Map;
21 * @version 2018/9/17 21 * @version 2018/9/17
22 */ 22 */
23 public class UfoBrandAggregation extends AbstractAggregation { 23 public class UfoBrandAggregation extends AbstractAggregation {
24 - private static final Logger logger = LoggerFactory.getLogger(BrandAggregation.class); 24 + private static final Logger logger = LoggerFactory.getLogger(UfoBrandAggregation.class);
25 25
26 private UfoBrandIndexBaseService brandIndexBaseService; 26 private UfoBrandIndexBaseService brandIndexBaseService;
27 private Map<String, String> paramMap; 27 private Map<String, String> paramMap;
@@ -33,12 +33,6 @@ public class UfoBrandAggregation extends AbstractAggregation { @@ -33,12 +33,6 @@ public class UfoBrandAggregation extends AbstractAggregation {
33 this.brandCount = 1000; 33 this.brandCount = 1000;
34 } 34 }
35 35
36 - UfoBrandAggregation(UfoBrandIndexBaseService brandIndexBaseService, Map<String, String> paramMap, int brandCount) {  
37 - this.brandIndexBaseService = brandIndexBaseService;  
38 - this.paramMap = paramMap;  
39 - this.brandCount = brandCount;  
40 - }  
41 -  
42 @Override 36 @Override
43 public String aggName() { 37 public String aggName() {
44 return "ufoBrandAgg"; 38 return "ufoBrandAgg";
@@ -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());