...
|
...
|
@@ -2,12 +2,14 @@ package com.yoho.search.service.scene.shopbrand; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.cache.CacheTimeConstants;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.cache.beans.AbstractCacheComponent;
|
|
|
import com.yoho.search.common.SearchCommonService;
|
|
|
import com.yoho.search.common.SearchRequestParams;
|
|
|
import com.yoho.search.common.utils.SearchApiResultUtils;
|
|
|
import com.yoho.search.core.es.agg.IAggregation;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.service.aggregations.AggregationsService;
|
|
|
import com.yoho.search.service.aggregations.impls.AggregationFactory;
|
...
|
...
|
@@ -15,6 +17,7 @@ import com.yoho.search.service.helper.UfoSearchQueryHelper; |
|
|
import org.elasticsearch.common.Nullable;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
...
|
...
|
@@ -37,12 +40,11 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
|
|
private AggregationFactory aggregationFactory;
|
|
|
@Autowired
|
|
|
private AggregationsService aggregationsService;
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
|
|
|
public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
|
|
|
return this.aggAllBrandList(paramMap, null);
|
|
|
}
|
|
|
|
|
|
public SearchApiResult aggAllBrandList(Map<String, String> paramMap, BoolQueryBuilder mustFilter) {
|
|
|
public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、构造带filter和query的SearchParam
|
|
|
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> { |
|
|
|
|
|
@Override
|
|
|
protected int cacheTimeInMinute() {
|
|
|
return CacheTimeConstants.CACHE_30_MINUTE;
|
|
|
return 0;//CacheTimeConstants.CACHE_30_MINUTE;
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -81,7 +83,9 @@ public class UfoAggBrandService extends AbstractCacheComponent<JSONArray> { |
|
|
IAggregation brandAggregation = (IAggregation) params[0];
|
|
|
|
|
|
// 2、从ES中获取
|
|
|
JSONObject jsonObject = aggregationsService.getAggNameAndResponse(brandAggregation, searchParam);
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);//this.doSearchForAggregation(searchParam, AggregationServiceIndex);
|
|
|
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps);
|
|
|
|
|
|
// 3、生成结果
|
|
|
JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|
...
|
...
|
|