1
|
package com.yoho.search.service.service.helper;
|
1
|
package com.yoho.search.service.service.helper;
|
2
|
|
2
|
|
3
|
import java.util.ArrayList;
|
3
|
import java.util.ArrayList;
|
|
|
4
|
+import java.util.Date;
|
4
|
import java.util.List;
|
5
|
import java.util.List;
|
5
|
import java.util.Map;
|
6
|
import java.util.Map;
|
6
|
|
7
|
|
|
@@ -17,6 +18,7 @@ import org.slf4j.LoggerFactory; |
|
@@ -17,6 +18,7 @@ import org.slf4j.LoggerFactory; |
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
import org.springframework.stereotype.Component;
|
19
|
import org.springframework.stereotype.Component;
|
19
|
|
20
|
|
|
|
21
|
+import com.yoho.search.base.utils.DateUtil;
|
20
|
import com.yoho.search.service.personalized.PersonalVectorFeatureSearch;
|
22
|
import com.yoho.search.service.personalized.PersonalVectorFeatureSearch;
|
21
|
import com.yoho.search.service.personalized.PersonalizedRedisService;
|
23
|
import com.yoho.search.service.personalized.PersonalizedRedisService;
|
22
|
import com.yoho.search.service.service.SearchDynamicConfigService;
|
24
|
import com.yoho.search.service.service.SearchDynamicConfigService;
|
|
@@ -37,7 +39,12 @@ public class FunctionScoreSearchHelper { |
|
@@ -37,7 +39,12 @@ public class FunctionScoreSearchHelper { |
37
|
@Autowired
|
39
|
@Autowired
|
38
|
private PersonalizedRedisService personalizedRedisService;
|
40
|
private PersonalizedRedisService personalizedRedisService;
|
39
|
|
41
|
|
40
|
- static float globalWeight = 0.50f;
|
42
|
+ private final float globalWeight = 0.50f;
|
|
|
43
|
+
|
|
|
44
|
+ private final int oneDaySecondCount = 24 * 60 * 60;
|
|
|
45
|
+ private final int limitDayCount = 45;
|
|
|
46
|
+ private final int offsetDayCount = 15;
|
|
|
47
|
+ private final int scaleDayCount = 30;
|
41
|
|
48
|
|
42
|
private WeightBuilder genWeightFactorBuilder(float factor) {
|
49
|
private WeightBuilder genWeightFactorBuilder(float factor) {
|
43
|
return ScoreFunctionBuilders.weightFactorFunction(factor);
|
50
|
return ScoreFunctionBuilders.weightFactorFunction(factor);
|
|
@@ -48,10 +55,18 @@ public class FunctionScoreSearchHelper { |
|
@@ -48,10 +55,18 @@ public class FunctionScoreSearchHelper { |
48
|
// 将某些SKN展示到前面
|
55
|
// 将某些SKN展示到前面
|
49
|
if (searchCommonHelper.isFirstProductSknSearch(paramMap)) {
|
56
|
if (searchCommonHelper.isFirstProductSknSearch(paramMap)) {
|
50
|
String[] productSkns = paramMap.get(SearchRequestParams.FIRST_PRODUCRSKN).split(",");
|
57
|
String[] productSkns = paramMap.get(SearchRequestParams.FIRST_PRODUCRSKN).split(",");
|
51
|
- functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn",productSkns),ScoreFunctionBuilders.weightFactorFunction(1000));
|
58
|
+ functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", productSkns), ScoreFunctionBuilders.weightFactorFunction(1000));
|
52
|
}
|
59
|
}
|
|
|
60
|
+ // 个性化搜索相关
|
53
|
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
|
61
|
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
|
54
|
personalVectorFeatureSearch.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
|
62
|
personalVectorFeatureSearch.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
|
|
|
63
|
+ //个性化统一添加时间规则
|
|
|
64
|
+ int todayLastSecond = DateUtil.getLastTimeSecond(new Date());
|
|
|
65
|
+ int limitSecondValue = todayLastSecond - limitDayCount * oneDaySecondCount;
|
|
|
66
|
+ int scaleSecondTime = scaleDayCount * oneDaySecondCount;
|
|
|
67
|
+ int offsetSecondValue = offsetDayCount * oneDaySecondCount;
|
|
|
68
|
+ functionScoreQueryBuilder.add(QueryBuilders.rangeQuery("firstShelveTime").lt(limitSecondValue), ScoreFunctionBuilders.weightFactorFunction(0.5f));
|
|
|
69
|
+ functionScoreQueryBuilder.add(QueryBuilders.rangeQuery("firstShelveTime").from(limitSecondValue), ScoreFunctionBuilders.linearDecayFunction("firstShelveTime",todayLastSecond,scaleSecondTime).setOffset(offsetSecondValue));
|
55
|
}
|
70
|
}
|
56
|
if (searchCommonHelper.containGlobal(paramMap)) {
|
71
|
if (searchCommonHelper.containGlobal(paramMap)) {
|
57
|
functionScoreQueryBuilder.add(QueryBuilders.termQuery("isGlobal", "Y"), genWeightFactorBuilder(globalWeight));
|
72
|
functionScoreQueryBuilder.add(QueryBuilders.termQuery("isGlobal", "Y"), genWeightFactorBuilder(globalWeight));
|
|
@@ -116,7 +131,7 @@ public class FunctionScoreSearchHelper { |
|
@@ -116,7 +131,7 @@ public class FunctionScoreSearchHelper { |
116
|
|
131
|
|
117
|
// 潮童频道,对非潮童频道的和成人的商品降分
|
132
|
// 潮童频道,对非潮童频道的和成人的商品降分
|
118
|
if (physicalChannel.equals("3")) {
|
133
|
if (physicalChannel.equals("3")) {
|
119
|
- results.add(new PhysicalChannelScore(notPhysicalChannelsQueryBuilder,physicalChannelWeight));
|
134
|
+ results.add(new PhysicalChannelScore(notPhysicalChannelsQueryBuilder, physicalChannelWeight));
|
120
|
results.add(new PhysicalChannelScore(QueryBuilders.termsQuery("ageLevel", "1"), physicalChannelWeight));
|
135
|
results.add(new PhysicalChannelScore(QueryBuilders.termsQuery("ageLevel", "1"), physicalChannelWeight));
|
121
|
return results;
|
136
|
return results;
|
122
|
}
|
137
|
}
|
|
@@ -132,14 +147,14 @@ public class FunctionScoreSearchHelper { |
|
@@ -132,14 +147,14 @@ public class FunctionScoreSearchHelper { |
132
|
}
|
147
|
}
|
133
|
// 男生频道,对非男生频道的商品和性别女的降分
|
148
|
// 男生频道,对非男生频道的商品和性别女的降分
|
134
|
if (physicalChannel.equals("1")) {
|
149
|
if (physicalChannel.equals("1")) {
|
135
|
- results.add(new PhysicalChannelScore(notPhysicalChannelsQueryBuilder,physicalChannelWeight));
|
150
|
+ results.add(new PhysicalChannelScore(notPhysicalChannelsQueryBuilder, physicalChannelWeight));
|
136
|
results.add(new PhysicalChannelScore(QueryBuilders.termsQuery("gender", "2"), this.getDescoreGenderWeight(uid, physicalChannelWeight, "2")));
|
151
|
results.add(new PhysicalChannelScore(QueryBuilders.termsQuery("gender", "2"), this.getDescoreGenderWeight(uid, physicalChannelWeight, "2")));
|
137
|
return results;
|
152
|
return results;
|
138
|
}
|
153
|
}
|
139
|
// 女生频道,对非女生频道的商品和性别男的降分
|
154
|
// 女生频道,对非女生频道的商品和性别男的降分
|
140
|
if (physicalChannel.equals("2")) {
|
155
|
if (physicalChannel.equals("2")) {
|
141
|
- results.add(new PhysicalChannelScore(notPhysicalChannelsQueryBuilder,physicalChannelWeight));
|
|
|
142
|
- results.add(new PhysicalChannelScore(QueryBuilders.termsQuery("gender", "1"),this.getDescoreGenderWeight(uid, physicalChannelWeight, "1")));
|
156
|
+ results.add(new PhysicalChannelScore(notPhysicalChannelsQueryBuilder, physicalChannelWeight));
|
|
|
157
|
+ results.add(new PhysicalChannelScore(QueryBuilders.termsQuery("gender", "1"), this.getDescoreGenderWeight(uid, physicalChannelWeight, "1")));
|
143
|
return results;
|
158
|
return results;
|
144
|
}
|
159
|
}
|
145
|
return new ArrayList<PhysicalChannelScore>();
|
160
|
return new ArrayList<PhysicalChannelScore>();
|