Authored by 胡古飞

有好货的个性化也考虑时间维度

... ... @@ -42,9 +42,9 @@ public class FunctionScoreSearchHelper {
// 普通个性化的时间维度
private final int oneDaySecondCount = 24 * 60 * 60;
private FirstShelveTimeScore commonFirstShelveTimeScore = new FirstShelveTimeScore(90,30,60);
private FirstShelveTimeScore commonFirstShelveTimeScore = new FirstShelveTimeScore(90, 30, 60);
// 新品到着的个性化时间维度
private FirstShelveTimeScore newRecShelveTimeScore = new FirstShelveTimeScore(30,10,20);
private FirstShelveTimeScore newRecShelveTimeScore = new FirstShelveTimeScore(30, 10, 20);
private final float globalWeight = 0.50f;
private WeightBuilder genWeightFactorBuilder(float factor) {
... ... @@ -60,8 +60,7 @@ public class FunctionScoreSearchHelper {
}
// 个性化搜索相关
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
personalVectorFeatureSearch.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
this.addFirstShelveTimeFunctionScore(functionScoreQueryBuilder, paramMap);
this.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
}
// 针对全球购降分
if (searchCommonHelper.containGlobal(paramMap)) {
... ... @@ -83,12 +82,14 @@ public class FunctionScoreSearchHelper {
}
/**
* 个性化时添加时间维度的降
* 为个性化搜索添加打
*
* @param functionScoreQueryBuilder
* @param paramMap
*/
private void addFirstShelveTimeFunctionScore(FunctionScoreQueryBuilder functionScoreQueryBuilder, Map<String, String> paramMap) {
public void addPersonalizedScriptScore(FunctionScoreQueryBuilder functionScoreQueryBuilder, Map<String, String> paramMap) {
// 个性化搜索相关
personalVectorFeatureSearch.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
if (searchCommonHelper.isNewRecPageDefault(paramMap)) {
this.addFirstShelveTimeScore(functionScoreQueryBuilder, newRecShelveTimeScore);
} else {
... ...
... ... @@ -35,7 +35,6 @@ import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.cache.CacheEnum;
import com.yoho.search.service.personalized.PersonalVectorFeatureSearch;
import com.yoho.search.service.service.SearchCacheService;
import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.service.helper.AggProductListHelper;
... ... @@ -55,8 +54,6 @@ public class GoodProductListService implements IGoodProductsService {
@Autowired
private SearchServiceHelper searchServiceHelper;
@Autowired
private FunctionScoreSearchHelper functionScoreSearchHelper;
@Autowired
private SearchCacheService searchCacheService;
@Autowired
private AggProductListHelper aggProductListHelper;
... ... @@ -65,7 +62,7 @@ public class GoodProductListService implements IGoodProductsService {
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
private PersonalVectorFeatureSearch personalVectorFeatureSearch;
private FunctionScoreSearchHelper functionScoreSearchHelper;
private final int maxSmallSortCount = 20;
private final int maxProductSknCountPerSort = 5;
... ... @@ -138,14 +135,14 @@ public class GoodProductListService implements IGoodProductsService {
if (recommendedSknList != null && !recommendedSknList.isEmpty()) {
Map<Integer, List<String>> recommondSknMap = this.splitProductSkns(recommendedSknList, maxCountPerGroup);
float currentGroupScore = recommendedSknMaxScore;
for (Map.Entry<Integer, List<String>> entry: recommondSknMap.entrySet()) {
for (Map.Entry<Integer, List<String>> entry : recommondSknMap.entrySet()) {
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", entry.getValue()), ScoreFunctionBuilders.weightFactorFunction(currentGroupScore));
currentGroupScore = currentGroupScore - 10;
}
}
// 加上个性化打分
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
personalVectorFeatureSearch.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
functionScoreSearchHelper.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
}
return functionScoreQueryBuilder;
}
... ... @@ -246,10 +243,8 @@ public class GoodProductListService implements IGoodProductsService {
if (!StringUtils.isBlank(productSkns)) {
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", productSkns.split(",")), ScoreFunctionBuilders.weightFactorFunction(100));
}
// 加上个性化打分
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
personalVectorFeatureSearch.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
}
// 强制加上个性化打分
functionScoreSearchHelper.addPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
searchParam.setQuery(functionScoreQueryBuilder);
// 4、设置聚合条件
... ... @@ -345,7 +340,7 @@ public class GoodProductListService implements IGoodProductsService {
public static void main(String[] args) {
List<String> list = new ArrayList<String>();
for (int i = 1; i <= 99; i++) {
list.add(i+"");
list.add(i + "");
}
Map<Integer, List<String>> results = new GoodProductListService().splitProductSkns(list, 20);
for (Map.Entry<Integer, List<String>> entry : results.entrySet()) {
... ...