|
|
package com.yoho.search.service.scene.aggregations;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.service.base.SearchRequestParams;
|
|
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -37,7 +33,7 @@ public class SceneAggregationsHelper { |
|
|
|
|
|
private Object getAggregationResponse(IAggregation aggregation, Map<String, String> paramMap) throws Exception {
|
|
|
// 1、构造SearchParam
|
|
|
SearchParam searchParam = searchParamHelper.buildWithFilterParam(paramMap, null);
|
|
|
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
|
|
|
searchParam.setAggregationBuilders(Arrays.asList(aggregation.getBuilder()));
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(0);
|
...
|
...
|
@@ -60,7 +56,7 @@ public class SceneAggregationsHelper { |
|
|
}
|
|
|
|
|
|
@SearchCacheAble(cacheName = "SCENE_AGG_CUSTOMIZETAG", cacheInMinute = 30, excludeParams = { "uid", "order", "page", "viewNum", "yh_channel" })
|
|
|
public SearchApiResult secneAggCustomizeTag(Map<String, String> paramMap) {
|
|
|
public SearchApiResult sceneAggCustomizeTag(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
IAggregation customizeAggregation = aggregationFactoryService.getCustomizeTagAggregation(paramMap);
|
|
|
Object respone = this.getAggregationResponse(customizeAggregation, paramMap);
|
...
|
...
|
@@ -70,32 +66,14 @@ public class SceneAggregationsHelper { |
|
|
return new SearchApiResult().setCode(500).setMessage("secneAggCustomizeTag Exception");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@SearchCacheAble(cacheName = "SCENE_AGG_RECOMMENDPROMOTION", cacheInMinute = 30, excludeParams = { "uid", "order", "page", "viewNum", "yh_channel" })
|
|
|
public SearchApiResult secneAggRecommendPromotion(Map<String, String> paramMap) {
|
|
|
public SearchApiResult sceneAggRecommendPromotion(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、获取aggregation
|
|
|
IAggregation aggregation = aggregationFactoryService.getRecommendPromotionAggregation(100);
|
|
|
// 1.1添加默认参数
|
|
|
paramMap.remove(SearchRequestParams.PARAM_SEARCH_ORDER);// 此接口不支持order
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND, "Y");// 页面屏蔽
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_STATUS, "1");// 上架
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_STOCKNUM, "1");// 有库存
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_ISOUTLETS, "2");// 非奥莱
|
|
|
paramMap.put(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT, "2");// 非赠品
|
|
|
// 2、构建带queryBuilder和filter的SearchParam
|
|
|
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false);
|
|
|
searchParam.setAggregationBuilders(Arrays.asList(aggregation.getBuilder()));
|
|
|
// 4、构建offset
|
|
|
searchParam.setOffset(100);// justForCache
|
|
|
// 6、从ES中获取
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
|
|
|
JSONObject respone = aggregation.getAggNameAndResponse(aggMaps);
|
|
|
if (respone == null) {
|
|
|
return new SearchApiResult().setData(Collections.emptyList());
|
|
|
}
|
|
|
JSONArray recommendPromotions = respone.getJSONArray("recommendPromotionAgg");
|
|
|
return new SearchApiResult().setData(recommendPromotions);
|
|
|
Object respone = this.getAggregationResponse(aggregation, paramMap);
|
|
|
return new SearchApiResult().setData(respone);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setCode(500).setMessage("secneAggrecommendPromotion Exception");
|
...
|
...
|
|