...
|
...
|
@@ -13,7 +13,6 @@ import com.yoho.search.core.es.model.SearchResult; |
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.service.aggregations.impls.AggregationFactory;
|
|
|
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;
|
...
|
...
|
@@ -25,10 +24,6 @@ import org.springframework.stereotype.Service; |
|
|
import java.util.Arrays;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author wangnan
|
|
|
* @version 2018/9/17
|
|
|
*/
|
|
|
@Service
|
|
|
public class UfoBrandListService {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UfoBrandListService.class);
|
...
|
...
|
@@ -41,7 +36,7 @@ public class UfoBrandListService { |
|
|
private SearchCommonService searchCommonService;
|
|
|
|
|
|
@SearchCacheAble(cacheName = "UFO_BRAND_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
|
|
|
public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
|
|
|
public SearchApiResult ufoBrandList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、构造带filter和query的SearchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
...
|
...
|
@@ -55,8 +50,13 @@ public class UfoBrandListService { |
|
|
IAggregation brandAggregation = aggregationFactory.getUfoBrandAggregation(paramMap);
|
|
|
searchParam.setAggregationBuilders(Arrays.asList(brandAggregation.getBuilder()));
|
|
|
|
|
|
// 3、调父类方法执行查询
|
|
|
JSONArray brandJSONArray = doRealQuery(searchParam, brandAggregation);
|
|
|
// 3、执行搜索
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
|
|
|
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps);
|
|
|
JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|
|
|
|
|
|
// 4、返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("brand_list", brandJSONArray);
|
|
|
return new SearchApiResult().setData(dataMap);
|
...
|
...
|
@@ -65,18 +65,4 @@ public class UfoBrandListService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
private JSONArray doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
|
|
|
// 1、从参数中获取IAggregation brandAggregation
|
|
|
IAggregation brandAggregation = (IAggregation) params[0];
|
|
|
|
|
|
// 2、从ES中获取
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_UFO_PRODUCT_INDEX, searchParam);
|
|
|
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
JSONObject jsonObject = brandAggregation.getAggNameAndResponse(aggMaps);
|
|
|
|
|
|
// 3、生成结果
|
|
|
JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|
|
|
return brandJSONArray;
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|