Authored by hugufei

Merge branch 'recall_config' into 0510

... ... @@ -36,8 +36,6 @@ public class SceneAggregationsHelper {
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private SceneSelectionsService sceneSelectionsService;
@Autowired
private PromotionIndexBaseService promotionIndexBaseService;
private Object getAggregationResponse(IAggregation aggregation, Map<String, String> paramMap) throws Exception {
... ... @@ -166,79 +164,4 @@ public class SceneAggregationsHelper {
}
}
/**
* 通用的筛选项-非个性化
*
* @param paramMap
* @return
*/
@SearchCacheAble(cacheName = "SCENE_AGGREGATIONS", cacheInMinute = 30, excludeParams = { "uid","udid", "order", "page", "viewNum", "yh_channel" })
public SearchApiResult sceneAggregations(Map<String, String> paramMap) {
try {
// 1、获取筛选项列表
List<IAggregation> aggregations = sceneSelectionsService.getCommonAggregations(paramMap);
// 2、构造SearchParam
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
List<AbstractAggregationBuilder<?>> builders = new ArrayList<>();
for (IAggregation aggregation : aggregations) {
builders.add(aggregation.getBuilder());
}
searchParam.setAggregationBuilders(builders);
searchParam.setOffset(0);
searchParam.setSize(0);
// 3、调用ES
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
if (aggMaps == null) {
return new SearchApiResult().setCode(500).setMessage("sceneAggregations Exception");
}
// 4、构造返回结果
JSONObject filter = new JSONObject();
for (IAggregation aggregation : aggregations) {
Object response = aggregation.getAggregationResponseMap(aggMaps);
if (response == null) {
continue;
}
filter.put(aggregation.filterName(), response);
}
return new SearchApiResult().setData(filter);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(500).setMessage("sceneAggregations Exception");
}
}
/**
* 通用的筛选项-个性化推荐品牌
*
* @param paramMap
* @return
*/
@SearchCacheAble(cacheName = "SCENE_RECOMMEND_BRAND", cacheInMinute = 30, excludeParams = { "order", "page", "viewNum", "yh_channel" })
public SearchApiResult sceneRecommendBrand(Map<String, String> paramMap) {
try {
// 1、获取核心参数
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, true);
// 2、构造聚合
IAggregation recommendBrandAgg = aggregationFactoryService.getRecommendBrandAggregation(paramMap, 8);
searchParam.setAggregationBuilders(Arrays.asList(recommendBrandAgg.getBuilder()));
searchParam.setOffset(0);//
// 3、查询es
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
// 4、构造结果
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
JSONObject recommendBrandResult = recommendBrandAgg.getAggNameAndResponse(aggMaps);
JSONArray brandJSONArray = recommendBrandResult.getJSONArray(recommendBrandAgg.aggName());
return new SearchApiResult().setData(brandJSONArray);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(500).setMessage("sceneAggregations Exception");
}
}
}
... ...
... ... @@ -26,23 +26,42 @@ public class SceneRecommendBrandsService {
@Autowired
private UserPersionalFactorComponent userPersionalFactorComponent;
@Autowired
private IAggRecommendService aggRecommendService;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result) {
getRecommendBrands(paramMap, result, null);
}
public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result, BoolQueryBuilder extFilter) {
if (result != null && result.getData() != null) {
JSONObject data = (JSONObject) result.getData();
JSONObject commonFilters = data.getJSONObject("filter");
if (commonFilters != null) {
getRecommendBrandsNew(commonFilters, paramMap);
}
}
}
private void getRecommendBrandsNew(JSONObject commonFilters, Map<String, String> paramMap) {
JSONArray recommendBrands = new JSONArray();
JSONArray brandList = commonFilters.getJSONArray("brand");
if (!CollectionUtils.isEmpty(brandList)) {
recommendBrands = getRecommendBrands(paramMap, brandList);
}
commonFilters.put("recommendBrand", recommendBrands);
}
private JSONArray getRecommendBrands(Map<String, String> paramMap, JSONArray brandList) {
List<JSONObject> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<JSONObject>>() {});
List<JSONObject> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<JSONObject>>() {
});
Map<Integer, JSONObject> brandIdMap = brandListTemp.stream().collect(Collectors.toMap(e -> e.getInteger("id"), Function.identity(), (m1, m2) -> m2));
int uid = MapUtils.getIntValue(paramMap, "uid", 0);
String udid = MapUtils.getString(paramMap, "udid", "");
int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));
JSONArray recBrands = new JSONArray(recommendBrandCount);
UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid,null);
UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid, null);
List<Integer> brandIds = new ArrayList<>();
if (userFactor != null) {
if (userFactor != null && userFactor.getRealTimeSortBrandList()!=null) {
List<SortBrand> sortBrandList = new ArrayList<>(userFactor.getRealTimeSortBrandList());
sortBrandList.addAll(userFactor.getRealTimeSortBrandList());
for (SortBrand sortBrand : sortBrandList) {
if (recBrands.size() >= recommendBrandCount) {
break;
... ... @@ -71,36 +90,4 @@ public class SceneRecommendBrandsService {
return recBrands;
}
public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result) {
getRecommendBrands(paramMap, result, null);
}
public void getRecommendBrands(Map<String, String> paramMap, SearchApiResult result, BoolQueryBuilder extFilter) {
if (result != null && result.getData() != null) {
JSONObject data = (JSONObject) result.getData();
JSONObject commonFilters = data.getJSONObject("filter");
if (commonFilters != null) {
if (searchDynamicConfigService.isRecommendBrandUserPersonalOpen()) {
getRecommendBrandsNew(commonFilters, paramMap);
} else {
getRecommendBrandsOld(commonFilters, paramMap, extFilter);
}
}
}
}
private void getRecommendBrandsNew(JSONObject commonFilters, Map<String, String> paramMap) {
JSONArray recommendBrands = new JSONArray();
JSONArray brandList = commonFilters.getJSONArray("brand");
if (!CollectionUtils.isEmpty(brandList)) {
recommendBrands = getRecommendBrands(paramMap, brandList);
}
commonFilters.put("recommendBrand", recommendBrands);
}
private void getRecommendBrandsOld(JSONObject commonFilters, Map<String, String> paramMap, BoolQueryBuilder extFilter) {
Map<String, String> newParamMap = new HashMap<>(paramMap);
SearchApiResult searchApiResult = aggRecommendService.aggRecommendBrand(newParamMap, extFilter);
commonFilters.put("recommendBrand", searchApiResult.getData());
}
}
... ...
... ... @@ -16,14 +16,6 @@ public interface IAggRecommendService {
*/
SearchApiResult aggRecommendBrand(Map<String, String> paramMap);
/**
* 获取品牌的聚合结果[使用本地缓存]
*
* @param paramMap
* @return
*/
SearchApiResult aggRecommendBrand(Map<String, String> paramMap, BoolQueryBuilder mustFilter);
/**
* 获取店铺的聚合结果[使用本地缓存]
... ...
... ... @@ -54,20 +54,11 @@ public class AggRecommendServiceImpl extends AbstractCacheAbleService implements
public SearchApiResult aggRecommendBrand(Map<String, String> paramMap) {
try {
logger.info("[func=aggRecommendBrand][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
return this.aggRecommendBrand(paramMap, null);
} catch (Exception e) {
return SearchApiResultUtils.errorSearchApiResult("aggRecommendBrand", paramMap, e);
}
}
@Override
public SearchApiResult aggRecommendBrand(Map<String, String> paramMap, BoolQueryBuilder mustFilter) {
try {
// 0、开关支持是否关闭个性化
if (!searchDynamicConfigService.isRecommendPersionalOpen()) {
paramMap.remove("uid");
}
// 1、获取核心参数
boolean needPreAggregation = true;
String aggWithParamBrand = paramMap.get(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND);
... ... @@ -77,7 +68,7 @@ public class AggRecommendServiceImpl extends AbstractCacheAbleService implements
int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));
// 2、构建带queryBuilder和filter的SearchParam
SearchParam searchParam = searchParamHelper.buildSearchParam(paramMap, true, mustFilter, needPreAggregation ? "brand" : null);
SearchParam searchParam = searchParamHelper.buildSearchParam(paramMap, true, null, needPreAggregation ? "brand" : null);
// 3、构造聚合
IAggregation recommendBrandAgg = aggregationFactoryService.getRecommendBrandAggregation(paramMap, recommendBrandCount);
... ...