Authored by hugufei

添加兜底策略是否一起参与个性化评分的开关

... ... @@ -61,7 +61,7 @@ public class RecallMergerResultBuilder {
private List<RecallMergerResult.SknResult> distinctRecallSkn(List<RecallRequestResponse> requestResponses) {
List<RecallMergerResult.SknResult> sknResults = new ArrayList<>();
//1、去重以及处理返回类型
Map<Integer, List<StrategyEnum>> sknRequestMaps = new HashMap<>();
Map<Integer, List<StrategyEnum>> skn2StrategyListMap = new HashMap<>();
for (RecallRequestResponse requestResponse : requestResponses) {
RecallRequest request = requestResponse.getRequest();
RecallResponse response = requestResponse.getResponse();
... ... @@ -69,21 +69,21 @@ public class RecallMergerResultBuilder {
continue;
}
for (RecallResponse.RecallSkn recallSkn : response.getSkns()) {
List<StrategyEnum> requestStrategys = sknRequestMaps.get(recallSkn.getSkn());
if (requestStrategys == null) {
List<StrategyEnum> strategyList = skn2StrategyListMap.get(recallSkn.getSkn());
if (strategyList == null) {
//1、加入返回结果
sknResults.add(new RecallMergerResult.SknResult(recallSkn));
//2、处理返回类型
requestStrategys = new ArrayList<>();
sknRequestMaps.put(recallSkn.getSkn(), requestStrategys);
strategyList = new ArrayList<>();
skn2StrategyListMap.put(recallSkn.getSkn(), strategyList);
}
requestStrategys.add(request.requestStrategy());
strategyList.add(request.requestStrategy());
}
}
//2、填充Strategys
for (RecallMergerResult.SknResult sknResult : sknResults) {
List<StrategyEnum> strategyEnum = sknRequestMaps.getOrDefault(sknResult.getProductSkn(), new ArrayList<>());
sknResult.setStrategys(strategyEnum);
List<StrategyEnum> strategyEnumList = skn2StrategyListMap.getOrDefault(sknResult.getProductSkn(), new ArrayList<>());
sknResult.setStrategys(strategyEnumList);
}
return sknResults;
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.recall.scene.beans.builder;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.core.personalized.PersonalizedSearch;
import com.yoho.search.core.personalized.models.SortPriceAreas;
import com.yoho.search.recall.performance.beans.ProductFeatureFactorHepler;
import com.yoho.search.recall.performance.model.UserFeatureFactor;
import com.yoho.search.recall.scene.beans.cache.SknVectorResquestResponseCacheBean;
... ... @@ -14,6 +15,7 @@ import com.yoho.search.recall.scene.models.req.UserRecallRequest;
import com.yoho.search.recall.scene.models.req.UserRecallResponse;
import com.yoho.search.service.base.ProductListSortKey;
import com.yoho.search.service.base.ProductListSortService;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
... ... @@ -36,6 +38,8 @@ public class UserRecallResponseBuilder {
private ProductFeatureFactorHepler productFeatureFactorHepler;
@Autowired
private SknVectorResquestResponseCacheBean sknVectorResquestResponseCacheBean;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
public UserRecallResponse builderRecallResult(RecallMergerResult recallMergerResult, UserRecallRequest param, UserPersonalFactor userPersonalFactor) {
//1、获取总数
... ... @@ -73,7 +77,9 @@ public class UserRecallResponseBuilder {
//8、构造返回结果
List<RecallSknInfo> sknList = new ArrayList<>();
for (RecallMergerResult.SknResult sknResult : sknResultList) {
String requestType = sknResult.getStrategys().get(0).name();//已经按优先级排序好了,取第一个就行
//按优先级排序,去第一种召回策略
Collections.sort(sknResult.getStrategys(), (o1, o2) -> o2.getPriority().compareTo(o1.getPriority()));
String requestType = sknResult.getStrategys().get(0).name();
sknList.add(new RecallSknInfo(sknResult.getProductSkn(), requestType));
}
int recallTotal = sknResultList.size();
... ... @@ -87,10 +93,16 @@ public class UserRecallResponseBuilder {
* @return
*/
private List<RecallMergerResult.SknResult> fillIsLikePriceArea(List<RecallMergerResult.SknResult> sknResults, UserPersonalFactor userPersonalFactor) {
Map<Integer, List<Integer>> misort2PriceAreas = new HashMap<>();
//1、获取用户价格带偏好
Map<Integer, List<Integer>> userMisort2PriceAreasMap = new HashMap<>();
List<SortPriceAreas> userSortPriceAreasList = userPersonalFactor.getSortPriceAreasList();
for (SortPriceAreas userSortPriceAreas: userSortPriceAreasList) {
userMisort2PriceAreasMap.put(userSortPriceAreas.getMisort(),userSortPriceAreas.getPriceAreas());
}
//2、填充当前skn是否属于用户偏好的价格带
for (RecallMergerResult.SknResult sknResult : sknResults) {
Integer misortId = sknResult.getMiddleSortId();
List<Integer> priceAreas = misort2PriceAreas.getOrDefault(misortId, new ArrayList<>());
List<Integer> priceAreas = userMisort2PriceAreasMap.getOrDefault(misortId, new ArrayList<>());
if (priceAreas.contains(sknResult.getPriceArea())) {
sknResult.setLikePriceArea(true);
} else {
... ... @@ -140,8 +152,8 @@ public class UserRecallResponseBuilder {
if (sknResult.isLikePriceArea()) {
score = score + 100;
}
//2)如果是个性化召回来的,则加分
if (this.isPersonalRecall(sknResult)) {
//2)判断兜底的数据是否参与评分
if(!searchDynamicConfigService.searchPersionalNewStrategyCommonJoinScoreOpen() && !this.isCommonRecallOnly(sknResult)){
score = score + 50;
}
sknResult.setScore(score);
... ... @@ -151,20 +163,17 @@ public class UserRecallResponseBuilder {
return sknResultList;
}
private boolean isPersonalRecall(RecallMergerResult.SknResult sknResult) {
private boolean isCommonRecallOnly(RecallMergerResult.SknResult sknResult) {
List<StrategyEnum> strategys = sknResult.getStrategys();
//1、非空判断
if (strategys == null || strategys.isEmpty()) {
return false;
return true;
}
//2、按优先级排序-分数越高的越排在前面
Collections.sort(strategys, (o1, o2) -> (-1) * (o1.getPriority().compareTo(o2.getPriority())));
//3、判断是否只有兜底
if (strategys.get(0).equals(StrategyEnum.COMMON)) {
return false;
//2、只是兜底策略
if(strategys.size()==1 &&strategys.get(0).equals(StrategyEnum.COMMON) ){
return true;
}
return true;
return false;
}
/**
... ...
... ... @@ -167,6 +167,15 @@ public class SearchDynamicConfigService {
}
/**
* 促销页使用新的的召回策略
*
* @return
*/
public boolean searchPersionalNewStrategyPromotionOpen() {
return configReader.getBoolean("search.persional.newstrategy.promotion.open", true);
}
/**
* 新的的召回策略-第一页是否缓存
*
* @return
... ... @@ -176,12 +185,12 @@ public class SearchDynamicConfigService {
}
/**
* 促销页使用新的的召回策略
* 新的的召回策略-兜底策略是否参与评分
*
* @return
*/
public boolean searchPersionalNewStrategyPromotionOpen() {
return configReader.getBoolean("search.persional.newstrategy.promotion.open", true);
public boolean searchPersionalNewStrategyCommonJoinScoreOpen() {
return configReader.getBoolean("search.persional.newstrategy.common.join_score.open", true);
}
/**
... ...
... ... @@ -52,6 +52,7 @@ search.sortpage.recall.brand.count=30
search.persional.newstrategy.open=true
search.persional.newstrategy.promotion.open=true
search.persional.newstrategy.first_page_cache.open=false
search.persional.newstrategy.common.join_score.open=true
#rateLimit
search.persional.rateLimit.open=true
... ...