...
|
...
|
@@ -23,6 +23,7 @@ import com.yoho.search.service.personalized.PersonalVectorFeatureSearch; |
|
|
import com.yoho.search.service.personalized.PersonalizedRedisService;
|
|
|
import com.yoho.search.service.service.SearchDynamicConfigService;
|
|
|
import com.yoho.search.service.utils.SearchRequestParams;
|
|
|
import com.yoho.search.service.vo.FirstShelveTimeScore;
|
|
|
import com.yoho.search.service.vo.PhysicalChannelScore;
|
|
|
|
|
|
@Component
|
...
|
...
|
@@ -39,13 +40,13 @@ public class FunctionScoreSearchHelper { |
|
|
@Autowired
|
|
|
private PersonalizedRedisService personalizedRedisService;
|
|
|
|
|
|
private final float globalWeight = 0.50f;
|
|
|
|
|
|
// 普通个性化的时间维度
|
|
|
private final int oneDaySecondCount = 24 * 60 * 60;
|
|
|
private final int limitDayCount = 90;
|
|
|
private final int offsetDayCount = 30;
|
|
|
private final int scaleDayCount = 60;
|
|
|
|
|
|
private FirstShelveTimeScore commonFirstShelveTimeScore = new FirstShelveTimeScore(90,30,60);
|
|
|
// 新品到着的个性化时间维度
|
|
|
private FirstShelveTimeScore newRecShelveTimeScore = new FirstShelveTimeScore(30,10,20);
|
|
|
private final float globalWeight = 0.50f;
|
|
|
|
|
|
private WeightBuilder genWeightFactorBuilder(float factor) {
|
|
|
return ScoreFunctionBuilders.weightFactorFunction(factor);
|
|
|
}
|
...
|
...
|
@@ -60,32 +61,52 @@ public class FunctionScoreSearchHelper { |
|
|
// 个性化搜索相关
|
|
|
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
|
|
|
personalVectorFeatureSearch.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
|
|
|
//个性化统一添加时间规则
|
|
|
int todayLastSecond = DateUtil.getLastTimeSecond(new Date());
|
|
|
int limitSecondValue = todayLastSecond - limitDayCount * oneDaySecondCount;
|
|
|
int scaleSecondTime = scaleDayCount * oneDaySecondCount;
|
|
|
int offsetSecondValue = offsetDayCount * oneDaySecondCount;
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.rangeQuery("firstShelveTime").lt(limitSecondValue), ScoreFunctionBuilders.weightFactorFunction(0.5f));
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.rangeQuery("firstShelveTime").from(limitSecondValue), ScoreFunctionBuilders.linearDecayFunction("firstShelveTime",todayLastSecond,scaleSecondTime).setOffset(offsetSecondValue));
|
|
|
this.addFirstShelveTimeFunctionScore(functionScoreQueryBuilder, paramMap);
|
|
|
}
|
|
|
// 针对全球购降分
|
|
|
if (searchCommonHelper.containGlobal(paramMap)) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termQuery("isGlobal", "Y"), genWeightFactorBuilder(globalWeight));
|
|
|
}
|
|
|
if (searchCommonHelper.isNeedDeScoreBrandSearch(paramMap)) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termQuery("isForbiddenSortBrand", "1"), ScoreFunctionBuilders.weightFactorFunction(0));
|
|
|
}
|
|
|
// 针对频道降分
|
|
|
// 模糊搜索针对频道降分
|
|
|
if (searchCommonHelper.isNeedDeScoreForChannel(paramMap)) {
|
|
|
List<PhysicalChannelScore> physicalChannelScores = this.getPhysicalChannelQueryBuilder(paramMap);
|
|
|
for (PhysicalChannelScore physicalChannelScore : physicalChannelScores) {
|
|
|
functionScoreQueryBuilder.add(physicalChannelScore.getQueryBuilder(), ScoreFunctionBuilders.weightFactorFunction(physicalChannelScore.getWeight()));
|
|
|
}
|
|
|
}
|
|
|
// 针对屏蔽的品牌降分【目前没用】
|
|
|
if (searchCommonHelper.isNeedDeScoreBrandSearch(paramMap)) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termQuery("isForbiddenSortBrand", "1"), ScoreFunctionBuilders.weightFactorFunction(0));
|
|
|
}
|
|
|
functionScoreQueryBuilder.boostMode(CombineFunction.MULT);
|
|
|
return functionScoreQueryBuilder;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 个性化时添加时间维度的降分
|
|
|
*
|
|
|
* @param functionScoreQueryBuilder
|
|
|
* @param paramMap
|
|
|
*/
|
|
|
private void addFirstShelveTimeFunctionScore(FunctionScoreQueryBuilder functionScoreQueryBuilder, Map<String, String> paramMap) {
|
|
|
if (searchCommonHelper.isNewRecPageDefault(paramMap)) {
|
|
|
this.addFirstShelveTimeScore(functionScoreQueryBuilder, newRecShelveTimeScore);
|
|
|
} else {
|
|
|
this.addFirstShelveTimeScore(functionScoreQueryBuilder, commonFirstShelveTimeScore);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void addFirstShelveTimeScore(FunctionScoreQueryBuilder functionScoreQueryBuilder, FirstShelveTimeScore firstShelveTimeScore) {
|
|
|
int todayLastSecond = DateUtil.getLastTimeSecond(new Date());
|
|
|
int limitSecondValue = todayLastSecond - firstShelveTimeScore.getLimitDayCount() * oneDaySecondCount;
|
|
|
int scaleSecondTime = firstShelveTimeScore.getScaleDayCount() * oneDaySecondCount;
|
|
|
int offsetSecondValue = firstShelveTimeScore.getOffsetDayCount() * oneDaySecondCount;
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.rangeQuery("firstShelveTime").lt(limitSecondValue), ScoreFunctionBuilders.weightFactorFunction(0.5f));
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.rangeQuery("firstShelveTime").from(limitSecondValue),
|
|
|
ScoreFunctionBuilders.linearDecayFunction("firstShelveTime", todayLastSecond, scaleSecondTime).setOffset(offsetSecondValue));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 直接使用商品特征的向量用来做个性化打分
|
|
|
*
|
|
|
* @param queryBuilder
|
...
|
...
|
@@ -106,7 +127,7 @@ public class FunctionScoreSearchHelper { |
|
|
* @param descoreGender
|
|
|
* @return
|
|
|
*/
|
|
|
public float getDescoreGenderWeight(String uid, float baseScore, String descoreGender) {
|
|
|
private float getDescoreGenderWeight(String uid, float baseScore, String descoreGender) {
|
|
|
try {
|
|
|
Map<String, Float> userGenderFloat = personalizedRedisService.getUserGenderFeature(uid);
|
|
|
Float userGenderWeight = userGenderFloat.get(descoreGender);
|
...
|
...
|
|