RecallCommonConfigService.java
3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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;
import java.util.Map;
@Component
public class RecallCommonConfigService {
private Map<String, Map<Integer, RecallCommonConfig>> configMap = new HashMap<>();
private RecallCommonConfig queryCommonConfig(int configPage, String configKey) {
Map<Integer, RecallCommonConfig> pageConfigMap = configMap.get(configKey);
if (pageConfigMap == null) {
return null;
}
RecallCommonConfig pageConfig = pageConfigMap.get(configPage);
if (pageConfig == null) {
pageConfig = pageConfigMap.get(0);
}
if (pageConfigMap == null) {
return null;
} else {
return pageConfig;
}
}
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;
}
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();
}
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();
}
/**
* 获取推荐的品类品牌的配置
*
* @param pageId
* @return
*/
public int getRecSortBrandCount(int pageId) {
RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.REC_S_B_COUNT);
if (recallCommonConfig != null) {
return recallCommonConfig.getSize();
}
return 12;
}
/**
* 获取预测的品类品牌的配置
*
* @param pageId
* @return
*/
public int getVectorW2vSortBrandCount(int pageId) {
RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.VEC_W2V_S_B_COUNT);
if (recallCommonConfig != null) {
return recallCommonConfig.getSize();
}
return 12;
}
/**
* 获取预测的品类品牌的配置
*
* @param pageId
* @return
*/
public int getVectorRNNSortBrandCount(int pageId) {
RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.VEC_RNN_S_B_COUNT);
if (recallCommonConfig != null) {
return recallCommonConfig.getSize();
}
return 12;
}
/**
* 获取预测的品类品牌的配置
*
* @param pageId
* @return
*/
public int getUserMaxRecallCount(int pageId) {
RecallCommonConfig recallCommonConfig = queryCommonConfig(pageId, RecallCommonConfigKeys.USER_MAX_RECALL_COUNT);
if (recallCommonConfig != null) {
return recallCommonConfig.getSize();
}
return 200;
}
}