...
|
...
|
@@ -45,7 +45,6 @@ import com.yoho.search.service.service.helper.SearchCommonHelper; |
|
|
import com.yoho.search.service.service.helper.SearchServiceHelper;
|
|
|
import com.yoho.search.service.service.helper.SearchSortHelper;
|
|
|
import com.yoho.search.service.servicenew.IGoodProductsService;
|
|
|
import com.yoho.search.service.utils.SearchRequestParams;
|
|
|
import com.yoho.search.service.vo.SearchApiResult;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -86,7 +85,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
// 3、再根据品类和品牌推荐SKN
|
|
|
List<String> recommondSkns = this.recommondSknsBySortAndBrandInfo(sortAndBrandInfo, paramMap);
|
|
|
|
|
|
if (openLog) {
|
|
|
if (paramMap.getOrDefault("uid", "0").equals("13420925")) {
|
|
|
logger.warn("goodProductList recommondSkns is : [{}]", recommondSkns);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -219,21 +218,18 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
// 2、构造filter
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = this.getDefaultBoolQueryBuilder();
|
|
|
BoolQueryBuilder brandAndSortFilter = new BoolQueryBuilder();
|
|
|
if (!brandIds.isEmpty()) {
|
|
|
boolFilter.must(QueryBuilders.termsQuery("brandId", brandIds));
|
|
|
brandAndSortFilter.should(QueryBuilders.termsQuery("brandId", brandIds));
|
|
|
}
|
|
|
if (!smallSortIds.isEmpty()) {
|
|
|
boolFilter.must(QueryBuilders.termsQuery("smallSortId", smallSortIds));
|
|
|
brandAndSortFilter.should(QueryBuilders.termsQuery("smallSortId", smallSortIds));
|
|
|
}
|
|
|
boolFilter.must(brandAndSortFilter);
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
|
|
|
// 3、构造query
|
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(QueryBuilders.matchAllQuery());
|
|
|
// 针对看过的SKN做加分
|
|
|
String productSkns = paramMap.get(SearchRequestParams.PARAM_SYNC_SKN);
|
|
|
if (!StringUtils.isBlank(productSkns)) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", productSkns.split(",")), ScoreFunctionBuilders.weightFactorFunction(100));
|
|
|
}
|
|
|
// 强制加上个性化打分
|
|
|
functionScoreSearchHelper.addCommonPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
|
|
|
searchParam.setQuery(functionScoreQueryBuilder);
|
...
|
...
|
@@ -249,7 +245,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
// 4.3)为子聚合添加孙聚合:取得分最大的值
|
|
|
sonAggregationBuilder.subAggregation(AggregationBuilders.max("sort").field(sortField));
|
|
|
// 4.4)为子聚合孙聚合:取打分最高的一个product
|
|
|
sonAggregationBuilder.subAggregation(AggregationBuilders.topHits("product").addSort(SortBuilders.fieldSort(sortField).order(sortOrder)).setSize(2));
|
|
|
sonAggregationBuilder.subAggregation(AggregationBuilders.topHits("product").addSort(SortBuilders.fieldSort(sortField).order(sortOrder)).setSize(1));
|
|
|
list.add(parentAggregationBuilder.subAggregation(sonAggregationBuilder));
|
|
|
searchParam.setAggregationBuilders(list);
|
|
|
|
...
|
...
|
@@ -295,6 +291,12 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 9、混合用户看过的商品前面
|
|
|
for (String skn : paramMap.getOrDefault("product_skn", "").split(",")) {
|
|
|
if (!recommendedSknJSONArray.contains(skn)) {
|
|
|
recommendedSknJSONArray.add(skn);
|
|
|
}
|
|
|
}
|
|
|
Collections.shuffle(recommendedSknJSONArray);
|
|
|
searchCacheService.addJSONArrayToCache(indexName, searchParam, recommendedSknJSONArray);
|
|
|
return this.jsonArrayToList(recommendedSknJSONArray, String.class);
|
...
|
...
|
@@ -305,7 +307,7 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
|
|
|
// 针对推荐出来的SKN做加分
|
|
|
if (recommendedSknList != null && !recommendedSknList.isEmpty()) {
|
|
|
Map<Integer, List<String>> recommondSknMap = this.splitProductSkns(recommendedSknList, 5);
|
|
|
Map<Integer, List<String>> recommondSknMap = this.splitProductSkns(recommendedSknList, 3);
|
|
|
float currentGroupScore = 1000;
|
|
|
for (Map.Entry<Integer, List<String>> entry : recommondSknMap.entrySet()) {
|
|
|
functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", entry.getValue()), ScoreFunctionBuilders.weightFactorFunction(currentGroupScore));
|
...
|
...
|
@@ -369,14 +371,16 @@ public class GoodProductListService implements IGoodProductsService { |
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
List<String> list = new ArrayList<String>();
|
|
|
JSONArray jsonArray = new JSONArray();
|
|
|
for (int i = 1; i <= 99; i++) {
|
|
|
list.add(i + "");
|
|
|
jsonArray.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());
|
|
|
for (int i = 1; i <= 99; i++) {
|
|
|
if (!jsonArray.contains(i + "")) {
|
|
|
jsonArray.add(i + "");
|
|
|
}
|
|
|
}
|
|
|
System.out.println(jsonArray.toJSONString());
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|