Authored by hugufei

数量和间隔代码优化

... ... @@ -2,6 +2,7 @@ package com.yoho.search.recall.beans.builder;
import com.yoho.search.common.utils.ABUserPartitionUtils;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.config.RecallCommonConfig;
import com.yoho.search.recall.config.RecallCommonConfigService;
import com.yoho.search.recall.beans.strategy.impls.*;
... ... @@ -32,16 +33,13 @@ public class CommonRecallRequestBuilder {
//1、构造召回请求
List<RecallRequest> requests = new ArrayList<>();
//1.1) firstSkn的召回
requests.add(this.buildFirstSknRequest(paramQueryFilter, firstProductSkns, 1));
requests.add(this.buildFirstSknRequest(paramQueryFilter, firstProductSkns, userRecallRequest.getPageId()));
//1.2) 直通车召回
RecallCommonConfig directTrainConfig = recallCommonConfigService.getDirectTrainConfig(userRecallRequest.getPageId());
requests.add(this.buildDirectTrainRequest(paramQueryFilter, directTrainConfig.getSize()));
requests.add(this.buildDirectTrainRequest(paramQueryFilter, userRecallRequest.getPageId()));
//1.3) 新开店铺的召回
RecallCommonConfig newShopConfig = recallCommonConfigService.getNewShopConfig(userRecallRequest.getPageId());
requests.add(this.buildNewShopRequest(paramQueryFilter, newShopConfig.getSize()));
requests.add(this.buildNewShopRequest(paramQueryFilter, userRecallRequest.getPageId()));
//1.4) 流量补偿的召回
RecallCommonConfig addFlowConfig = recallCommonConfigService.getAddFlowConfig(userRecallRequest.getPageId());
requests.add(this.buildAddFlowRequest(paramQueryFilter, addFlowConfig.getSize()));
requests.add(this.buildAddFlowRequest(paramQueryFilter,userRecallRequest.getPageId()));
//1.5) 页面的兜底召回
if (ABUserPartitionUtils.isAUserComplete(userRecallRequest.getUid(), userRecallRequest.getUdid())) {
requests.add(this.buildCommonHeatValueStrategy(paramQueryFilter, pageSize));
... ... @@ -56,11 +54,11 @@ public class CommonRecallRequestBuilder {
*
* @param paramQueryFilter
* @param firstProductSkns
* @param size
* @param pageId
* @return
*/
private RecallRequest buildFirstSknRequest(ParamQueryFilter paramQueryFilter, List<String> firstProductSkns, int size) {
CommonFirstSknStrategy strategy = new CommonFirstSknStrategy(size, firstProductSkns);
private RecallRequest buildFirstSknRequest(ParamQueryFilter paramQueryFilter, List<String> firstProductSkns, int pageId) {
CommonFirstSknStrategy strategy = new CommonFirstSknStrategy(1, firstProductSkns);
return new RecallRequest(paramQueryFilter, strategy);
}
... ... @@ -68,10 +66,11 @@ public class CommonRecallRequestBuilder {
* 构建【按直通车召回】的请求参数
*
* @param paramQueryFilter
* @param size
* @param pageId
* @return
*/
private RecallRequest buildDirectTrainRequest(ParamQueryFilter paramQueryFilter, int size) {
private RecallRequest buildDirectTrainRequest(ParamQueryFilter paramQueryFilter, int pageId) {
int size = recallCommonConfigService.getRecallSize(pageId, StrategyEnum.DIRECT_TRAIN);
CommonDirectTrainStrategy strategy = new CommonDirectTrainStrategy(size);
return new RecallRequest(paramQueryFilter, strategy);
}
... ... @@ -80,10 +79,11 @@ public class CommonRecallRequestBuilder {
* 构建【按新开店铺召回】的请求参数
*
* @param paramQueryFilter
* @param size
* @param pageId
* @return
*/
private RecallRequest buildNewShopRequest(ParamQueryFilter paramQueryFilter, int size) {
private RecallRequest buildNewShopRequest(ParamQueryFilter paramQueryFilter, int pageId) {
int size = recallCommonConfigService.getRecallSize(pageId, StrategyEnum.NEW_SHOP);
CommonNewShopStrategy strategy = new CommonNewShopStrategy(size);
return new RecallRequest(paramQueryFilter, strategy);
}
... ... @@ -92,10 +92,11 @@ public class CommonRecallRequestBuilder {
* 构建【流量补偿】的请求参数
*
* @param paramQueryFilter
* @param size
* @param pageId
* @return
*/
private RecallRequest buildAddFlowRequest(ParamQueryFilter paramQueryFilter, int size) {
private RecallRequest buildAddFlowRequest(ParamQueryFilter paramQueryFilter, int pageId) {
int size = recallCommonConfigService.getRecallSize(pageId, StrategyEnum.ADD_FLOW);
CommonAddFlowStrategy strategy = new CommonAddFlowStrategy(size);
return new RecallRequest(paramQueryFilter, strategy);
}
... ...
... ... @@ -38,8 +38,6 @@ public class UserRecallResponseBuilder {
@Autowired
private SknBaseInfoCacheBean sknBaseInfoCacheBean;
@Autowired
private SearchDynamicConfigService searchDynamicConfigService;
@Autowired
private RecallCommonConfigService recallCommonConfigService;
public UserRecallResponse builderRecallResult(RecallMergerResult recallMergerResult, UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
... ... @@ -60,7 +58,7 @@ public class UserRecallResponseBuilder {
sknResultList = this.doCalScoreAndSort(sknResultList, userRecallRequest.getUid(), userRecallRequest.getPageSize());
//6、处理firstSkn-直通车等信息
sknResultList = this.doReRank(sknResultList);
sknResultList = this.doReRank(userRecallRequest.getPageId(), sknResultList);
//7、添加日志
for (RecallMergerResult.SknResult sknResult : sknResultList) {
... ... @@ -270,14 +268,14 @@ public class UserRecallResponseBuilder {
}
/**
* 重排-处理直通车以及直通车
* 重排-处理需要占坑的商品
*
* @param pageId
* @param sknResultList
* @return
*/
private List<RecallMergerResult.SknResult> doReRank(List<RecallMergerResult.SknResult> sknResultList) {
private List<RecallMergerResult.SknResult> doReRank(int pageId, List<RecallMergerResult.SknResult> sknResultList) {
List<RecallMergerResult.SknResult> results = new ArrayList<>();
//1、插入first_skn
Iterator<RecallMergerResult.SknResult> iterator = sknResultList.iterator();
while (iterator.hasNext()) {
... ... @@ -288,27 +286,22 @@ public class UserRecallResponseBuilder {
break;
}
}
// 2、加入全部【除直通车和推荐】外的商品
// 2、加入全部【占坑位置】外的商品
iterator = sknResultList.iterator();
List<StrategyEnum> intervalStrategyEnums = StrategyHelper.getIntervalStrategyEnums();
while (iterator.hasNext()) {
RecallMergerResult.SknResult sknResult = iterator.next();
if (!Arrays.asList(StrategyEnum.DIRECT_TRAIN, StrategyEnum.REC_SKN, StrategyEnum.RT_SIM_SKN).contains(sknResult.getStrategy())) {
if (!intervalStrategyEnums.contains(sknResult.getStrategy())) {
results.add(sknResult);
iterator.remove();
}
}
// 3、插入【REC_SKN】的商品-随机插入
this.addByIndexIndex(sknResultList, results, 1, 2, (sknResult -> StrategyEnum.REC_SKN.equals(sknResult.getStrategy())), dropTransfer);
// 4、插入【RT_SIM_SKN】的商品-随机插入
this.addByIndexIndex(sknResultList, results, 1, 3, (sknResult -> StrategyEnum.RT_SIM_SKN.equals(sknResult.getStrategy())), dropTransfer);
// 5、插入【直通车】商品-随机插入
int directTrainIndexInterval = searchDynamicConfigService.directTrainIndexInterval();
this.addByIndexIndex(sknResultList, results, 4, directTrainIndexInterval, (sknResult -> StrategyEnum.DIRECT_TRAIN.equals(sknResult.getStrategy())), dropTransfer);
// 3、占坑
int fromIndex = 1;
for (StrategyEnum strategyEnum : intervalStrategyEnums) {
int recallInterval = recallCommonConfigService.getRecallInterval(pageId, strategyEnum);
this.addByIndexIndex(sknResultList, results, fromIndex++, recallInterval, (sknResult -> strategyEnum.equals(sknResult.getStrategy())), dropTransfer);
}
return results;
}
... ...
... ... @@ -7,6 +7,7 @@ import com.yoho.search.common.cache.impls.EhCache;
import com.yoho.search.common.cache.impls.SearchRedis;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.config.RecallCommonConfig;
import com.yoho.search.recall.config.RecallCommonConfigService;
import com.yoho.search.recall.beans.persional.PageProductIdBitSetComponent;
... ... @@ -60,14 +61,12 @@ public class SknRecallCacheBean {
try {
List<Integer> filterSknList = new ArrayList<>();
//1、获取实时点击skn的配置
RecallCommonConfig recSknConfig = recallCommonConfigService.getRecSknConfig(userRecallRequest.getPageId());
int recSknCount = recSknConfig == null ? 0 : recSknConfig.getSize();
int recSknCount = recallCommonConfigService.getRecallSize(userRecallRequest.getPageId(), StrategyEnum.REC_SKN);
if (recSknCount > 0 && userPersonalFactor.getRecommendSknList() != null) {
filterSknList.addAll(userPersonalFactor.getRecommendSknList());
}
//2、获取相似skn的配置
RecallCommonConfig rtSimSknConfig = recallCommonConfigService.getRtSimSknConfig(userRecallRequest.getPageId());
int rtSimSknCount = rtSimSknConfig == null ? 0 : rtSimSknConfig.getSize();
int rtSimSknCount = recallCommonConfigService.getRecallSize(userRecallRequest.getPageId(), StrategyEnum.RT_SIM_SKN);
if (rtSimSknCount > 0 && userPersonalFactor.getRealTimeSimilarSknList() != null) {
filterSknList.addAll(userPersonalFactor.getRealTimeSimilarSknList());
}
... ... @@ -91,7 +90,7 @@ public class SknRecallCacheBean {
}
private List<RecallRequestResponse> buildResults(ParamQueryFilter paramQueryFilter, List<Integer> filterSkns, Class<? extends IRecallSknStrategy> clazz, List<Integer> sknResults, int maxReturnCount) {
if (filterSkns == null || filterSkns.isEmpty() || sknResults == null || sknResults.isEmpty()) {
if (filterSkns == null || filterSkns.isEmpty() || sknResults == null || sknResults.isEmpty() || maxReturnCount<=0){
return new ArrayList<>();
}
List<RecallRequestResponse> results = new ArrayList<>();
... ...
package com.yoho.search.recall.beans.helper;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.config.RecallCommonConfigKeys;
import java.util.Arrays;
import java.util.List;
public class StrategyHelper {
public static boolean isCommonStrategy(StrategyEnum strategy) {
return strategy.equals(StrategyEnum.COMMON_CTR_VALUE) || strategy.equals(StrategyEnum.COMMON_HEAT_VALUE);
}
public static List<StrategyEnum> getIntervalStrategyEnums() {
return Arrays.asList(StrategyEnum.REC_SKN, StrategyEnum.RT_SIM_SKN, StrategyEnum.DIRECT_TRAIN, StrategyEnum.ADD_FLOW, StrategyEnum.NEW_SHOP);
}
}
... ...
package com.yoho.search.recall.config;
import com.yoho.search.recall.beans.helper.StrategyHelper;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import java.util.HashMap;
... ... @@ -26,63 +29,43 @@ public class RecallCommonConfigService {
}
}
/**
* 获取实时skn的配置
*
* @param pageId
* @return
*/
public RecallCommonConfig getRecSknConfig(int pageId) {
RecallCommonConfig config = queryCommonConfig(pageId, RecallCommonConfigKeys.REC_SKN);
return config == null ? new RecallCommonConfig(8, 2) : config;
}
/**
* 获取相似skn的配置
*
* @param pageId
* @return
*/
public RecallCommonConfig getRtSimSknConfig(int pageId) {
RecallCommonConfig config = queryCommonConfig(pageId, RecallCommonConfigKeys.RT_SIM_SKN);
return config == null ? new RecallCommonConfig(8, 3) : config;
}
/**
* 获取直通车的配置
*
* @param pageId
* @return
*/
public RecallCommonConfig getDirectTrainConfig(int pageId) {
RecallCommonConfig config = queryCommonConfig(pageId, RecallCommonConfigKeys.DIRECT_TRAIN);
return config == null ? new RecallCommonConfig(60, 5) : config;
private String getConfiKey(StrategyEnum strategyEnum) {
if (strategyEnum.equals(StrategyEnum.REC_SKN)) {
return RecallCommonConfigKeys.REC_SKN;
}
if (strategyEnum.equals(StrategyEnum.RT_SIM_SKN)) {
return RecallCommonConfigKeys.RT_SIM_SKN;
}
if (strategyEnum.equals(StrategyEnum.DIRECT_TRAIN)) {
return RecallCommonConfigKeys.DIRECT_TRAIN;
}
if (strategyEnum.equals(StrategyEnum.NEW_SHOP)) {
return RecallCommonConfigKeys.NEW_SHOP;
}
if (strategyEnum.equals(StrategyEnum.ADD_FLOW)) {
return RecallCommonConfigKeys.ADD_FLOW;
}
return null;
}
/**
* 获取新开店铺的配置
*
* @param pageId
* @return
*/
public RecallCommonConfig getNewShopConfig(int pageId) {
RecallCommonConfig config = queryCommonConfig(pageId, RecallCommonConfigKeys.NEW_SHOP);
return config == null ? new RecallCommonConfig(10, 8) : config;
public int getRecallSize(int pageId, StrategyEnum strategyEnum) {
String configKey = this.getConfiKey(strategyEnum);
if (StringUtils.isBlank(configKey)) {
return 0;
}
RecallCommonConfig config = queryCommonConfig(pageId, configKey);
return config == null ? 0 : config.getSize();
}
/**
* 获取addFlow的配置
*
* @param pageId
* @return
*/
public RecallCommonConfig getAddFlowConfig(int pageId) {
RecallCommonConfig config = queryCommonConfig(pageId, RecallCommonConfigKeys.ADD_FLOW);
return config == null ? new RecallCommonConfig(10, 8) : config;
public int getRecallInterval(int pageId, StrategyEnum strategyEnum) {
String configKey = this.getConfiKey(strategyEnum);
if (StringUtils.isBlank(configKey)) {
return 0;
}
RecallCommonConfig config = queryCommonConfig(pageId, configKey);
return config == null ? 0 : config.getInterval();
}
/**
* 获取推荐的品类品牌的配置
*
... ...