Authored by hugufei

召回数量代码优化

... ... @@ -40,7 +40,7 @@ public class SortBrandRecallRequestBuilder {
// 3)、参数构造
for (SortBrand sortBrand : sortBrands) {
RecallSknCount recallSknCount = recallConfigService.queryRecallSknCount(pageId, sortBrand);
RecallSknCount recallSknCount = recallConfigService.queryRecallSknCount(pageId, sortBrandType,sortBrand);
if (recallSknCount == null) {
continue;
}
... ...
package com.yoho.search.recall.beans.strategy;
public enum SortBrandType {
/**
* 品牌品类类型,字段不能该,取召回数量的时后要用到
*/
public enum SortBrandType {
REC_SORT_BRAND,
VEC_RNN_SORT_BRAND,
VEC_W2V_SORT_BRAND
... ...
... ... @@ -6,10 +6,6 @@ public class RecallConfigConstants {
public static final int DEFAULT_PAGE_ID = 0;
public static final int SKN_COUNT_CONFIG_PAGE = 1;
public static final int SKN_COUNT_CONFIG_SORT = 2;
public static final int SKN_COUNT_CONFIG_BRAND = 3;
public static final String DIRECT_TRAIN = "DIRECT_TRAIN";
public static final String REC_SKN = "REC_SKN";
... ... @@ -20,11 +16,10 @@ public class RecallConfigConstants {
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 RNN_SORT_BRAND = "RNN_SORT_BRAND";
public static final String W2V_SORT_BRAND = "W2V_SORT_BRAND";
public static final String SORT = "SORT";
public static final String BRAND = "SORT";
public static final String RECALL_SKN_COUNT_REC_SORT_BRAND = "REC_SORT_BRAND";
public static final String RECALL_SKN_COUNT_RNN_SORT_BRAND = "VEC_RNN_SORT_BRAND";
public static final String RECALL_SKN_COUNT_W2V_SORT_BRAND = "VEC_W2V_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.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -19,8 +20,8 @@ public class RecallConfigService {
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, SortBrand sortBrand) {
return recallConfigServiceProduct.queryRecallSknCount(pageId, sortBrand);
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType,SortBrand sortBrand) {
return recallConfigServiceProduct.queryRecallSknCount(pageId,sortBrandType,sortBrand);
}
/**
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.recall.config;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.dal.model.CsRecallConfigProduct;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.service.base.index.CsRecallConfigProductIndexBaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -24,7 +25,7 @@ class RecallConfigServiceProduct {
@Autowired
private CsRecallConfigProductIndexBaseService csRecallConfigProductIndexBaseService;
private Map<Integer, Map<Integer, RecallSknCount>> configCache = new HashMap<>();
private Map<String, Map<Integer, RecallSknCount>> typePageConfigCache = new HashMap<>();
private ScheduledExecutorService schedule = Executors.newSingleThreadScheduledExecutor();
... ... @@ -35,24 +36,24 @@ class RecallConfigServiceProduct {
private void loadRecallSknCountConfig() {
try {
Map<Integer, Map<Integer, RecallSknCount>> tempConfig = new HashMap<>();
Map<String, Map<Integer, RecallSknCount>> tempTypePageConfigCache = new HashMap<>();
List<CsRecallConfigProduct> configList = csRecallConfigProductIndexBaseService.queryAll();
for (CsRecallConfigProduct productConfig : configList) {
//1、按配置类型获取配置
int configType = productConfig.getConfigType();
Map<Integer, RecallSknCount> typeConfig = tempConfig.get(configType);
if (typeConfig == null) {
typeConfig = new HashMap<>();
tempConfig.put(configType, typeConfig);
}
//2、页面类型的配置,不判断状态,其他类型的需要判断状态
int configTypeId = productConfig.getConfigTypeId();
int configStatus = productConfig.getConfigStatus();
if (configType == RecallConfigConstants.SKN_COUNT_CONFIG_PAGE || configStatus == 1) {
typeConfig.put(configTypeId, this.genProductCountConfig(productConfig));
}
// //1、按配置类型获取配置
// int configType = productConfig.getConfigType();
// Map<Integer, RecallSknCount> typeConfig = tempConfig.get(configType);
// if (typeConfig == null) {
// typeConfig = new HashMap<>();
// tempConfig.put(configType, typeConfig);
// }
// //2、页面类型的配置,不判断状态,其他类型的需要判断状态
// int configTypeId = productConfig.getConfigTypeId();
// int configStatus = productConfig.getConfigStatus();
// if (configType == RecallConfigConstants.SKN_COUNT_CONFIG_PAGE || configStatus == 1) {
// typeConfig.put(configTypeId, this.genProductCountConfig(productConfig));
// }
}
configCache = tempConfig;
typePageConfigCache = tempTypePageConfigCache;
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
... ... @@ -89,33 +90,44 @@ class RecallConfigServiceProduct {
return genProductCountConfig(newShelve, promotion, reducePrice, ctrValue, heatValue, random);
}
private RecallSknCount queryConfigBySort(int middleSortId) {
Map<Integer, RecallSknCount> sortConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_SORT);
if (sortConfig == null) {
return null;
}
return sortConfig.get(middleSortId);
private String buildSortCacheKey(int middleSortId) {
return RecallConfigConstants.RECALL_SKN_COUNT_SORT + "_" + middleSortId;
}
private RecallSknCount queryConfigByBrand(int brandId) {
Map<Integer, RecallSknCount> brandConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_BRAND);
if (brandConfig == null) {
return null;
}
return brandConfig.get(brandId);
private String buildBrandCacheKey(int brandId) {
return RecallConfigConstants.RECALL_SKN_COUNT_BRAND + "_" + brandId;
}
private RecallSknCount queryConfigByPage(int pageId) {
Map<Integer, RecallSknCount> pageConfig = configCache.get(RecallConfigConstants.SKN_COUNT_CONFIG_PAGE);
private String buildSortBrandCacheKey(SortBrandType sortBrandType, SortBrand sortBrand) {
return sortBrandType.name() + "_" + sortBrand.key();
}
private RecallSknCount getRecallSknCount(String key, int pageId) {
Map<Integer, RecallSknCount> pageConfig = typePageConfigCache.get(key);
if (pageConfig == null) {
return null;
}
RecallSknCount config = pageConfig.get(pageId);
if (config == null) {
return pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
} else {
return config;
RecallSknCount sknCount = pageConfig.get(pageId);
if (sknCount == null) {
sknCount = pageConfig.get(RecallConfigConstants.DEFAULT_PAGE_ID);
}
return sknCount;
}
private RecallSknCount queryConfigBySort(int pageId, int middleSortId) {
String sortKey = this.buildSortCacheKey(middleSortId);
return this.getRecallSknCount(sortKey, pageId);
}
private RecallSknCount queryConfigByBrand(int pageId, int brandId) {
String brandKey = this.buildBrandCacheKey(brandId);
return this.getRecallSknCount(brandKey, pageId);
}
private RecallSknCount queryConfigByPage(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
String sortBrandKey = this.buildSortBrandCacheKey(sortBrandType, sortBrand);
return this.getRecallSknCount(sortBrandKey, pageId);
}
/**
... ... @@ -125,9 +137,9 @@ class RecallConfigServiceProduct {
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, SortBrand sortBrand) {
RecallSknCount sortConfig = this.queryConfigBySort(sortBrand.getMisort());
RecallSknCount brandConfig = this.queryConfigByBrand(sortBrand.getBrandId());
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType 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);
}
... ... @@ -137,7 +149,11 @@ class RecallConfigServiceProduct {
if (brandConfig != null) {
return brandConfig;
}
RecallSknCount pageConfig = this.queryConfigByPage(pageId);
RecallSknCount pageConfig = this.queryConfigByPage(pageId, sortBrandType, sortBrand);
if (pageConfig != null) {
return pageConfig;
}
pageConfig = this.queryConfigByPage(pageId, sortBrandType, new SortBrand());//使用默认的值替代
if (pageConfig != null) {
return pageConfig;
}
... ...