...
|
...
|
@@ -2,8 +2,8 @@ package com.yoho.search.service.scene.ufo; |
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.aop.cache.SearchCacheAble;
|
|
|
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.utils.SearchApiResultUtils;
|
|
|
import com.yoho.search.core.es.agg.IAggregation;
|
...
|
...
|
@@ -32,7 +32,7 @@ import java.util.Map; |
|
|
* @version 2018/9/17
|
|
|
*/
|
|
|
@Service
|
|
|
public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> {
|
|
|
public class UfoSelectionsService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(UfoSelectionsService.class);
|
|
|
|
...
|
...
|
@@ -43,31 +43,26 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { |
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
|
|
|
@SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = 10)
|
|
|
public SearchApiResult getSelectionsForApp(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
return this.getSelectionsForApp(paramMap, null);
|
|
|
// 1)构造searchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilder(paramMap, null);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
QueryBuilder queryBuilder = ufoSearchQueryHelper.constructQueryBuilder(paramMap);
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
searchParam.setSize(0);
|
|
|
// 2)调父类查询
|
|
|
JSONObject result = doRealQuery(searchParam, paramMap);
|
|
|
// 3)生成结果
|
|
|
return new SearchApiResult().setData(result);
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult(logger, paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SearchApiResult getSelectionsForApp(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {
|
|
|
// 1)构造searchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = ufoSearchQueryHelper.constructFilterBuilder(paramMap, null);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
QueryBuilder queryBuilder = ufoSearchQueryHelper.constructQueryBuilder(paramMap);
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
searchParam.setSize(0);
|
|
|
// 2)调父类查询
|
|
|
JSONObject result = super.queryWithCache(searchParam, paramMap);
|
|
|
// 3)生成结果
|
|
|
return new SearchApiResult().setData(result);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected JSONObject doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
|
|
|
|
|
|
private JSONObject doRealQuery(SearchParam searchParam, @Nullable Object... params) throws Exception {
|
|
|
Map<String, String> paramMap = (Map<String, String>) params[0];
|
|
|
|
|
|
// 构造聚合报文
|
...
|
...
|
@@ -89,42 +84,26 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { |
|
|
return dataMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected int cacheTimeInMinute() {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected String cacheSceneKey() {
|
|
|
return "UFO_SELECTIONS_FOR_APP";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构造不带提前聚合逻辑的报文
|
|
|
**/
|
|
|
private List<AbstractAggregationBuilder<?>> getAllAggregationBuilders(Map<String, String> paramMap) {
|
|
|
List<AbstractAggregationBuilder<?>> list = new ArrayList<AbstractAggregationBuilder<?>>();
|
|
|
|
|
|
// 6)品牌
|
|
|
//品牌
|
|
|
list.add(aggregationFactory.getUfoBrandAggregation(paramMap).getBuilder());
|
|
|
|
|
|
//品类
|
|
|
list.add(aggregationFactory.getUfoSortAggregation(paramMap).getBuilder());
|
|
|
|
|
|
// 2)性别
|
|
|
//性别
|
|
|
list.add(aggregationFactory.getUfoGenderAggregation().getBuilder());
|
|
|
|
|
|
// 8)尺码
|
|
|
//尺码
|
|
|
list.add(aggregationFactory.getUfoSizeAggregation().getBuilder());
|
|
|
|
|
|
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
private Map<String, Object> getAggResultMap(Map<String, String> paramMap, Map<String, Aggregation> aggMaps) {
|
|
|
Map<String, Object> filter = new HashMap<String, Object>();
|
|
|
|
|
|
// 2)获取性别的聚合结果
|
|
|
// 性别的聚合结果
|
|
|
IAggregation genderAggregation = aggregationFactory.getUfoGenderAggregation();
|
|
|
Object genderResponse = genderAggregation.getAggregationResponseMap(aggMaps);
|
|
|
if (genderResponse != null) {
|
...
|
...
|
@@ -133,7 +112,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { |
|
|
filter.put("gender", new JSONArray());
|
|
|
}
|
|
|
|
|
|
// 6)获取品牌层面的聚合结果
|
|
|
// 6品牌层面的聚合结果
|
|
|
IAggregation brandAggregation = aggregationFactory.getUfoBrandAggregation(paramMap);
|
|
|
Object brandResponse = brandAggregation.getAggregationResponseMap(aggMaps);
|
|
|
if (brandResponse != null) {
|
...
|
...
|
@@ -151,7 +130,7 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { |
|
|
filter.put("sort", new JSONArray());
|
|
|
}
|
|
|
|
|
|
// 7)获取尺码聚合结果[尺码不会提前聚合]
|
|
|
// 尺码
|
|
|
IAggregation sizeAggregation = aggregationFactory.getUfoSizeAggregation();
|
|
|
Object sizeResponse = sizeAggregation.getAggregationResponseMap(aggMaps);
|
|
|
if (sizeResponse != null) {
|
...
|
...
|
@@ -160,7 +139,6 @@ public class UfoSelectionsService extends AbstractCacheComponent<JSONObject> { |
|
|
filter.put("size", new JSONArray());
|
|
|
}
|
|
|
|
|
|
|
|
|
return filter;
|
|
|
}
|
|
|
|
...
|
...
|
|