Authored by 胡古飞

fix 发现好货的逻辑

@@ -45,7 +45,6 @@ import com.yoho.search.service.service.helper.SearchCommonHelper; @@ -45,7 +45,6 @@ import com.yoho.search.service.service.helper.SearchCommonHelper;
45 import com.yoho.search.service.service.helper.SearchServiceHelper; 45 import com.yoho.search.service.service.helper.SearchServiceHelper;
46 import com.yoho.search.service.service.helper.SearchSortHelper; 46 import com.yoho.search.service.service.helper.SearchSortHelper;
47 import com.yoho.search.service.servicenew.IGoodProductsService; 47 import com.yoho.search.service.servicenew.IGoodProductsService;
48 -import com.yoho.search.service.utils.SearchRequestParams;  
49 import com.yoho.search.service.vo.SearchApiResult; 48 import com.yoho.search.service.vo.SearchApiResult;
50 49
51 @Service 50 @Service
@@ -86,7 +85,7 @@ public class GoodProductListService implements IGoodProductsService { @@ -86,7 +85,7 @@ public class GoodProductListService implements IGoodProductsService {
86 // 3、再根据品类和品牌推荐SKN 85 // 3、再根据品类和品牌推荐SKN
87 List<String> recommondSkns = this.recommondSknsBySortAndBrandInfo(sortAndBrandInfo, paramMap); 86 List<String> recommondSkns = this.recommondSknsBySortAndBrandInfo(sortAndBrandInfo, paramMap);
88 87
89 - if (openLog) { 88 + if (paramMap.getOrDefault("uid", "0").equals("13420925")) {
90 logger.warn("goodProductList recommondSkns is : [{}]", recommondSkns); 89 logger.warn("goodProductList recommondSkns is : [{}]", recommondSkns);
91 } 90 }
92 91
@@ -219,21 +218,18 @@ public class GoodProductListService implements IGoodProductsService { @@ -219,21 +218,18 @@ public class GoodProductListService implements IGoodProductsService {
219 // 2、构造filter 218 // 2、构造filter
220 SearchParam searchParam = new SearchParam(); 219 SearchParam searchParam = new SearchParam();
221 BoolQueryBuilder boolFilter = this.getDefaultBoolQueryBuilder(); 220 BoolQueryBuilder boolFilter = this.getDefaultBoolQueryBuilder();
  221 + BoolQueryBuilder brandAndSortFilter = new BoolQueryBuilder();
222 if (!brandIds.isEmpty()) { 222 if (!brandIds.isEmpty()) {
223 - boolFilter.must(QueryBuilders.termsQuery("brandId", brandIds)); 223 + brandAndSortFilter.should(QueryBuilders.termsQuery("brandId", brandIds));
224 } 224 }
225 if (!smallSortIds.isEmpty()) { 225 if (!smallSortIds.isEmpty()) {
226 - boolFilter.must(QueryBuilders.termsQuery("smallSortId", smallSortIds)); 226 + brandAndSortFilter.should(QueryBuilders.termsQuery("smallSortId", smallSortIds));
227 } 227 }
  228 + boolFilter.must(brandAndSortFilter);
228 searchParam.setFiter(boolFilter); 229 searchParam.setFiter(boolFilter);
229 230
230 // 3、构造query 231 // 3、构造query
231 FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(QueryBuilders.matchAllQuery()); 232 FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(QueryBuilders.matchAllQuery());
232 - // 针对看过的SKN做加分  
233 - String productSkns = paramMap.get(SearchRequestParams.PARAM_SYNC_SKN);  
234 - if (!StringUtils.isBlank(productSkns)) {  
235 - functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", productSkns.split(",")), ScoreFunctionBuilders.weightFactorFunction(100));  
236 - }  
237 // 强制加上个性化打分 233 // 强制加上个性化打分
238 functionScoreSearchHelper.addCommonPersonalizedScriptScore(functionScoreQueryBuilder, paramMap); 234 functionScoreSearchHelper.addCommonPersonalizedScriptScore(functionScoreQueryBuilder, paramMap);
239 searchParam.setQuery(functionScoreQueryBuilder); 235 searchParam.setQuery(functionScoreQueryBuilder);
@@ -249,7 +245,7 @@ public class GoodProductListService implements IGoodProductsService { @@ -249,7 +245,7 @@ public class GoodProductListService implements IGoodProductsService {
249 // 4.3)为子聚合添加孙聚合:取得分最大的值 245 // 4.3)为子聚合添加孙聚合:取得分最大的值
250 sonAggregationBuilder.subAggregation(AggregationBuilders.max("sort").field(sortField)); 246 sonAggregationBuilder.subAggregation(AggregationBuilders.max("sort").field(sortField));
251 // 4.4)为子聚合孙聚合:取打分最高的一个product 247 // 4.4)为子聚合孙聚合:取打分最高的一个product
252 - sonAggregationBuilder.subAggregation(AggregationBuilders.topHits("product").addSort(SortBuilders.fieldSort(sortField).order(sortOrder)).setSize(2)); 248 + sonAggregationBuilder.subAggregation(AggregationBuilders.topHits("product").addSort(SortBuilders.fieldSort(sortField).order(sortOrder)).setSize(1));
253 list.add(parentAggregationBuilder.subAggregation(sonAggregationBuilder)); 249 list.add(parentAggregationBuilder.subAggregation(sonAggregationBuilder));
254 searchParam.setAggregationBuilders(list); 250 searchParam.setAggregationBuilders(list);
255 251
@@ -295,6 +291,12 @@ public class GoodProductListService implements IGoodProductsService { @@ -295,6 +291,12 @@ public class GoodProductListService implements IGoodProductsService {
295 } 291 }
296 } 292 }
297 } 293 }
  294 + // 9、混合用户看过的商品前面
  295 + for (String skn : paramMap.getOrDefault("product_skn", "").split(",")) {
  296 + if (!recommendedSknJSONArray.contains(skn)) {
  297 + recommendedSknJSONArray.add(skn);
  298 + }
  299 + }
298 Collections.shuffle(recommendedSknJSONArray); 300 Collections.shuffle(recommendedSknJSONArray);
299 searchCacheService.addJSONArrayToCache(indexName, searchParam, recommendedSknJSONArray); 301 searchCacheService.addJSONArrayToCache(indexName, searchParam, recommendedSknJSONArray);
300 return this.jsonArrayToList(recommendedSknJSONArray, String.class); 302 return this.jsonArrayToList(recommendedSknJSONArray, String.class);
@@ -305,7 +307,7 @@ public class GoodProductListService implements IGoodProductsService { @@ -305,7 +307,7 @@ public class GoodProductListService implements IGoodProductsService {
305 FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder); 307 FunctionScoreQueryBuilder functionScoreQueryBuilder = new FunctionScoreQueryBuilder(queryBuilder);
306 // 针对推荐出来的SKN做加分 308 // 针对推荐出来的SKN做加分
307 if (recommendedSknList != null && !recommendedSknList.isEmpty()) { 309 if (recommendedSknList != null && !recommendedSknList.isEmpty()) {
308 - Map<Integer, List<String>> recommondSknMap = this.splitProductSkns(recommendedSknList, 5); 310 + Map<Integer, List<String>> recommondSknMap = this.splitProductSkns(recommendedSknList, 3);
309 float currentGroupScore = 1000; 311 float currentGroupScore = 1000;
310 for (Map.Entry<Integer, List<String>> entry : recommondSknMap.entrySet()) { 312 for (Map.Entry<Integer, List<String>> entry : recommondSknMap.entrySet()) {
311 functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", entry.getValue()), ScoreFunctionBuilders.weightFactorFunction(currentGroupScore)); 313 functionScoreQueryBuilder.add(QueryBuilders.termsQuery("productSkn", entry.getValue()), ScoreFunctionBuilders.weightFactorFunction(currentGroupScore));
@@ -369,14 +371,16 @@ public class GoodProductListService implements IGoodProductsService { @@ -369,14 +371,16 @@ public class GoodProductListService implements IGoodProductsService {
369 } 371 }
370 372
371 public static void main(String[] args) { 373 public static void main(String[] args) {
372 - List<String> list = new ArrayList<String>(); 374 + JSONArray jsonArray = new JSONArray();
373 for (int i = 1; i <= 99; i++) { 375 for (int i = 1; i <= 99; i++) {
374 - list.add(i + ""); 376 + jsonArray.add(i + "");
375 } 377 }
376 - Map<Integer, List<String>> results = new GoodProductListService().splitProductSkns(list, 20);  
377 - for (Map.Entry<Integer, List<String>> entry : results.entrySet()) {  
378 - System.out.println(entry.getKey() + "_" + entry.getValue()); 378 + for (int i = 1; i <= 99; i++) {
  379 + if (!jsonArray.contains(i + "")) {
  380 + jsonArray.add(i + "");
  381 + }
379 } 382 }
  383 + System.out.println(jsonArray.toJSONString());
380 } 384 }
381 385
382 } 386 }