...
|
...
|
@@ -34,7 +34,6 @@ import com.yoho.search.service.service.IAggRecommendService; |
|
|
public class AggRecommendServiceImpl implements IAggRecommendService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(AggRecommendServiceImpl.class);
|
|
|
private static final String RECOMMENG_PROMOTION_LIST = "recommend_promotion_list";
|
|
|
private static final int DEFAULT_AGGREGATION_COUNT = 100;
|
|
|
|
|
|
@Autowired
|
...
|
...
|
@@ -159,12 +158,8 @@ public class AggRecommendServiceImpl implements IAggRecommendService { |
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void recommendPromotion(SearchApiResult searchResult, Map<String, String> paramMap) {
|
|
|
public List<Object> recommendPromotion(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
if (searchResult == null || searchResult.getCode() != 200 || searchResult.getData() == null) {
|
|
|
return;
|
|
|
}
|
|
|
JSONObject dataMap = ((JSONObject) searchResult.getData());
|
|
|
// 1、获取核心参数
|
|
|
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
// 1.1添加默认参数
|
...
|
...
|
@@ -185,24 +180,23 @@ public class AggRecommendServiceImpl implements IAggRecommendService { |
|
|
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (cacheJSONArray != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("/productList.json", paramMap);
|
|
|
dataMap.put(RECOMMENG_PROMOTION_LIST, subList(cacheJSONArray, page, 1));
|
|
|
return;
|
|
|
return subList(cacheJSONArray, page, 1);
|
|
|
}
|
|
|
// 6、从ES中获取
|
|
|
JSONObject recommendPromotionResult = aggregationService.getAggNameAndResponse(recommendPromotionAgg, searchParam);
|
|
|
if (recommendPromotionResult == null) {
|
|
|
return;
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
// 7、生成结果并且加入缓存
|
|
|
JSONArray recommendPromotions = recommendPromotionResult.getJSONArray(recommendPromotionAgg.aggName());
|
|
|
if (recommendPromotions != null) {
|
|
|
searchCacheService.addJSONArrayToCache(searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam, recommendPromotions);
|
|
|
dataMap.put(RECOMMENG_PROMOTION_LIST, subList(recommendPromotions, page, 1));
|
|
|
return subList(recommendPromotions, page, 1);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
return;
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
return;
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
private List<Object> subList(JSONArray sourceList, int page, int count) {
|
...
|
...
|
|