Authored by 胡古飞

个性化添加时间维度的判断

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>();
@@ -108,7 +108,7 @@ public class SearchCommonHelper { @@ -108,7 +108,7 @@ public class SearchCommonHelper {
108 } 108 }
109 return false; 109 return false;
110 } 110 }
111 - 111 +
112 /** 112 /**
113 * 是否需要对频道降分 113 * 是否需要对频道降分
114 * 114 *
@@ -117,13 +117,13 @@ public class SearchCommonHelper { @@ -117,13 +117,13 @@ public class SearchCommonHelper {
117 */ 117 */
118 public boolean isNeedDeScoreForChannel(Map<String, String> paramMap) { 118 public boolean isNeedDeScoreForChannel(Map<String, String> paramMap) {
119 String physicalChannel = paramMap.get(SearchRequestParams.PHYSICAL_CHANNEL); 119 String physicalChannel = paramMap.get(SearchRequestParams.PHYSICAL_CHANNEL);
120 - if(StringUtils.isBlank(physicalChannel)){ 120 + if (StringUtils.isBlank(physicalChannel)) {
121 return false; 121 return false;
122 } 122 }
123 - if(!isFuzzySearchDefault(paramMap)){ 123 + if (!isFuzzySearchDefault(paramMap)) {
124 return false; 124 return false;
125 } 125 }
126 - if(!dynamicConfig.isDeScorePhysicalChannelOpen()){ 126 + if (!dynamicConfig.isDeScorePhysicalChannelOpen()) {
127 return false; 127 return false;
128 } 128 }
129 return true; 129 return true;
@@ -187,6 +187,24 @@ public class SearchCommonHelper { @@ -187,6 +187,24 @@ public class SearchCommonHelper {
187 } 187 }
188 188
189 /** 189 /**
  190 + * 是否需要对新品到着默认页降分
  191 + *
  192 + * @param paramMap
  193 + * @return
  194 + */
  195 + public boolean isNeedDeScoreForNewArrivePage(Map<String, String> paramMap) {
  196 + String pageId = paramMap.get("pageId");
  197 + if (!("4".equals(pageId))) {
  198 + return false;
  199 + }
  200 + String order = paramMap.get("order");
  201 + if (!StringUtils.isBlank(order)) {
  202 + return false;
  203 + }
  204 + return true;
  205 + }
  206 +
  207 + /**
190 * 关键字中含性别,则加上性别的过滤条件 208 * 关键字中含性别,则加上性别的过滤条件
191 * 209 *
192 * @param keyword 210 * @param keyword