Authored by hugufei

Merge branch 'recall_config' into 0510

... ... @@ -5,7 +5,7 @@ import com.yoho.search.recall.beans.strategy.IStrategy;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.impls.*;
import com.yoho.search.recall.config.RecallConfigService;
import com.yoho.search.recall.config.RecallSknCount;
import com.yoho.search.recall.config.ConfigSknCount;
import com.yoho.search.recall.models.common.ParamQueryFilter;
import com.yoho.search.recall.models.req.RecallRequest;
import com.yoho.search.recall.models.req.UserRecallRequest;
... ... @@ -40,33 +40,33 @@ public class SortBrandRecallRequestBuilder {
// 3)、参数构造
for (SortBrand sortBrand : sortBrands) {
RecallSknCount recallSknCount = recallConfigService.queryRecallSknCount(pageId, sortBrandType,sortBrand);
if (recallSknCount == null) {
ConfigSknCount configSknCount = recallConfigService.queryRecallSknCount(pageId, sortBrandType,sortBrand);
if (configSknCount == null) {
continue;
}
// 1) 新品
if (recallSknCount.getNewShelve() > 0) {
requests.add(this.buildSortBrandNewShelveRequest(paramQueryFilter, sortBrand, recallSknCount.getNewShelve(), sortBrandType));
if (configSknCount.getNewShelve() > 0) {
requests.add(this.buildSortBrandNewShelveRequest(paramQueryFilter, sortBrand, configSknCount.getNewShelve(), sortBrandType));
}
// 2) 新开促销
if (recallSknCount.getPromotion() > 0) {
requests.add(this.buildSortBrandPromotionRequest(paramQueryFilter, sortBrand, recallSknCount.getPromotion(), sortBrandType));
if (configSknCount.getPromotion() > 0) {
requests.add(this.buildSortBrandPromotionRequest(paramQueryFilter, sortBrand, configSknCount.getPromotion(), sortBrandType));
}
// 3) 新降价
if (recallSknCount.getReducePrice() > 0) {
requests.add(this.buildSortBrandReducePriceRequest(paramQueryFilter, sortBrand, recallSknCount.getReducePrice(), sortBrandType));
if (configSknCount.getReducePrice() > 0) {
requests.add(this.buildSortBrandReducePriceRequest(paramQueryFilter, sortBrand, configSknCount.getReducePrice(), sortBrandType));
}
// 4) 转化率
if (recallSknCount.getCtrValue() > 0) {
requests.add(this.buildSortBrandCtrValueRequest(paramQueryFilter, sortBrand, recallSknCount.getCtrValue(), sortBrandType));
if (configSknCount.getCtrValue() > 0) {
requests.add(this.buildSortBrandCtrValueRequest(paramQueryFilter, sortBrand, configSknCount.getCtrValue(), sortBrandType));
}
// 5) 人气
if (recallSknCount.getHeatValue() > 0) {
requests.add(this.buildSortBrandHeatValueRequest(paramQueryFilter, sortBrand, recallSknCount.getHeatValue(), sortBrandType));
if (configSknCount.getHeatValue() > 0) {
requests.add(this.buildSortBrandHeatValueRequest(paramQueryFilter, sortBrand, configSknCount.getHeatValue(), sortBrandType));
}
// 6) 随机
if (recallSknCount.getRandom() > 0) {
requests.add(this.buildSortBrandRandomRequest(paramQueryFilter, sortBrand, recallSknCount.getRandom(), sortBrandType));
if (configSknCount.getRandom() > 0) {
requests.add(this.buildSortBrandRandomRequest(paramQueryFilter, sortBrand, configSknCount.getRandom(), sortBrandType));
}
}
return requests;
... ...
package com.yoho.search.recall.config;
public class RecallSizeInterval {
public class ConfigSizeInterval {
private int size;
private int interval;
public RecallSizeInterval(int size, int interval) {
public ConfigSizeInterval(int size, int interval) {
this.size = size;
this.interval = interval;
}
... ...
package com.yoho.search.recall.config;
public class RecallSknCount {
public class ConfigSknCount {
private int newShelve;
private int promotion;
... ...
... ... @@ -27,7 +27,7 @@ class RecallConfigCommonService {
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
private Map<String, Map<Integer, RecallSizeInterval>> typePageConfigCache = new HashMap<>();
private Map<String, Map<Integer, ConfigSizeInterval>> typePageConfigCache = new HashMap<>();
@PostConstruct
void init() {
... ... @@ -37,16 +37,16 @@ class RecallConfigCommonService {
private void loadConfig() {
try {
List<CsRecallConfigCommon> configList = csRecallConfigCommonIndexBaseService.queryAll();
Map<String, Map<Integer, RecallSizeInterval>> temp = new HashMap<>();
Map<String, Map<Integer, ConfigSizeInterval>> temp = new HashMap<>();
for (CsRecallConfigCommon csRecallConfigCommon : configList) {
Map<Integer, RecallSizeInterval> pageConfigs = temp.get(csRecallConfigCommon.getConfigType());
Map<Integer, ConfigSizeInterval> 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));
pageConfigs.put(csRecallConfigCommon.getConfigPage(), new ConfigSizeInterval(size, interval));
}
typePageConfigCache = temp;
System.out.println(JSON.toJSONString(typePageConfigCache));
... ... @@ -55,12 +55,12 @@ class RecallConfigCommonService {
}
}
private RecallSizeInterval queryCommonConfig(String configKey, int configPage) {
Map<Integer, RecallSizeInterval> pageConfigMap = typePageConfigCache.get(configKey);
private ConfigSizeInterval queryCommonConfig(String configKey, int configPage) {
Map<Integer, ConfigSizeInterval> pageConfigMap = typePageConfigCache.get(configKey);
if (pageConfigMap == null) {
return null;
}
RecallSizeInterval pageConfig = pageConfigMap.get(configPage);
ConfigSizeInterval pageConfig = pageConfigMap.get(configPage);
if (pageConfig == null) {
pageConfig = pageConfigMap.get(RecallConfigConstants.DEFAULT_PAGE_ID);
}
... ... @@ -83,7 +83,7 @@ class RecallConfigCommonService {
if (StringUtils.isBlank(configKey)) {
return defaultSize;
}
RecallSizeInterval config = queryCommonConfig(configKey, pageId);
ConfigSizeInterval config = queryCommonConfig(configKey, pageId);
return config == null ? defaultSize : config.getSize();
}
... ... @@ -99,7 +99,7 @@ class RecallConfigCommonService {
if (StringUtils.isBlank(configKey)) {
return defaultInterval;
}
RecallSizeInterval config = queryCommonConfig(configKey, pageId);
ConfigSizeInterval config = queryCommonConfig(configKey, pageId);
return config == null ? defaultInterval : config.getInterval();
}
... ...
... ... @@ -6,7 +6,6 @@ public class RecallConfigConstants {
public static final int DEFAULT_PAGE_ID = 0;
public static final String DIRECT_TRAIN = "DIRECT_TRAIN";
public static final String REC_SKN = "REC_SKN";
public static final String RT_SIM_SKN = "RT_SIM_SKN";
... ...
... ... @@ -25,7 +25,7 @@ class RecallConfigProductService {
@Autowired
private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService;
private Map<String, Map<Integer, RecallSknCount>> typePageConfigCache = new HashMap<>();
private Map<String, Map<Integer, ConfigSknCount>> typePageConfigCache = new HashMap<>();
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
... ... @@ -36,7 +36,7 @@ class RecallConfigProductService {
private void loadRecallSknCountConfig() {
try {
Map<String, Map<Integer, RecallSknCount>> tempTypePageConfigCache = new HashMap<>();
Map<String, Map<Integer, ConfigSknCount>> tempTypePageConfigCache = new HashMap<>();
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
for (CsRecallConfigProduct productConfig : configList) {
String configType = productConfig.getConfigType();
... ... @@ -71,14 +71,14 @@ class RecallConfigProductService {
return type + "_" + cacheKey;
}
private void addElement(String configKey, int pageId, RecallSknCount recallSknCount, Map<String, Map<Integer, RecallSknCount>> map) {
private void addElement(String configKey, int pageId, ConfigSknCount configSknCount, Map<String, Map<Integer, ConfigSknCount>> map) {
if (!map.containsKey(configKey)) {
map.put(configKey, new HashMap<>());
}
map.get(configKey).put(pageId, recallSknCount);
map.get(configKey).put(pageId, configSknCount);
}
private RecallSknCount genProductCountConfig(CsRecallConfigProduct configProduct) {
private ConfigSknCount genProductCountConfig(CsRecallConfigProduct configProduct) {
int newShelve = configProduct.getNewShelve();
int promotion = configProduct.getPromotion();
int reducePrice = configProduct.getReducePrice();
... ... @@ -88,24 +88,24 @@ class RecallConfigProductService {
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 ConfigSknCount genProductCountConfig(int newShelve, int promotion, int reducePrice, int ctrValue, int heatValue, int random) {
ConfigSknCount configSknCount = new ConfigSknCount();
configSknCount.setNewShelve(newShelve);
configSknCount.setPromotion(promotion);
configSknCount.setReducePrice(reducePrice);
configSknCount.setCtrValue(ctrValue);
configSknCount.setHeatValue(heatValue);
configSknCount.setRandom(random);
return configSknCount;
}
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());
private ConfigSknCount genProductCountConfigByCompare(ConfigSknCount configSknCount1, ConfigSknCount configSknCount2) {
int newShelve = Math.min(configSknCount1.getNewShelve(), configSknCount2.getNewShelve());
int promotion = Math.min(configSknCount1.getPromotion(), configSknCount2.getPromotion());
int reducePrice = Math.min(configSknCount1.getReducePrice(), configSknCount2.getReducePrice());
int ctrValue = Math.min(configSknCount1.getCtrValue(), configSknCount2.getCtrValue());
int heatValue = Math.min(configSknCount1.getHeatValue(), configSknCount2.getHeatValue());
int random = Math.min(configSknCount1.getHeatValue(), configSknCount2.getHeatValue());
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
}
... ... @@ -116,15 +116,15 @@ class RecallConfigProductService {
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, String sortBrandTypeKey, SortBrand sortBrand) {
public ConfigSknCount queryRecallSknCount(int pageId, String sortBrandTypeKey, SortBrand sortBrand) {
//1、先取【配置的品牌*品类】的配置
RecallSknCount recallSknCount = this.queryConfigBySortBrandWithType(pageId,RecallConfigConstants.SORT_BRAND, sortBrand);
if(recallSknCount!=null){
return recallSknCount;
ConfigSknCount configSknCount = this.queryConfigBySortBrandWithType(pageId,RecallConfigConstants.SORT_BRAND, sortBrand);
if(configSknCount !=null){
return configSknCount;
}
//2、再取【配置的品牌或品类】配置
RecallSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort());
RecallSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId());
ConfigSknCount sortConfig = this.queryConfigBySort(pageId, sortBrand.getMisort());
ConfigSknCount brandConfig = this.queryConfigByBrand(pageId, sortBrand.getBrandId());
if (sortConfig != null && brandConfig != null) {
return genProductCountConfigByCompare(sortConfig, brandConfig);
}
... ... @@ -135,7 +135,7 @@ class RecallConfigProductService {
return brandConfig;
}
//3、再取当前类型的【品牌*品类】配置-没有则取默认的【0_0的数据】
RecallSknCount pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, sortBrand);
ConfigSknCount pageConfig = this.queryConfigBySortBrandWithType(pageId, sortBrandTypeKey, sortBrand);
if (pageConfig != null) {
return pageConfig;
}
... ... @@ -153,7 +153,7 @@ class RecallConfigProductService {
* @param sortBrand
* @return
*/
private RecallSknCount queryConfigBySortBrandWithType(int pageId, String sortBrandType, SortBrand sortBrand) {
private ConfigSknCount queryConfigBySortBrandWithType(int pageId, String sortBrandType, SortBrand sortBrand) {
String sortBrandKey = this.buildCacheKey(sortBrandType, sortBrand.key());
return this.getRecallSknCount(sortBrandKey, pageId);
}
... ... @@ -164,7 +164,7 @@ class RecallConfigProductService {
* @param middleSortId
* @return
*/
private RecallSknCount queryConfigBySort(int pageId, int middleSortId) {
private ConfigSknCount queryConfigBySort(int pageId, int middleSortId) {
String sortKey = this.buildCacheKey(RecallConfigConstants.SORT,String.valueOf(middleSortId));
return this.getRecallSknCount(sortKey, pageId);
}
... ... @@ -175,18 +175,18 @@ class RecallConfigProductService {
* @param brandId
* @return
*/
private RecallSknCount queryConfigByBrand(int pageId, int brandId) {
private ConfigSknCount queryConfigByBrand(int pageId, int brandId) {
String brandKey = this.buildCacheKey(RecallConfigConstants.BRAND,String.valueOf(brandId));
return this.getRecallSknCount(brandKey, pageId);
}
private RecallSknCount getRecallSknCount(String key, int pageId) {
Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key);
private ConfigSknCount getRecallSknCount(String key, int pageId) {
Map<Integer, ConfigSknCount> pageConfig = typePageConfigCache.get(key);
if (pageConfig == null) {
return null;
}
RecallSknCount sknCount = pageConfig.get(pageId);
ConfigSknCount sknCount = pageConfig.get(pageId);
if (sknCount == null) {
sknCount = pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
}
... ...
... ... @@ -101,21 +101,21 @@ public class RecallConfigService {
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
public ConfigSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
String sortBrandTypeKey = this.getSortBrandConfigKey(sortBrandType);
RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand);
if (recallSknCount == null) {
ConfigSknCount configSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandTypeKey, sortBrand);
if (configSknCount == null) {
RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],sortBrand is[{}], RecallSknCount is[{}]", pageId, sortBrand.key(), sortBrandType.name(), "null");
return null;
}
recallSknCount.setNewShelve(this.legallValue(recallSknCount.getNewShelve(), 0, 20));
recallSknCount.setPromotion(this.legallValue(recallSknCount.getPromotion(), 0, 20));
recallSknCount.setCtrValue(this.legallValue(recallSknCount.getCtrValue(), 0, 20));
recallSknCount.setHeatValue(this.legallValue(recallSknCount.getHeatValue(), 0, 20));
recallSknCount.setReducePrice(this.legallValue(recallSknCount.getReducePrice(), 0, 20));
recallSknCount.setRandom(this.legallValue(recallSknCount.getRandom(), 0, 20));
RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],sortBrand is[{}], RecallSknCount is[{}]", pageId, sortBrand.key(), sortBrandType.name(), JSON.toJSONString(recallSknCount));
return recallSknCount;
configSknCount.setNewShelve(this.legallValue(configSknCount.getNewShelve(), 0, 20));
configSknCount.setPromotion(this.legallValue(configSknCount.getPromotion(), 0, 20));
configSknCount.setCtrValue(this.legallValue(configSknCount.getCtrValue(), 0, 20));
configSknCount.setHeatValue(this.legallValue(configSknCount.getHeatValue(), 0, 20));
configSknCount.setReducePrice(this.legallValue(configSknCount.getReducePrice(), 0, 20));
configSknCount.setRandom(this.legallValue(configSknCount.getRandom(), 0, 20));
RECALL_LOGGER.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],sortBrand is[{}], RecallSknCount is[{}]", pageId, sortBrand.key(), sortBrandType.name(), JSON.toJSONString(configSknCount));
return configSknCount;
}
private String getSortBrandConfigKey(SortBrandType sortBrandType) {
... ...
package com.yoho.search.recall.config;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.dal.model.CsRecallConfigSortBrand;
import com.yoho.search.recall.models.personal.PagePersonalFactor;
import com.yoho.search.service.base.index.CsRecallConfigSortBrandIndexBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@Component
class RecallConfigSortBrandService {
@Autowired
private CsRecallConfigSortBrandIndexBaseService csRecallConfigSortBrandIndexBaseService;
private List<SortBrand> configSortBrands = new ArrayList<>();
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
@PostConstruct
void init() {
schedule.scheduleAtFixedRate(() -> loadConfigSortBrands(), 0, 1, TimeUnit.MINUTES);
}
private void loadConfigSortBrands(){
List<SortBrand> temp = new ArrayList<>();
List<CsRecallConfigSortBrand> csRecallConfigSortBrands = csRecallConfigSortBrandIndexBaseService.queryAll();
for (CsRecallConfigSortBrand csRecallConfigSortBrand:csRecallConfigSortBrands){
Integer misort = csRecallConfigSortBrand.getSortId();
List<Integer> brandIds = ConvertUtils.stringToIntList(csRecallConfigSortBrand.getBrandIds(),",");
for (Integer brandId:brandIds){
temp.add(new SortBrand(misort,brandId));
}
}
configSortBrands = temp;
}
/**
* 随机获取size个品类品牌
*
... ...
package com.yoho.search.service.base.index;
import com.alibaba.fastjson.JSON;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.dal.model.CsRecallConfigSortBrand;
import com.yoho.search.service.base.SearchCommonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service
public class CsRecallConfigSortBrandIndexBaseService {
@Autowired
private SearchCommonService searchCommonService;
public List<CsRecallConfigSortBrand> queryAll(){
SearchParam searchParam = new SearchParam();
searchParam.setOffset(0);
searchParam.setSize(10000);
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_CS_RECALL_CONFIG_SORT_BRAND, searchParam);
List<Map<String, Object>> results = searchResult.getResultList();
List<CsRecallConfigSortBrand> list = new ArrayList<>();
for (Map<String, Object> result : results) {
list.add(JSON.parseObject(JSON.toJSONString(result),CsRecallConfigSortBrand.class));
}
return list;
}
}
... ...