Authored by unknown

推荐店铺返回推荐的商品

... ... @@ -81,8 +81,8 @@ public class AggregationFactoryService {
return new RecommendBrandAggregation(brandIndexBaseService, personalVectorFeatureSearch, paramMap, brandCount);
}
public IAggregation getRecommendShopAggregation(Map<String, String> paramMap, int shopCount) {
return new RecommendShopAggregation(shopsIndexBaseService, personalVectorFeatureSearch, paramMap, shopCount);
public IAggregation getRecommendShopAggregation(Map<String, String> paramMap, int shopCount,int topHitCount) {
return new RecommendShopAggregation(shopsIndexBaseService,productIndexBaseService,personalVectorFeatureSearch, paramMap, shopCount,topHitCount);
}
public IAggregation getGroupBrandAggregation(String topHitOrder, int tophitCount) {
... ...
package com.yoho.search.service.aggregations.impls;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
... ... @@ -11,6 +12,7 @@ import org.springframework.util.CollectionUtils;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.agg.AbstractAggregation;
import com.yoho.search.service.aggregations.common.SimpleFieldAgg;
import com.yoho.search.service.base.index.ProductIndexBaseService;
import com.yoho.search.service.base.index.ShopsIndexBaseService;
import com.yoho.search.service.helper.AggCommonHelper;
import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch;
... ... @@ -18,13 +20,18 @@ import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch;
public class RecommendShopAggregation extends AbstractAggregation {
private ShopsIndexBaseService shopsIndexBaseService;
private ProductIndexBaseService productIndexBaseService;
private List<SimpleFieldAgg> simpleFieldAggs;
private int shopCount;
private int topHitCount;
private String topHitOrder = "heatValue:desc";
RecommendShopAggregation(ShopsIndexBaseService shopsIndexBaseService, PersonalVectorFeatureSearch personalVectorFeatureSearch, Map<String, String> paramMap, int shopCount) {
RecommendShopAggregation(ShopsIndexBaseService shopsIndexBaseService, ProductIndexBaseService productIndexBaseService, PersonalVectorFeatureSearch personalVectorFeatureSearch,
Map<String, String> paramMap, int shopCount, int topHitCount) {
this.shopsIndexBaseService = shopsIndexBaseService;
this.productIndexBaseService = productIndexBaseService;
this.shopCount = shopCount;
this.topHitCount = topHitCount;
// 构造聚合条件
this.simpleFieldAggs = new ArrayList<SimpleFieldAgg>();
simpleFieldAggs.add(new SimpleFieldAgg(aggName(), ProductIndexEsField.shopId, shopCount));
... ... @@ -46,23 +53,36 @@ public class RecommendShopAggregation extends AbstractAggregation {
@Override
public AbstractAggregationBuilder getBuilder() {
return AggCommonHelper.getTopHitAggregation(simpleFieldAggs, topHitOrder, 1);
return AggCommonHelper.getTopHitAggregation(simpleFieldAggs, topHitOrder, topHitCount);
}
@Override
public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) {
List<Map<String, Object>> products = AggCommonHelper.getTopHitList(aggMaps, simpleFieldAggs, topHitOrder, shopCount);
List<Map<String, Object>> products = AggCommonHelper.getTopHitList(aggMaps, simpleFieldAggs, topHitOrder, shopCount * topHitCount);
Map<Integer, List<Map<String, Object>>> shopProductsInfo = new HashMap<Integer, List<Map<String, Object>>>();
List<Integer> shopIds = new ArrayList<Integer>();
for (Map<String, Object> esProduct : products) {
Integer shopId = (Integer) esProduct.getOrDefault(ProductIndexEsField.shopId, 0);
if (shopId != null && shopId != 0 && !shopIds.contains(shopId)) {
shopIds.add(shopId);
}
List<Map<String, Object>> shopHitProducts = shopProductsInfo.get(shopId);
if (shopHitProducts == null) {
shopHitProducts = new ArrayList<Map<String, Object>>();
shopProductsInfo.put(shopId, shopHitProducts);
}
Map<String, Object> productReturnInfo = productIndexBaseService.getProductMapFromEsSource(esProduct);
productReturnInfo.put("sales_phrase", "");
productReturnInfo.put("phrase", "");
shopHitProducts.add(productReturnInfo);
}
if (CollectionUtils.isEmpty(shopIds)) {
return new ArrayList<>();
}
return shopsIndexBaseService.getShopListByIdsWithSortAndStatus(shopIds);
List<Map<String, Object>> shopInfoList = shopsIndexBaseService.getShopListByIdsWithSortAndStatus(shopIds);
for (Map<String, Object> shopInfo : shopInfoList) {
shopInfo.put("product_list", shopProductsInfo.getOrDefault(shopInfo.getOrDefault("shop_id", 0), new ArrayList<>()));
}
return shopInfoList;
}
}
... ...
... ... @@ -75,8 +75,6 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
needPreAggregation = false;
}
int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));
// paramMap.remove(SearchRequestParams.PARAM_SEARCH_ORDER);//
// 此接口不支持ORDER参数【只会按人气或者个性化打分排序】
// 2、构建带queryBuilder和filter的SearchParam
SearchParam searchParam = searchParamHelper.buildSearchParam(paramMap, true, mustFilter, needPreAggregation ? "brand" : null);
... ... @@ -118,13 +116,19 @@ public class AggRecommendServiceImpl implements IAggRecommendService {
final int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
final int count = StringUtils.isBlank(paramMap.get("viewNum")) ? 1 : Integer.parseInt(paramMap.get("viewNum"));
// 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, true);
// 3、构造聚合操作
IAggregation recommendShopAgg = aggregationFactoryService.getRecommendShopAggregation(paramMap, 100);
IAggregation recommendShopAgg = aggregationFactoryService.getRecommendShopAggregation(paramMap, 100, 2);
searchParam.setAggregationBuilders(Arrays.asList(recommendShopAgg.getBuilder()));
// 4、构建offset
... ...