|
|
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));
|
...
|
...
|
@@ -38,7 +45,7 @@ public class RecommendShopAggregation extends AbstractAggregation { |
|
|
public final String aggName() {
|
|
|
return "recommendShopAgg";
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public String filterName() {
|
|
|
return "recommendShop";
|
...
|
...
|
@@ -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;
|
|
|
}
|
|
|
} |
...
|
...
|
|