...
|
...
|
@@ -2,18 +2,22 @@ package com.yoho.search.service.scene.activity; |
|
|
|
|
|
import com.yoho.search.base.helper.Word2VectorCalculator;
|
|
|
import com.yoho.search.base.utils.CollectionUtils;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
import com.yoho.search.cache.beans.AbstractCacheBean;
|
|
|
import com.yoho.search.core.personalized.models.PersonalizedSearch;
|
|
|
import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
|
|
|
import com.yoho.search.service.recall.beans.helper.StrategyHelper;
|
|
|
import com.yoho.search.service.recall.beans.persional.ProductFeatureFactorComponent;
|
|
|
import com.yoho.search.service.recall.beans.persional.UserPersionalFactorComponent;
|
|
|
import com.yoho.search.service.recall.beans.strategy.IStrategy;
|
|
|
import com.yoho.search.service.recall.beans.strategy.impls.SortBrandHeatValueStrategy;
|
|
|
import com.yoho.search.service.recall.beans.strategy.StrategyEnum;
|
|
|
import com.yoho.search.service.recall.beans.vector.BrandVectorCacheBean;
|
|
|
import com.yoho.search.service.recall.models.common.ParamQueryFilter;
|
|
|
import com.yoho.search.service.recall.models.personal.BrandVectorScore;
|
|
|
import com.yoho.search.service.recall.models.personal.UserPersonalFactor;
|
|
|
import com.yoho.search.service.recall.models.personal.UserFeatureFactor;
|
|
|
import com.yoho.search.service.recall.models.req.RecallRequest;
|
|
|
import com.yoho.search.service.recall.models.req.RecallRequestResponse;
|
|
|
import com.yoho.search.service.recall.models.req.UserRecallRequest;
|
|
|
import com.yoho.search.service.scene.shopbrand.AggProductResponse;
|
|
|
import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
...
|
...
|
@@ -31,6 +35,10 @@ public class AggBrandProductCacheBean extends AbstractCacheBean<BrandProductRequ |
|
|
private BrandVectorCacheBean brandVectorCacheBean;
|
|
|
@Autowired
|
|
|
private BatchBrandProductCacheBean batchBrandProductCacheBean;
|
|
|
@Autowired
|
|
|
private PersonalVectorFeatureSearch personalVectorFeatureSearch;
|
|
|
@Autowired
|
|
|
private ProductFeatureFactorComponent productFeatureFactorComponent;
|
|
|
|
|
|
/**
|
|
|
* 入口
|
...
|
...
|
@@ -81,13 +89,50 @@ public class AggBrandProductCacheBean extends AbstractCacheBean<BrandProductRequ |
|
|
}
|
|
|
|
|
|
//2、获取召回结果
|
|
|
batchRecall(brandProductRequest, userPersonalbrandIds, aggBrandIds);
|
|
|
List<BatchBrandProductRequestResponse> brandProductList = batchRecall(brandProductRequest, userPersonalbrandIds, aggBrandIds);
|
|
|
|
|
|
if (brandProductRequest.hasUidOrUdid()) {
|
|
|
doCalScoreAndSort(brandProductList, brandProductRequest.getUid(), brandProductRequest.getBrandCount());
|
|
|
}
|
|
|
|
|
|
//直接截取
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 粗排-按相关性计算得分,并按得分排序
|
|
|
*
|
|
|
* @param sknResultList
|
|
|
* @param uid
|
|
|
*/
|
|
|
private void doCalScoreAndSort(List<BatchBrandProductRequestResponse> sknResultList, int uid, int pageSize) {
|
|
|
//1、获取用户向量
|
|
|
Map<String, String> paramMap = new HashMap<>();
|
|
|
paramMap.put("uid", "" + uid);
|
|
|
PersonalizedSearch personalizedSearch = personalVectorFeatureSearch.queryPersonalizedSearch(paramMap);
|
|
|
UserFeatureFactor userFeatureFactor = new UserFeatureFactor(personalizedSearch);
|
|
|
//2、计算相关性
|
|
|
int recommendSknIndex = 10000;
|
|
|
|
|
|
for (BatchBrandProductRequestResponse brandProduct : sknResultList){
|
|
|
AggProductResponse aggProductResponse = brandProduct.getResponse();
|
|
|
List<Map<String, Object>> productList = aggProductResponse.getProduct_list();
|
|
|
|
|
|
|
|
|
for (Map<String, Object> product : productList) {
|
|
|
double score = 0d;
|
|
|
score = productFeatureFactorComponent.calProductFeatureFactor(userFeatureFactor, product.get(ProductIndexEsField.productFeatureFactor).toString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<Integer> buildUserPersonalBrandIds(List<Integer> aggBrandIds, UserPersonalFactorRspNew userFactor, int count) {
|
|
|
List<Integer> result = new ArrayList<>();
|
|
|
double userBrandVectorNorm = Word2VectorCalculator.getVectorListNorm(userFactor.getBrandVectorW2v());
|
...
|
...
|
@@ -111,11 +156,11 @@ public class AggBrandProductCacheBean extends AbstractCacheBean<BrandProductRequ |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private List<BrandProductRequestResponse> batchRecall(BrandProductRequest brandProductRequest, List<Integer> userPersonalbrandIds, List<Integer> aggBrandIds) {
|
|
|
private List<BatchBrandProductRequestResponse> batchRecall(BrandProductRequest brandProductRequest, List<Integer> userPersonalbrandIds, List<Integer> aggBrandIds) {
|
|
|
|
|
|
List<Integer> brandIds = new ArrayList<>(userPersonalbrandIds);
|
|
|
brandIds.addAll(aggBrandIds);
|
|
|
int brandProductCount = brandProductRequest.getBrandProductCount() + 10;
|
|
|
int brandProductCount = brandProductRequest.getBrandProductCount() + 20;
|
|
|
ParamQueryFilter paramQueryFilter = brandProductRequest.getParamQueryFilter();
|
|
|
|
|
|
List<RecallRequest> brandRequests = brandIds.stream().map(brandId -> {
|
...
|
...
|
@@ -123,11 +168,8 @@ public class AggBrandProductCacheBean extends AbstractCacheBean<BrandProductRequ |
|
|
return new RecallRequest(paramQueryFilter, strategy);
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
List<BatchBrandProductRequestResponse> requestResponses = batchBrandProductCacheBean.batchRecallAndCache(brandRequests);
|
|
|
return requestResponses;
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|