Authored by hugufei

搜索支持配置的品类品牌召回

... ... @@ -113,7 +113,10 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us
//5、处理基于RNN向量生成的品类品牌的召回
CompletableFuture<List<RecallRequestResponse>> vectorRnnSortBrandCompletableFuture = this.doRecallVectorRnnSortBrand(userRecallRequest, userPersonalFactor);
//6、构造最终返回结果投入额
//6、处理基于RNN向量生成的品类品牌的召回
CompletableFuture<List<RecallRequestResponse>> configSortBrandCompletableFuture = this.doRecallConfigSortBrand(userRecallRequest, userPersonalFactor);
//7、构造最终返回结果投入额
List<RecallRequestResponse> batchRequestResults = new ArrayList<>();
batchRequestResults.addAll(this.getResultFromCompletableFuture(sknListCompletableFuture));//按skn召回放在第一个,不然merger的时候可能会无序
... ... @@ -121,6 +124,7 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us
batchRequestResults.addAll(this.getResultFromCompletableFuture(realTimeSortBrandCompletableFuture));
batchRequestResults.addAll(this.getResultFromCompletableFuture(vectorW2vSortBrandCompletableFuture));
batchRequestResults.addAll(this.getResultFromCompletableFuture(vectorRnnSortBrandCompletableFuture));
batchRequestResults.addAll(this.getResultFromCompletableFuture(configSortBrandCompletableFuture));
//9、日志打印
if (userRecallRequest.openDetailLog()) {
... ... @@ -207,7 +211,7 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us
long begin = System.currentTimeMillis();
List<RecallRequest> vectorRnnSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest, userPersonalFactor.getVectorRnnSortBrandList(), SortBrandType.VEC_RNN_SORT_BRAND);
List<RecallRequestResponse> vecSortBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(vectorRnnSortBrandRequests);
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.5]-doRecallVectorRnnSortBrand,requestCount is [{}], cost is [{}]", vectorRnnSortBrandRequests.size(), System.currentTimeMillis() - begin);
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.4]-doRecallVectorRnnSortBrand,requestCount is [{}], cost is [{}]", vectorRnnSortBrandRequests.size(), System.currentTimeMillis() - begin);
return vecSortBrandRequestsResponses;
}, recallExecutorService);
}
... ... @@ -224,9 +228,26 @@ public class UserRecallCacheBean extends AbstractCacheBean<UserRecallRequest, Us
long begin = System.currentTimeMillis();
List<RecallRequest> vectorW2vSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest, userPersonalFactor.getVectorW2vSortBrandList(), SortBrandType.VEC_W2V_SORT_BRAND);
List<RecallRequestResponse> vecSortBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(vectorW2vSortBrandRequests);
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.6]-doRecallVectorW2vSortBrand,requestCount is [{}], cost is [{}]", vectorW2vSortBrandRequests.size(), System.currentTimeMillis() - begin);
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.5]-doRecallVectorW2vSortBrand,requestCount is [{}], cost is [{}]", vectorW2vSortBrandRequests.size(), System.currentTimeMillis() - begin);
return vecSortBrandRequestsResponses;
}, recallExecutorService);
}
/**
* 执行配置的【品牌+品类】的召回
*
* @param userRecallRequest
* @param userPersonalFactor
* @return
*/
private CompletableFuture<List<RecallRequestResponse>> doRecallConfigSortBrand(UserRecallRequest userRecallRequest, UserPersonalFactor userPersonalFactor) {
return CompletableFuture.supplyAsync(() -> {
long begin = System.currentTimeMillis();
List<RecallRequest> configSortBrandRequests = sortBrandRecallRequestBuilder.buildSortBrandRecallRequests(userRecallRequest, userPersonalFactor.getConfigSortBrandList(), SortBrandType.CONFIG_SORT_BRAND);
List<RecallRequestResponse> configBrandRequestsResponses = batchRecallCacheBean.batchRecallAndCache(configSortBrandRequests);
RECALL_NEW_LOGGER.info("UserRecallCacheBean[2.6]-doRecallConfigSortBrand,requestCount is [{}], cost is [{}]", configSortBrandRequests.size(), System.currentTimeMillis() - begin);
return configBrandRequestsResponses;
}, recallExecutorService);
}
}
... ...
... ... @@ -3,6 +3,7 @@ package com.yoho.search.recall.beans.persional;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.core.personalized.models.SortPriceAreas;
import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.vector.SortBrandVectorComponent;
import com.yoho.search.recall.config.RecallConfigService;
import com.yoho.search.recall.models.personal.PagePersonalFactor;
... ... @@ -93,28 +94,31 @@ public class QueryUserPersionalFactorBean {
pageSortBrandKeys.add(pageSortBrand.key());
}
//4、构造实时【品类+品牌】
int recSortBrandCount = recallConfigService.getRecSortBrandCount(pageId);
int recSortBrandCount = recallConfigService.querySortBrandConfigCount(pageId, SortBrandType.REC_SORT_BRAND, 12);
List<SortBrand> realTimeSortBrandList = this.getSortBrandListWithSort(pageSortBrandKeys, filterSortBrandKeys, userFactor.getRealTimeSortBrandList(), recSortBrandCount);
//realTimeSortBrandList = Arrays.asList(new SortBrand(63,28));
for (SortBrand existSortBrand : realTimeSortBrandList) {
filterSortBrandKeys.add(existSortBrand.key());
}
//5、构造基于RNN向量的【品牌+品牌】,去除实时的品类和品牌
int vectorRNNSortBrandCount = recallConfigService.getVectorRNNSortBrandCount(pageId);
int vectorRNNSortBrandCount = recallConfigService.querySortBrandConfigCount(pageId, SortBrandType.VEC_RNN_SORT_BRAND, 0);
List<SortBrand> vectorRnnSortBrandList = sortBrandVectorComponent.queryVectorSortBrandList(pageFactor, filterSortBrandKeys, userFactor.getBrandVector(), userFactor.getSortBrandVector(), true, vectorRNNSortBrandCount);
//vectorRnnSortBrandList = Arrays.asList(new SortBrand(59,199));
for (SortBrand existSortBrand : vectorRnnSortBrandList) {
filterSortBrandKeys.add(existSortBrand.key());
}
//6、构造基于W2V向量的【品牌+品牌】,去除实时的品类和品牌
int vecW2vSortBrandCount = recallConfigService.getVectorW2vSortBrandCount(pageId);
int vecW2vSortBrandCount = recallConfigService.querySortBrandConfigCount(pageId, SortBrandType.VEC_W2V_SORT_BRAND, 12);
List<SortBrand> vectorW2vSortBrandList = sortBrandVectorComponent.queryVectorSortBrandList(pageFactor, filterSortBrandKeys, userFactor.getBrandVectorW2v(), userFactor.getSortBrandVectorW2v(), false, vecW2vSortBrandCount);
//vectorW2vSortBrandList = Arrays.asList(new SortBrand(266,105));
for (SortBrand existSortBrand : vectorW2vSortBrandList) {
filterSortBrandKeys.add(existSortBrand.key());
}
//7、返回最终结果
return new UserPersonalFactor(recommendSknList, realTimeSimilarSknList, sortPriceAreasList, realTimeSortBrandList, vectorRnnSortBrandList, vectorW2vSortBrandList);
//7、构造基于配置的【品牌+品牌】,去除其他类型的品类和品牌
int configSortBrandCount = recallConfigService.querySortBrandConfigCount(pageId, SortBrandType.CONFIG_SORT_BRAND, 0);
List<SortBrand> configSortBrandList = recallConfigService.queryConfigSortBrandList(pageFactor, filterSortBrandKeys, configSortBrandCount);
//8、返回最终结果
return new UserPersonalFactor(recommendSknList, realTimeSimilarSknList, sortPriceAreasList, realTimeSortBrandList, vectorRnnSortBrandList, vectorW2vSortBrandList, configSortBrandList);
}
private List<SortBrand> getSortBrandListWithSort(Set<String> pageSortBrandKeys, Set<String> filterSortBrandKeys, List<SortBrand> userSortBrands, int maxCount) {
... ...
... ... @@ -6,5 +6,6 @@ package com.yoho.search.recall.beans.strategy;
public enum SortBrandType {
REC_SORT_BRAND,
VEC_RNN_SORT_BRAND,
VEC_W2V_SORT_BRAND
VEC_W2V_SORT_BRAND,
CONFIG_SORT_BRAND
}
... ...
... ... @@ -30,8 +30,15 @@ public enum StrategyEnum {
VEC_W2V_S_B_HEAT_VALUE(65),//向量预测的品牌+品类的人气值
VEC_W2V_S_B_RANDOM(64),//向量预测的品牌+品类的随机
COMMON_CTR_VALUE(2),//页面兜底召回-包含个性化【随机200取40】
COMMON_HEAT_VALUE(1),//页面兜底召回-包含个性化【随机200取40】
CONFIG_S_B_NEW(59),//配置的品牌+品类的新品
CONFIG_S_B_PROMOTION(58),//配置的品牌+品类的新开促销
CONFIG_S_B_REDUCE_PRICE(57),//配置的品牌+品类的最新降价
CONFIG_S_B_CTR_VALUE(56),//配置的品牌+品类的转化率
CONFIG_S_B_HEAT_VALUE(55),//配置的的品牌+品类的人气值
CONFIG_S_B_RANDOM(54),//配置的的品牌+品类的随机
COMMON_CTR_VALUE(2),//页面兜底召回
COMMON_HEAT_VALUE(1),//页面兜底召回
DEFAULT_HEAT_VALUE(-1),//第四部分做A/B测试
DEFAULT_CTR_VALUE(-2);//第四部分做A/B测试
... ...
... ... @@ -44,6 +44,8 @@ public abstract class SortBrandAbstractStrategy implements IStrategy {
return StrategyEnum.VEC_RNN_S_B_HEAT_VALUE;
case VEC_W2V_SORT_BRAND:
return StrategyEnum.VEC_W2V_S_B_HEAT_VALUE;
case CONFIG_SORT_BRAND:
return StrategyEnum.CONFIG_S_B_HEAT_VALUE;
default:
return null;
}
... ... @@ -57,6 +59,8 @@ public abstract class SortBrandAbstractStrategy implements IStrategy {
return StrategyEnum.VEC_RNN_S_B_CTR_VALUE;
case VEC_W2V_SORT_BRAND:
return StrategyEnum.VEC_W2V_S_B_CTR_VALUE;
case CONFIG_SORT_BRAND:
return StrategyEnum.CONFIG_S_B_CTR_VALUE;
default:
return null;
}
... ... @@ -70,6 +74,8 @@ public abstract class SortBrandAbstractStrategy implements IStrategy {
return StrategyEnum.VEC_RNN_S_B_NEW;
case VEC_W2V_SORT_BRAND:
return StrategyEnum.VEC_W2V_S_B_NEW;
case CONFIG_SORT_BRAND:
return StrategyEnum.CONFIG_S_B_NEW;
default:
return null;
}
... ... @@ -83,6 +89,8 @@ public abstract class SortBrandAbstractStrategy implements IStrategy {
return StrategyEnum.VEC_RNN_S_B_PROMOTION;
case VEC_W2V_SORT_BRAND:
return StrategyEnum.VEC_W2V_S_B_PROMOTION;
case CONFIG_SORT_BRAND:
return StrategyEnum.CONFIG_S_B_PROMOTION;
default:
return null;
}
... ... @@ -97,6 +105,8 @@ public abstract class SortBrandAbstractStrategy implements IStrategy {
return StrategyEnum.VEC_RNN_S_B_REDUCE_PRICE;
case VEC_W2V_SORT_BRAND:
return StrategyEnum.VEC_W2V_S_B_REDUCE_PRICE;
case CONFIG_SORT_BRAND:
return StrategyEnum.CONFIG_S_B_REDUCE_PRICE;
default:
return null;
}
... ... @@ -110,6 +120,8 @@ public abstract class SortBrandAbstractStrategy implements IStrategy {
return StrategyEnum.VEC_RNN_S_B_RANDOM;
case VEC_W2V_SORT_BRAND:
return StrategyEnum.VEC_W2V_S_B_RANDOM;
case CONFIG_SORT_BRAND:
return StrategyEnum.CONFIG_S_B_PROMOTION;
default:
return null;
}
... ...
package com.yoho.search.recall.config;
import com.alibaba.fastjson.JSON;
import com.yoho.search.dal.model.CsRecallConfigCommon;
import com.yoho.search.service.base.index.CsRecallConfigCommonIndexBaseService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@Component
class RecallConfigCommonService {
private static final Logger logger = LoggerFactory.getLogger(RecallConfigCommonService.class);
@Autowired
private CsRecallConfigCommonIndexBaseService csRecallConfigCommonIndexBaseService;
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
private Map<String, Map<Integer, RecallSizeInterval>> typePageConfigCache = new HashMap<>();
@PostConstruct
void init() {
schedule.scheduleAtFixedRate(() -> loadConfig(), 0, 1, TimeUnit.MINUTES);
}
private void loadConfig() {
try {
List<CsRecallConfigCommon> configList = csRecallConfigCommonIndexBaseService.queryAll();
Map<String, Map<Integer, RecallSizeInterval>> temp = new HashMap<>();
for (CsRecallConfigCommon csRecallConfigCommon : configList) {
Map<Integer, RecallSizeInterval> pageConfigs = temp.get(csRecallConfigCommon.getConfigType());
if (pageConfigs == null) {
pageConfigs = new HashMap<>();
temp.put(csRecallConfigCommon.getConfigType(), pageConfigs);
}
int size = csRecallConfigCommon.getSize();
int interval = csRecallConfigCommon.getInterval();
pageConfigs.put(csRecallConfigCommon.getConfigPage(), new RecallSizeInterval(size, interval));
}
typePageConfigCache = temp;
System.out.println(JSON.toJSONString(typePageConfigCache));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
private RecallSizeInterval queryCommonConfig(String configKey, int configPage) {
Map<Integer, RecallSizeInterval> pageConfigMap = typePageConfigCache.get(configKey);
if (pageConfigMap == null) {
return null;
}
RecallSizeInterval pageConfig = pageConfigMap.get(configPage);
if (pageConfig == null) {
pageConfig = pageConfigMap.get(RecallConfigConstants.DEFAULT_PAGE_ID);
}
if (pageConfigMap == null) {
return null;
} else {
return pageConfig;
}
}
/**
* 获取配置的大小
*
* @param pageId
* @param configKey
* @param defaultSize
* @return
*/
public int queryConfigSize(int pageId, String configKey, int defaultSize) {
if (StringUtils.isBlank(configKey)) {
return defaultSize;
}
RecallSizeInterval config = queryCommonConfig(configKey, pageId);
return config == null ? defaultSize : config.getSize();
}
/**
* 获取配置的间隔
*
* @param pageId
* @param configKey
* @param defaultInterval
* @return
*/
public int queryConfigInterval(int pageId, String configKey, int defaultInterval) {
if (StringUtils.isBlank(configKey)) {
return defaultInterval;
}
RecallSizeInterval config = queryCommonConfig(configKey, pageId);
return config == null ? defaultInterval : config.getInterval();
}
}
... ...
... ... @@ -12,13 +12,12 @@ public class RecallConfigConstants {
public static final String RT_SIM_SKN = "RT_SIM_SKN";
public static final String ADD_FLOW = "ADD_FLOW";
public static final String NEW_SHOP = "NEW_SHOP";
public static final String REC_S_B_COUNT = "REC_S_B_COUNT";
public static final String VEC_RNN_S_B_COUNT = "VEC_RNN_S_B_COUNT";
public static final String VEC_W2V_S_B_COUNT = "VEC_W2V_S_B_COUNT";
public static final String REC_SORT_BRAND = "REC_SORT_BRAND";
public static final String VEC_RNN_SORT_BRAND = "VEC_RNN_SORT_BRAND";
public static final String VEC_W2V_SORT_BRAND = "VEC_W2V_SORT_BRAND";
public static final String CONFIG_SORT_BRAND = "CONFIG_SORT_BRAND";
public static final String RECALL_SKN_COUNT_SORT = "SORT";
public static final String RECALL_SKN_COUNT_BRAND = "BRAND";
... ...
package com.yoho.search.recall.config;
import com.alibaba.fastjson.JSON;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.dal.model.CsRecallConfigProduct;
import com.yoho.search.service.base.index.CsRecallConfigProductIndexBaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@Component
class RecallConfigProductService {
private static final Logger logger = LoggerFactory.getLogger(RecallConfigProductService.class);
@Autowired
private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService;
private Map<String, Map<Integer, RecallSknCount>> typePageConfigCache = new HashMap<>();
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
@PostConstruct
void init() {
schedule.scheduleAtFixedRate(() -> loadRecallSknCountConfig(), 0, 1, TimeUnit.MINUTES);
}
private void loadRecallSknCountConfig() {
try {
Map<String, Map<Integer, RecallSknCount>> tempTypePageConfigCache = new HashMap<>();
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
for (CsRecallConfigProduct productConfig : configList) {
String configType = productConfig.getConfigType();
int configTypeId = productConfig.getConfigTypeId();
int pageId = productConfig.getConfigPage();
String configKey = this.buildConfiKey(configType,configTypeId);
int configStatus = productConfig.getConfigStatus();
if(configStatus==1){
this.addElement(configKey,pageId,this.genProductCountConfig(productConfig),tempTypePageConfigCache);
}
}
typePageConfigCache = tempTypePageConfigCache;
System.out.println(JSON.toJSONString(typePageConfigCache));
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
private String buildConfiKey(String configType, int configTypeId) {
if (configType.equalsIgnoreCase(RecallConfigConstants.RECALL_SKN_COUNT_SORT)) {
return this.buildSortCacheKey(configTypeId);
} else if (configType.equalsIgnoreCase(RecallConfigConstants.RECALL_SKN_COUNT_BRAND)) {
return this.buildBrandCacheKey(configTypeId);
} else {
return this.buildSortBrandCacheKey(configType, new SortBrand());
}
}
private String buildSortCacheKey(int middleSortId) {
return RecallConfigConstants.RECALL_SKN_COUNT_SORT + "_" + middleSortId;
}
private String buildBrandCacheKey(int brandId) {
return RecallConfigConstants.RECALL_SKN_COUNT_BRAND + "_" + brandId;
}
private String buildSortBrandCacheKey(String sortBrandType, SortBrand sortBrand) {
return sortBrandType + "_" + sortBrand.key();
}
private void addElement(String configKey, int pageId, RecallSknCount recallSknCount, Map<String, Map<Integer, RecallSknCount>> map) {
if (!map.containsKey(configKey)) {
map.put(configKey, new HashMap<>());
}
map.get(configKey).put(pageId, recallSknCount);
}
private RecallSknCount genProductCountConfig(CsRecallConfigProduct configProduct) {
int newShelve = configProduct.getNewShelve();
int promotion = configProduct.getPromotion();
int reducePrice = configProduct.getReducePrice();
int ctrValue = configProduct.getCtrValue();
int heatValue = configProduct.getHeatValue();
int random = configProduct.getRandom();
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
}
private RecallSknCount genProductCountConfig(int newShelve, int promotion, int reducePrice, int ctrValue, int heatValue, int random) {
RecallSknCount recallSknCount = new RecallSknCount();
recallSknCount.setNewShelve(newShelve);
recallSknCount.setPromotion(promotion);
recallSknCount.setReducePrice(reducePrice);
recallSknCount.setCtrValue(ctrValue);
recallSknCount.setHeatValue(heatValue);
recallSknCount.setRandom(random);
return recallSknCount;
}
private RecallSknCount genProductCountConfigByCompare(RecallSknCount recallSknCount1, RecallSknCount recallSknCount2) {
int newShelve = Math.min(recallSknCount1.getNewShelve(), recallSknCount2.getNewShelve());
int promotion = Math.min(recallSknCount1.getPromotion(), recallSknCount2.getPromotion());
int reducePrice = Math.min(recallSknCount1.getReducePrice(), recallSknCount2.getReducePrice());
int ctrValue = Math.min(recallSknCount1.getCtrValue(), recallSknCount2.getCtrValue());
int heatValue = Math.min(recallSknCount1.getHeatValue(), recallSknCount2.getHeatValue());
int random = Math.min(recallSknCount1.getHeatValue(), recallSknCount2.getHeatValue());
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
}
/**
* 按页面+品类+品牌获取商品的召回数量
*
* @param pageId
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, String sortBrandType, SortBrand sortBrand) {
RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort());
RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId());
if (sortConfig != null && sortConfig != null) {
return genProductCountConfigByCompare(sortConfig, brandConfig);
}
if (sortConfig != null) {
return sortConfig;
}
if (brandConfig != null) {
return brandConfig;
}
RecallSknCount pageConfig = this.queryConfigByPage(pageId, sortBrandType, sortBrand);
if (pageConfig != null) {
return pageConfig;
}
pageConfig = this.queryConfigByPage(pageId, sortBrandType, new SortBrand());//使用默认的值替代
if (pageConfig != null) {
return pageConfig;
}
return genProductCountConfig(6, 3, 6, 6, 6, 0);
}
/**
* 查询中分类在页面上的召回配置,没有则取pageId=0的数据
* @param pageId
* @param middleSortId
* @return
*/
private RecallSknCount queryConfigBySort(int pageId, int middleSortId) {
String sortKey = this.buildSortCacheKey(middleSortId);
return this.getRecallSknCount(sortKey, pageId);
}
/**
* 查询品牌在页面上的召回配置,没有则取pageId=0的数据
* @param pageId
* @param brandId
* @return
*/
private RecallSknCount queryConfigByBrand(int pageId, int brandId) {
String brandKey = this.buildBrandCacheKey(brandId);
return this.getRecallSknCount(brandKey, pageId);
}
/**
* 查询【品类*品牌】在页面上的召回配置,没有则取pageId=0的数据
* @param pageId
* @param sortBrandType
* @param sortBrand
* @return
*/
private RecallSknCount queryConfigByPage(int pageId, String sortBrandType, SortBrand sortBrand) {
String sortBrandKey = this.buildSortBrandCacheKey(sortBrandType, sortBrand);
return this.getRecallSknCount(sortBrandKey, pageId);
}
private RecallSknCount getRecallSknCount(String key, int pageId) {
Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key);
if (pageConfig == null) {
return null;
}
RecallSknCount sknCount = pageConfig.get(pageId);
if (sknCount == null) {
sknCount = pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
}
return sknCount;
}
}
... ...
package com.yoho.search.recall.config;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.models.personal.PagePersonalFactor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.applet.Main;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@Service
public class RecallConfigService {
@Autowired
private RecallConfigServiceProduct recallConfigServiceProduct;
private RecallConfigProductService recallConfigProductService;
@Autowired
private RecallConfigCommonService recallConfigCommonService;
@Autowired
private RecallConfigServiceCommon recallConfigServiceCommon;
private RecallConfigSortBrandService recallConfigSortBrandService;
private static int legallValue(int value, int min, int max) {
value = Math.min(value, max);
... ... @@ -21,39 +29,6 @@ public class RecallConfigService {
}
/**
* 获取推荐的品类品牌的配置
*
* @param pageId
* @return
*/
public int getRecSortBrandCount(int pageId) {
int value = recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.REC_S_B_COUNT, 12);
return this.legallValue(value, 0, 30);
}
/**
* 获取W2v预测的品类品牌的数量
*
* @param pageId
* @return
*/
public int getVectorW2vSortBrandCount(int pageId) {
int value = recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.VEC_W2V_S_B_COUNT, 12);
return this.legallValue(value, 0, 30);
}
/**
* 获取RNN预测的品类品牌的数量
*
* @param pageId
* @return
*/
public int getVectorRNNSortBrandCount(int pageId) {
int value = recallConfigServiceCommon.queryConfigSize(pageId, RecallConfigConstants.VEC_RNN_S_B_COUNT, 0);
return this.legallValue(value, 0, 30);
}
/**
* 获取某些策略的召回数量
*
* @param pageId
... ... @@ -62,7 +37,7 @@ public class RecallConfigService {
*/
public int queryStrategyConfigSize(int pageId, StrategyEnum strategyEnum) {
String configKey = getStrategyConfigKey(strategyEnum);
int value = recallConfigServiceCommon.queryConfigSize(pageId, configKey, 0);
int value = recallConfigCommonService.queryConfigSize(pageId, configKey, 0);
return this.legallValue(value, 0, 100);
}
... ... @@ -75,7 +50,7 @@ public class RecallConfigService {
*/
public int queryStrategyConfigInterval(int pageId, StrategyEnum strategyEnum) {
String configKey = getStrategyConfigKey(strategyEnum);
int interval = recallConfigServiceCommon.queryConfigInterval(pageId, configKey, 10);
int interval = recallConfigCommonService.queryConfigInterval(pageId, configKey, 10);
return this.legallValue(interval, 2, 40);
}
... ... @@ -99,15 +74,27 @@ public class RecallConfigService {
}
/**
* 获取品类品牌的召回数量
* 获取推荐的【品类*品牌】的数量
*
* @param pageId
* @return
*/
public int querySortBrandConfigCount(int pageId, SortBrandType sortBrandType, int defaultSize) {
String sortBrandConfigKey = this.getSortBrandConfigKey(sortBrandType);
int value = recallConfigCommonService.queryConfigSize(pageId, sortBrandConfigKey, defaultSize);
return this.legallValue(value, 0, 30);
}
/**
* 获取【品类*品牌】下的的商品的召回数量
*
* @param pageId
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
String sortBrandTypeKey = this.getStrategyConfiKey(sortBrandType);
RecallSknCount recallSknCount = recallConfigServiceProduct.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand);
String sortBrandConfigKey = this.getSortBrandConfigKey(sortBrandType);
RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandConfigKey, sortBrand);
if (recallSknCount == null) {
return null;
}
... ... @@ -120,7 +107,7 @@ public class RecallConfigService {
return recallSknCount;
}
private String getStrategyConfiKey(SortBrandType sortBrandType) {
private String getSortBrandConfigKey(SortBrandType sortBrandType) {
if (sortBrandType.equals(SortBrandType.REC_SORT_BRAND)) {
return RecallConfigConstants.REC_SORT_BRAND;
}
... ... @@ -130,11 +117,27 @@ public class RecallConfigService {
if (sortBrandType.equals(SortBrandType.VEC_W2V_SORT_BRAND)) {
return RecallConfigConstants.VEC_W2V_SORT_BRAND;
}
if (sortBrandType.equals(SortBrandType.CONFIG_SORT_BRAND)) {
return RecallConfigConstants.CONFIG_SORT_BRAND;
}
return null;
}
/**
* 随机获取configSortBrandCount数量
* @param pageFactor
* @param filterSortBrandKeys
* @param configSortBrandCount
* @return
*/
public List<SortBrand> queryConfigSortBrandList(PagePersonalFactor pageFactor, Set<String> filterSortBrandKeys, int configSortBrandCount) {
List<SortBrand> pageConfigSortBrands = recallConfigSortBrandService.queryConfigSortBrand(pageFactor,filterSortBrandKeys);
Collections.shuffle(pageConfigSortBrands);
return CollectionUtils.safeSubList(pageConfigSortBrands,0,configSortBrandCount);
}
public static void main(String[] args) {
System.out.println(legallValue(-1,0,30));
System.out.println(legallValue(-1, 0, 30));
}
... ...
package com.yoho.search.recall.config;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.models.personal.PagePersonalFactor;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
class RecallConfigSortBrandService {
private Map<String,SortBrand> allConfigSortBrand = new HashMap<>();
public List<SortBrand> queryConfigSortBrand(PagePersonalFactor pageFactor, Set<String> filterSortBrandKeys) {
return new ArrayList<>();
//pageFactor.getSortBrandList();
}
}
... ...
... ... @@ -15,6 +15,7 @@ public class UserPersonalFactor {
private List<SortBrand> realTimeSortBrandList;
private List<SortBrand> vectorRnnSortBrandList;
private List<SortBrand> vectorW2vSortBrandList;
private List<SortBrand> configSortBrandList;
public UserPersonalFactor() {
this.recommendSknList = new ArrayList<>();
... ... @@ -24,9 +25,10 @@ public class UserPersonalFactor {
this.realTimeSortBrandList = new ArrayList<>();
this.vectorRnnSortBrandList = new ArrayList<>();
this.vectorW2vSortBrandList = new ArrayList<>();
this.configSortBrandList = new ArrayList<>();
}
public UserPersonalFactor(List<Integer> recommendSknList, List<Integer> realTimeSimilarSknList, List<SortPriceAreas> sortPriceAreasList, List<SortBrand> realTimeSortBrandList, List<SortBrand> vectorRnnSortBrandList, List<SortBrand> vectorW2vSortBrandList) {
public UserPersonalFactor(List<Integer> recommendSknList, List<Integer> realTimeSimilarSknList, List<SortPriceAreas> sortPriceAreasList, List<SortBrand> realTimeSortBrandList, List<SortBrand> vectorRnnSortBrandList, List<SortBrand> vectorW2vSortBrandList,List<SortBrand> configSortBrandList) {
this.recommendSknList = recommendSknList;
this.realTimeSimilarSknList = realTimeSimilarSknList;
this.sortPriceAreasList = sortPriceAreasList;
... ... @@ -34,6 +36,7 @@ public class UserPersonalFactor {
this.realTimeSortBrandList = realTimeSortBrandList;
this.vectorRnnSortBrandList = vectorRnnSortBrandList;
this.vectorW2vSortBrandList = vectorW2vSortBrandList;
this.configSortBrandList = configSortBrandList;
}
public List<Integer> getRecommendSknList() {
... ... @@ -60,4 +63,7 @@ public class UserPersonalFactor {
return vectorW2vSortBrandList;
}
public List<SortBrand> getConfigSortBrandList() {
return configSortBrandList;
}
}
... ...