...
|
...
|
@@ -27,7 +27,7 @@ import com.yoho.search.service.helper.SearchParamHelper; |
|
|
import com.yoho.search.service.recall.beans.persional.UserPersionalFactorComponent;
|
|
|
import com.yoho.search.service.recall.beans.vector.BrandVectorCacheBean;
|
|
|
import com.yoho.search.service.recall.config.SpecialShopConstants;
|
|
|
import com.yoho.search.service.scene.activity.recommendshop.ActivityShopBrand;
|
|
|
import com.yoho.search.service.scene.shopbrand.ShopBrandRelation;
|
|
|
import com.yoho.search.service.scene.general.SortGroupService;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
...
|
...
|
@@ -193,11 +193,11 @@ public class RecommendOnProductAnalysisService { |
|
|
List<Integer> realTimeBrandIds = userFactor.getRealTimeSortBrandList().stream().map(SortBrand::getBrandId).collect(Collectors.toList());
|
|
|
if (!CollectionUtils.isEmpty(realTimeBrandIds)) {
|
|
|
List<AggKeyCountTwoLevel> aggKeyCountTwoLevels = productAggBrandShopIds(paramMap, 10000, 20);
|
|
|
List<ActivityShopBrand> shopBrands = doCombineShopIdAndBrandId(aggKeyCountTwoLevels, realTimeBrandIds);
|
|
|
List<ShopBrandRelation> shopBrands = doCombineShopIdAndBrandId(aggKeyCountTwoLevels, realTimeBrandIds);
|
|
|
if (CollectionUtils.isEmpty(shopBrands)) {
|
|
|
return seenShopIds;
|
|
|
}
|
|
|
seenShopIds = shopBrands.stream().map(ActivityShopBrand::getShopId).distinct().collect(Collectors.toList());
|
|
|
seenShopIds = shopBrands.stream().map(ShopBrandRelation::getShopId).distinct().collect(Collectors.toList());
|
|
|
return SearchCollectionUtils.safeSubList(seenShopIds, 0, 10);
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -213,7 +213,7 @@ public class RecommendOnProductAnalysisService { |
|
|
SearchParam searchParam = buildSearchParam(paramMap);
|
|
|
List<Integer> aggBestBrandIds = aggBestBrandIds(searchParam, 1000);
|
|
|
List<AggKeyCountTwoLevel> aggKeyCountTwoLevels = productAggBrandShopIds(paramMap, 10000, 100);
|
|
|
List<ActivityShopBrand> shopBrands = combineShopIdAndBrandId(aggKeyCountTwoLevels, aggBestBrandIds, viewNum + 10);
|
|
|
List<ShopBrandRelation> shopBrands = combineShopIdAndBrandId(aggKeyCountTwoLevels, aggBestBrandIds, viewNum + 10);
|
|
|
if (CollectionUtils.isEmpty(shopBrands)) {
|
|
|
return recShopIds;
|
|
|
}
|
...
|
...
|
@@ -253,7 +253,7 @@ public class RecommendOnProductAnalysisService { |
|
|
|
|
|
|
|
|
//构造卖的最好的shopidbrandid
|
|
|
private List<ActivityShopBrand> combineShopIdAndBrandId(List<AggKeyCountTwoLevel> aggKeyCountTwoLevels, List<Integer> aggBestBrandIds, int size){
|
|
|
private List<ShopBrandRelation> combineShopIdAndBrandId(List<AggKeyCountTwoLevel> aggKeyCountTwoLevels, List<Integer> aggBestBrandIds, int size){
|
|
|
if (CollectionUtils.isEmpty(aggKeyCountTwoLevels)) {
|
|
|
return Collections.emptyList();
|
|
|
}
|
...
|
...
|
@@ -265,8 +265,8 @@ public class RecommendOnProductAnalysisService { |
|
|
return doCombineShopIdAndBrandId(candidateBrandShops, realBestBrandIds);
|
|
|
}
|
|
|
|
|
|
private List<ActivityShopBrand> doCombineShopIdAndBrandId(List<AggKeyCountTwoLevel> candidateBrandShops, List<Integer> realBestBrandIds){
|
|
|
List<ActivityShopBrand> shopBrandList = new ArrayList<>();
|
|
|
private List<ShopBrandRelation> doCombineShopIdAndBrandId(List<AggKeyCountTwoLevel> candidateBrandShops, List<Integer> realBestBrandIds){
|
|
|
List<ShopBrandRelation> shopBrandList = new ArrayList<>();
|
|
|
Set<Integer> filterShopIds = new HashSet<>();
|
|
|
if (!CollectionUtils.isEmpty(candidateBrandShops) && !CollectionUtils.isEmpty(realBestBrandIds)) {
|
|
|
Map<Integer, AggKeyCountTwoLevel> andidateBrandShopsMap = candidateBrandShops.stream().collect(Collectors.toMap(i -> i.getFirstAggKeyCount().getKey(), p -> p));
|
...
|
...
|
@@ -285,7 +285,7 @@ public class RecommendOnProductAnalysisService { |
|
|
if (filterShopIds.contains(shopId)) {
|
|
|
continue;
|
|
|
}
|
|
|
shopBrandList.add(new ActivityShopBrand(shopId, brandId));//取商品数最多的一个店铺即可,防止多品店的问题
|
|
|
shopBrandList.add(new ShopBrandRelation(shopId, brandId));//取商品数最多的一个店铺即可,防止多品店的问题
|
|
|
filterShopIds.add(shopId);//每个品牌只赋给一个店铺
|
|
|
break;
|
|
|
}
|
...
|
...
|
@@ -322,7 +322,7 @@ public class RecommendOnProductAnalysisService { |
|
|
}
|
|
|
|
|
|
//获取用户有行为的品类 排序sort, RealTimeSort加分放前面,预测的放后面
|
|
|
private List<Integer> reorderShopOnUserPersonalBrand(List<ActivityShopBrand> shopBrands, List<AggKeyCountTwoLevel> aggKeyCountTwoLevels, int uid, String udid) {
|
|
|
private List<Integer> reorderShopOnUserPersonalBrand(List<ShopBrandRelation> shopBrands, List<AggKeyCountTwoLevel> aggKeyCountTwoLevels, int uid, String udid) {
|
|
|
if (uid > 0 || StringUtils.isNotBlank(udid)) {
|
|
|
UserPersonalFactorRspNew userFactor = getUserPersonalFactor(uid, udid);
|
|
|
if (userFactor != null && !CollectionUtils.isEmpty(userFactor.getRealTimeSortBrandList())) {
|
...
|
...
|
@@ -332,26 +332,26 @@ public class RecommendOnProductAnalysisService { |
|
|
calScore(shopBrands, userFactor.getBrandVector(), true);
|
|
|
}
|
|
|
Collections.sort(shopBrands, (o1, o2) -> (o2.getScore()).compareTo(o1.getScore()));
|
|
|
List<Integer> orderedAggBestShopIds = shopBrands.stream().map(ActivityShopBrand::getShopId).collect(Collectors.toList());
|
|
|
List<Integer> orderedAggBestShopIds = shopBrands.stream().map(ShopBrandRelation::getShopId).collect(Collectors.toList());
|
|
|
List<Integer> personalBrandIds = userFactor.getRealTimeSortBrandList().stream().map(SortBrand::getBrandId).collect(Collectors.toList());
|
|
|
List<ActivityShopBrand> personalShopBrands = doCombineShopIdAndBrandId(aggKeyCountTwoLevels, personalBrandIds);
|
|
|
List<Integer> personalShopIds = personalShopBrands.stream().map(ActivityShopBrand::getShopId).collect(Collectors.toList());
|
|
|
List<ShopBrandRelation> personalShopBrands = doCombineShopIdAndBrandId(aggKeyCountTwoLevels, personalBrandIds);
|
|
|
List<Integer> personalShopIds = personalShopBrands.stream().map(ShopBrandRelation::getShopId).collect(Collectors.toList());
|
|
|
personalShopIds.addAll(orderedAggBestShopIds);
|
|
|
return personalShopIds.stream().distinct().collect(Collectors.toList());
|
|
|
}
|
|
|
}
|
|
|
return shopBrands.stream().map(ActivityShopBrand::getShopId).distinct().collect(Collectors.toList());
|
|
|
return shopBrands.stream().map(ShopBrandRelation::getShopId).distinct().collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按向量计算品牌得分
|
|
|
*/
|
|
|
private void calScore(List<ActivityShopBrand> shopBrandList, List<Double> userBrandVector, boolean isRnn) {
|
|
|
private void calScore(List<ShopBrandRelation> shopBrandList, List<Double> userBrandVector, boolean isRnn) {
|
|
|
if (userBrandVector == null || userBrandVector.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
double userBrandVectorNorm = Word2VectorCalculator.getVectorListNorm(userBrandVector);
|
|
|
for (ActivityShopBrand shopBrand : shopBrandList) {
|
|
|
for (ShopBrandRelation shopBrand : shopBrandList) {
|
|
|
try {
|
|
|
Integer brandId = shopBrand.getBrandId();
|
|
|
List<Double> brandVector = brandVectorCacheBean.queryBrandVector(brandId, isRnn);
|
...
|
...
|
|