...
|
...
|
@@ -3,6 +3,7 @@ package com.yoho.search.service.servicenew.impl; |
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
...
|
...
|
@@ -68,6 +69,9 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
|
|
|
private final int maxSmallSortCount = 20;
|
|
|
private final int maxProductSknCountPerSort = 5;
|
|
|
private final int maxCountPerGroup = 10;
|
|
|
private final float firstSknScore = 300;
|
|
|
private final float recommendedSknMaxScore = 200;
|
|
|
|
|
|
@Override
|
|
|
public SearchApiResult goodProductList(Map<String, String> paramMap) {
|
...
|
...
|
@@ -122,17 +126,22 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
}
|
|
|
|
|
|
private QueryBuilder builderGoodProductQueryBuilder(Map<String, String> paramMap, List<String> recommondSkns) {
|
|
|
private QueryBuilder builderGoodProductQueryBuilder(Map<String, String> paramMap, List<String> recommendedSknList) {
|
|
|
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
|
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
|
|
|
// 针对参数里第一个SKN加分
|
|
|
String productSkns = paramMap.get(SearchRequestParams.PARAM_SYNC_SKN);
|
|
|
if (!StringUtils.isBlank(productSkns)) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", productSkns.split(",")[0]), ScoreFunctionBuilders.weightFactorFunction(100));
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", productSkns.split(",")[0]), ScoreFunctionBuilders.weightFactorFunction(firstSknScore));
|
|
|
}
|
|
|
// 针对推荐出来的SKN做加分
|
|
|
if (recommondSkns != null && !recommondSkns.isEmpty()) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", recommondSkns), ScoreFunctionBuilders.weightFactorFunction(50));
|
|
|
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()) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", entry.getValue()), ScoreFunctionBuilders.weightFactorFunction(currentGroupScore));
|
|
|
currentGroupScore = currentGroupScore - 10;
|
|
|
}
|
|
|
}
|
|
|
// 加上个性化打分
|
|
|
if (searchCommonHelper.isNeedPersonalSearch(paramMap)) {
|
...
|
...
|
@@ -291,6 +300,28 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
return JSONObject.parseArray(jsonArray.toJSONString(), clazz);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 分组
|
|
|
*
|
|
|
* @param recommendedSknList
|
|
|
* @param maxGroupCount
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<Integer, List<String>> splitProductSkns(List<String> recommendedSknList, int maxCountPerGroup) {
|
|
|
int maxSize = recommendedSknList.size();
|
|
|
int groupSize = maxSize / maxCountPerGroup;
|
|
|
if (maxSize % maxCountPerGroup > 0) {
|
|
|
groupSize = groupSize + 1;
|
|
|
}
|
|
|
Map<Integer, List<String>> result = new HashMap<Integer, List<String>>();
|
|
|
for (int i = 0; i < groupSize; i++) {
|
|
|
int fromIndex = i * maxCountPerGroup;
|
|
|
int toIndex = (i + 1) * maxCountPerGroup;
|
|
|
result.put(i, recommendedSknList.subList(fromIndex, toIndex > maxSize ? maxSize : toIndex));
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private List<String> getRecommendedSknList(MultiBucketsAggregation aggregation) {
|
|
|
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
|
|
|
// 获取聚合出来的商品
|
...
|
...
|
@@ -310,4 +341,16 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
Collections.shuffle(recommendedSknList);
|
|
|
return recommendedSknList;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
List<String> list = new ArrayList<String>();
|
|
|
for (int i = 1; i <= 99; i++) {
|
|
|
list.add(i+"");
|
|
|
}
|
|
|
Map<Integer, List<String>> results = new GoodProductListService().splitProductSkns(list, 20);
|
|
|
for (Map.Entry<Integer, List<String>> entry : results.entrySet()) {
|
|
|
System.out.println(entry.getKey() + "_" + entry.getValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|