1
|
package com.yoho.search.service.service.helper;
|
1
|
package com.yoho.search.service.service.helper;
|
2
|
|
2
|
|
|
|
3
|
+import java.util.ArrayList;
|
|
|
4
|
+import java.util.List;
|
3
|
import java.util.Map;
|
5
|
import java.util.Map;
|
4
|
|
6
|
|
5
|
import org.apache.commons.lang.StringUtils;
|
7
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -15,8 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
@@ -15,8 +17,10 @@ import org.springframework.beans.factory.annotation.Autowired; |
15
|
import org.springframework.stereotype.Component;
|
17
|
import org.springframework.stereotype.Component;
|
16
|
|
18
|
|
17
|
import com.yoho.search.service.personalized.PersonalVectorFeatureSearch;
|
19
|
import com.yoho.search.service.personalized.PersonalVectorFeatureSearch;
|
|
|
20
|
+import com.yoho.search.service.personalized.PersonalizedRedisService;
|
18
|
import com.yoho.search.service.service.SearchDynamicConfigService;
|
21
|
import com.yoho.search.service.service.SearchDynamicConfigService;
|
19
|
import com.yoho.search.service.utils.SearchRequestParams;
|
22
|
import com.yoho.search.service.utils.SearchRequestParams;
|
|
|
23
|
+import com.yoho.search.service.vo.PhysicalChannelScore;
|
20
|
|
24
|
|
21
|
@Component
|
25
|
@Component
|
22
|
public class FunctionScoreSearchHelper {
|
26
|
public class FunctionScoreSearchHelper {
|
|
@@ -27,6 +31,8 @@ public class FunctionScoreSearchHelper { |
|
@@ -27,6 +31,8 @@ public class FunctionScoreSearchHelper { |
27
|
private PersonalVectorFeatureSearch personalVectorFeatureSearch;
|
31
|
private PersonalVectorFeatureSearch personalVectorFeatureSearch;
|
28
|
@Autowired
|
32
|
@Autowired
|
29
|
private SearchDynamicConfigService dynamicConfig;
|
33
|
private SearchDynamicConfigService dynamicConfig;
|
|
|
34
|
+ @Autowired
|
|
|
35
|
+ private PersonalizedRedisService personalizedRedisService;
|
30
|
|
36
|
|
31
|
static float globalWeight = 0.50f;
|
37
|
static float globalWeight = 0.50f;
|
32
|
|
38
|
|
|
@@ -52,10 +58,9 @@ public class FunctionScoreSearchHelper { |
|
@@ -52,10 +58,9 @@ public class FunctionScoreSearchHelper { |
52
|
}
|
58
|
}
|
53
|
// 针对频道降分
|
59
|
// 针对频道降分
|
54
|
if (searchCommonHelper.isNeedDeScoreForChannel(paramMap)) {
|
60
|
if (searchCommonHelper.isNeedDeScoreForChannel(paramMap)) {
|
55
|
- QueryBuilder physicalChannelQueryBuilder = this.getPhysicalChannelQueryBuilder(paramMap);
|
|
|
56
|
- if (physicalChannelQueryBuilder != null) {
|
|
|
57
|
- float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();
|
|
|
58
|
- functionScoreQueryBuilder.add(physicalChannelQueryBuilder, ScoreFunctionBuilders.weightFactorFunction(physicalChannelWeight));
|
61
|
+ List<PhysicalChannelScore> physicalChannelScores = this.getPhysicalChannelQueryBuilder(paramMap);
|
|
|
62
|
+ for (PhysicalChannelScore physicalChannelScore : physicalChannelScores) {
|
|
|
63
|
+ functionScoreQueryBuilder.add(physicalChannelScore.getQueryBuilder(), ScoreFunctionBuilders.weightFactorFunction(physicalChannelScore.getWeight()));
|
59
|
}
|
64
|
}
|
60
|
}
|
65
|
}
|
61
|
functionScoreQueryBuilder.boostMode(CombineFunction.MULT);
|
66
|
functionScoreQueryBuilder.boostMode(CombineFunction.MULT);
|
|
@@ -75,39 +80,69 @@ public class FunctionScoreSearchHelper { |
|
@@ -75,39 +80,69 @@ public class FunctionScoreSearchHelper { |
75
|
return functionScoreQueryBuilder;
|
80
|
return functionScoreQueryBuilder;
|
76
|
}
|
81
|
}
|
77
|
|
82
|
|
78
|
- private QueryBuilder getPhysicalChannelQueryBuilder(Map<String, String> paramMap) {
|
83
|
+ /**
|
|
|
84
|
+ * 获取将要降分的性别权重
|
|
|
85
|
+ *
|
|
|
86
|
+ * @param uid
|
|
|
87
|
+ * @param baseScore
|
|
|
88
|
+ * @param descoreGender
|
|
|
89
|
+ * @return
|
|
|
90
|
+ */
|
|
|
91
|
+ public float getDescoreGenderWeight(String uid, float baseScore, String descoreGender) {
|
|
|
92
|
+ Map<String, Float> userGenderFloat = personalizedRedisService.getUserGenderFeature(uid);
|
|
|
93
|
+ Float userGenderWeight = userGenderFloat.get(descoreGender);
|
|
|
94
|
+ if (userGenderWeight == null) {
|
|
|
95
|
+ return baseScore;
|
|
|
96
|
+ }
|
|
|
97
|
+ return baseScore * (1 + userGenderWeight);
|
|
|
98
|
+ }
|
|
|
99
|
+
|
|
|
100
|
+ private List<PhysicalChannelScore> getPhysicalChannelQueryBuilder(Map<String, String> paramMap) {
|
|
|
101
|
+ float physicalChannelWeight = (float) dynamicConfig.getDeScorePhysicalChannelWeight();
|
|
|
102
|
+ String uid = paramMap.get("uid");
|
|
|
103
|
+
|
79
|
String physicalChannel = paramMap.get(SearchRequestParams.PHYSICAL_CHANNEL);
|
104
|
String physicalChannel = paramMap.get(SearchRequestParams.PHYSICAL_CHANNEL);
|
80
|
- BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
81
|
TermsQueryBuilder physicalChannelsTermsQueryBuilder = QueryBuilders.termsQuery("physicalChannels", physicalChannel);
|
105
|
TermsQueryBuilder physicalChannelsTermsQueryBuilder = QueryBuilders.termsQuery("physicalChannels", physicalChannel);
|
|
|
106
|
+
|
|
|
107
|
+ List<PhysicalChannelScore> results = new ArrayList<PhysicalChannelScore>();
|
|
|
108
|
+
|
82
|
// 潮童频道,对非潮童频道的或成人的商品降分
|
109
|
// 潮童频道,对非潮童频道的或成人的商品降分
|
83
|
if (physicalChannel.equals("3")) {
|
110
|
if (physicalChannel.equals("3")) {
|
|
|
111
|
+ BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
84
|
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
|
112
|
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
|
85
|
boolQueryBuilder.should(QueryBuilders.termsQuery("ageLevel", "1"));
|
113
|
boolQueryBuilder.should(QueryBuilders.termsQuery("ageLevel", "1"));
|
86
|
- return boolQueryBuilder;
|
114
|
+ results.add(new PhysicalChannelScore(boolQueryBuilder, physicalChannelWeight));
|
|
|
115
|
+ return results;
|
87
|
}
|
116
|
}
|
88
|
// 创意生活频道,对非创意生活频道的商品降分
|
117
|
// 创意生活频道,对非创意生活频道的商品降分
|
89
|
if (physicalChannel.equals("4")) {
|
118
|
if (physicalChannel.equals("4")) {
|
90
|
- return boolQueryBuilder.mustNot(physicalChannelsTermsQueryBuilder);
|
119
|
+ BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder);
|
|
|
120
|
+ results.add(new PhysicalChannelScore(boolQueryBuilder, physicalChannelWeight));
|
|
|
121
|
+ return results;
|
91
|
}
|
122
|
}
|
92
|
-
|
|
|
93
|
// 如果用户在男女频道的意图中包含了明显的性别意图,则只针对频道降分
|
123
|
// 如果用户在男女频道的意图中包含了明显的性别意图,则只针对频道降分
|
94
|
if (isUserSearchContainGender(paramMap)) {
|
124
|
if (isUserSearchContainGender(paramMap)) {
|
95
|
- return boolQueryBuilder.mustNot(physicalChannelsTermsQueryBuilder);
|
125
|
+ BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder);
|
|
|
126
|
+ results.add(new PhysicalChannelScore(boolQueryBuilder, physicalChannelWeight));
|
|
|
127
|
+ return results;
|
96
|
}
|
128
|
}
|
97
|
-
|
|
|
98
|
// 男生频道,对非男生频道的商品或者性别女的降分
|
129
|
// 男生频道,对非男生频道的商品或者性别女的降分
|
99
|
if (physicalChannel.equals("1")) {
|
130
|
if (physicalChannel.equals("1")) {
|
|
|
131
|
+ BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
100
|
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
|
132
|
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
|
101
|
boolQueryBuilder.should(QueryBuilders.termsQuery("gender", "2"));
|
133
|
boolQueryBuilder.should(QueryBuilders.termsQuery("gender", "2"));
|
102
|
- return boolQueryBuilder;
|
134
|
+ results.add(new PhysicalChannelScore(boolQueryBuilder, this.getDescoreGenderWeight(uid, physicalChannelWeight, "2")));
|
|
|
135
|
+ return results;
|
103
|
}
|
136
|
}
|
104
|
// 女生频道,对非女生频道的商品或者性别男的降分
|
137
|
// 女生频道,对非女生频道的商品或者性别男的降分
|
105
|
if (physicalChannel.equals("2")) {
|
138
|
if (physicalChannel.equals("2")) {
|
|
|
139
|
+ BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
106
|
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
|
140
|
boolQueryBuilder.should(QueryBuilders.boolQuery().mustNot(physicalChannelsTermsQueryBuilder));
|
107
|
boolQueryBuilder.should(QueryBuilders.termsQuery("gender", "1"));
|
141
|
boolQueryBuilder.should(QueryBuilders.termsQuery("gender", "1"));
|
108
|
- return boolQueryBuilder;
|
142
|
+ results.add(new PhysicalChannelScore(boolQueryBuilder, this.getDescoreGenderWeight(uid, physicalChannelWeight, "1")));
|
|
|
143
|
+ return results;
|
109
|
}
|
144
|
}
|
110
|
- return null;
|
145
|
+ return new ArrayList<PhysicalChannelScore>();
|
111
|
}
|
146
|
}
|
112
|
|
147
|
|
113
|
private boolean isUserSearchContainGender(Map<String, String> paramMap) {
|
148
|
private boolean isUserSearchContainGender(Map<String, String> paramMap) {
|