Authored by hugufei

添加品类页的动态参数

@@ -166,4 +166,18 @@ public class SearchDynamicConfigService { @@ -166,4 +166,18 @@ public class SearchDynamicConfigService {
166 public int getSearchLikeNotInShopSameSortPercent() { 166 public int getSearchLikeNotInShopSameSortPercent() {
167 return configReader.getInt("search.searchlike.not_in_shop.same_sort_percent", 60); 167 return configReader.getInt("search.searchlike.not_in_shop.same_sort_percent", 60);
168 } 168 }
  169 +
  170 + /**
  171 + * 品类页使用新的召回机制
  172 + */
  173 + public boolean isSortPageRecallOpen() {
  174 + return configReader.getBoolean("search.sortpage.recall.open", true);
  175 + }
  176 +
  177 + /**
  178 + * 召回时是否使用全局品牌id
  179 + */
  180 + public boolean isSortPageRecallUseGlobalBrand() {
  181 + return configReader.getBoolean("search.sortpage.recall.use_global_brand", false);
  182 + }
169 } 183 }
@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service; @@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
15 import com.alibaba.fastjson.JSONObject; 15 import com.alibaba.fastjson.JSONObject;
16 import com.yoho.search.base.utils.SearchPageIdDefine; 16 import com.yoho.search.base.utils.SearchPageIdDefine;
17 import com.yoho.search.models.SearchApiResult; 17 import com.yoho.search.models.SearchApiResult;
  18 +import com.yoho.search.service.base.SearchDynamicConfigService;
18 import com.yoho.search.service.base.SearchRequestParams; 19 import com.yoho.search.service.base.SearchRequestParams;
19 import com.yoho.search.service.helper.SearchCommonHelper; 20 import com.yoho.search.service.helper.SearchCommonHelper;
20 import com.yoho.search.service.scene.common.AbstractSceneService; 21 import com.yoho.search.service.scene.common.AbstractSceneService;
@@ -41,6 +42,8 @@ public class SortSceneService extends AbstractSceneService { @@ -41,6 +42,8 @@ public class SortSceneService extends AbstractSceneService {
41 private IAggRecommendService aggRecommendService; 42 private IAggRecommendService aggRecommendService;
42 @Autowired 43 @Autowired
43 private SortRecallSceneService sortRecallSceneService; 44 private SortRecallSceneService sortRecallSceneService;
  45 + @Autowired
  46 + private SearchDynamicConfigService searchDynamicConfigService;
44 47
45 @Override 48 @Override
46 public String pageId() { 49 public String pageId() {
@@ -86,16 +89,18 @@ public class SortSceneService extends AbstractSceneService { @@ -86,16 +89,18 @@ public class SortSceneService extends AbstractSceneService {
86 // 1、添加默认参数 89 // 1、添加默认参数
87 this.addParamsToParamMap(paramMap); 90 this.addParamsToParamMap(paramMap);
88 CompletableFuture<SearchApiResult> productListFuture = null; 91 CompletableFuture<SearchApiResult> productListFuture = null;
89 - // 2、获取商品列表  
90 - //if(!"13420925".equals(this.getuid(paramMap))){  
91 - productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)),executorService);  
92 - //}else{  
93 - // productListFuture = CompletableFuture.supplyAsync(() -> sortRecallSceneService.productList(this.newParamMap(paramMap)),executorService);  
94 - //} 92 + // 2、获取商品列表-是否使用召回策略
  93 + if (searchDynamicConfigService.isSortPageRecallOpen()) {
  94 + productListFuture = CompletableFuture.supplyAsync(() -> sortRecallSceneService.productList(this.newParamMap(paramMap)), executorService);
  95 + } else {
  96 + productListFuture = CompletableFuture.supplyAsync(() -> sceneProductListService.productList(this.newParamMap(paramMap)), executorService);
  97 + }
95 // 3、获取聚合结果 98 // 3、获取聚合结果
96 - CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggStandard(this.newParamMap(paramMap)),executorService);  
97 - CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(this.newParamMap(paramMap)),executorService);  
98 - CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> aggRecommendService.recommendPromotion(this.newParamMap(paramMap)), executorService); 99 + CompletableFuture<SearchApiResult> standardsFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggStandard(this.newParamMap(paramMap)), executorService);
  100 + CompletableFuture<SearchApiResult> customizeTagFuture = CompletableFuture.supplyAsync(() -> productIndexService.aggCustomizeTag(this.newParamMap(paramMap)),
  101 + executorService);
  102 + CompletableFuture<List<Object>> recommendProductFuture = CompletableFuture.supplyAsync(() -> aggRecommendService.recommendPromotion(this.newParamMap(paramMap)),
  103 + executorService);
99 // 4、组合结果 104 // 4、组合结果
100 SearchApiResult productList = productListFuture.get(); 105 SearchApiResult productList = productListFuture.get();
101 SearchApiResult standards = standardsFuture.get(); 106 SearchApiResult standards = standardsFuture.get();
@@ -52,17 +52,17 @@ public abstract class AbstractRecallService { @@ -52,17 +52,17 @@ public abstract class AbstractRecallService {
52 long begin = System.currentTimeMillis(); 52 long begin = System.currentTimeMillis();
53 // 1、获取召回策略 53 // 1、获取召回策略
54 List<IRecallStrategy> recallStrategys = this.getRecallStrategys(paramMap); 54 List<IRecallStrategy> recallStrategys = this.getRecallStrategys(paramMap);
55 - logger.warn("[func=getRecallStrategys][cost={}ms]", System.currentTimeMillis() - begin); 55 + logger.info("[func=getRecallStrategys][cost={}ms]", System.currentTimeMillis() - begin);
56 56
57 // 2、获取召回参数 57 // 2、获取召回参数
58 begin = System.currentTimeMillis(); 58 begin = System.currentTimeMillis();
59 List<RecallSearchParam> recallSearchParams = this.getRecallSearchParams(paramMap, recallStrategys); 59 List<RecallSearchParam> recallSearchParams = this.getRecallSearchParams(paramMap, recallStrategys);
60 - logger.warn("[func=getRecallSearchParams][cost={}ms]", System.currentTimeMillis() - begin); 60 + logger.info("[func=getRecallSearchParams][cost={}ms]", System.currentTimeMillis() - begin);
61 61
62 // 3、执行查询 62 // 3、执行查询
63 begin = System.currentTimeMillis(); 63 begin = System.currentTimeMillis();
64 RecallResult recallResult = this.queryRecallResult(recallSearchParams); 64 RecallResult recallResult = this.queryRecallResult(recallSearchParams);
65 - logger.warn("[func=queryRecallResult][cost={}ms]", System.currentTimeMillis() - begin); 65 + logger.info("[func=queryRecallResult][cost={}ms]", System.currentTimeMillis() - begin);
66 66
67 // 4、从兜底策略中获取总数 67 // 4、从兜底策略中获取总数
68 long total = this.getTotalFromRecallResult(recallResult); 68 long total = this.getTotalFromRecallResult(recallResult);
@@ -70,17 +70,17 @@ public abstract class AbstractRecallService { @@ -70,17 +70,17 @@ public abstract class AbstractRecallService {
70 // 5、粗排 70 // 5、粗排
71 begin = System.currentTimeMillis(); 71 begin = System.currentTimeMillis();
72 recallResult = this.doSketchyRank(paramMap, recallResult); 72 recallResult = this.doSketchyRank(paramMap, recallResult);
73 - logger.warn("[func=doSketchyRank][cost={}ms]", System.currentTimeMillis() - begin); 73 + logger.info("[func=doSketchyRank][cost={}ms]", System.currentTimeMillis() - begin);
74 74
75 // 6、精排 75 // 6、精排
76 begin = System.currentTimeMillis(); 76 begin = System.currentTimeMillis();
77 recallResult = this.doCarefulRank(paramMap, recallResult); 77 recallResult = this.doCarefulRank(paramMap, recallResult);
78 - logger.warn("[func=doCarefulRank][cost={}ms]", System.currentTimeMillis() - begin); 78 + logger.info("[func=doCarefulRank][cost={}ms]", System.currentTimeMillis() - begin);
79 79
80 // 7、重排 80 // 7、重排
81 begin = System.currentTimeMillis(); 81 begin = System.currentTimeMillis();
82 recallResult = this.doReRank(paramMap, recallResult); 82 recallResult = this.doReRank(paramMap, recallResult);
83 - logger.warn("[func=doReRank][cost={}ms]", System.currentTimeMillis() - begin); 83 + logger.info("[func=doReRank][cost={}ms]", System.currentTimeMillis() - begin);
84 84
85 // 8、构造返回结果 85 // 8、构造返回结果
86 begin = System.currentTimeMillis(); 86 begin = System.currentTimeMillis();
@@ -137,7 +137,7 @@ public abstract class AbstractRecallService { @@ -137,7 +137,7 @@ public abstract class AbstractRecallService {
137 searchParams.add(recallSearchParam.getSearchParam()); 137 searchParams.add(recallSearchParam.getSearchParam());
138 } 138 }
139 List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams); 139 List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams);
140 - logger.warn("doMutiSearch cost is:[{}]", System.currentTimeMillis() - begin); 140 + logger.info("doMutiSearch cost is:[{}]", System.currentTimeMillis() - begin);
141 List<RecallSearchResult> recallSearchResults = new ArrayList<RecallSearchResult>(); 141 List<RecallSearchResult> recallSearchResults = new ArrayList<RecallSearchResult>();
142 for (int i = 0; i < recallSearchParams.size(); i++) { 142 for (int i = 0; i < recallSearchParams.size(); i++) {
143 recallSearchResults.add(new RecallSearchResult(recallSearchParams.get(i).getRecallType(), searchResults.get(i))); 143 recallSearchResults.add(new RecallSearchResult(recallSearchParams.get(i).getRecallType(), searchResults.get(i)));
@@ -126,14 +126,12 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -126,14 +126,12 @@ public class SortRecallSceneService extends AbstractRecallService {
126 // 2)获取商品列表 126 // 2)获取商品列表
127 long begin = System.currentTimeMillis(); 127 long begin = System.currentTimeMillis();
128 RecallProductInfoList recallProductInfoList = this.queryRecallProductInfoList(paramMap, page, pageSize); 128 RecallProductInfoList recallProductInfoList = this.queryRecallProductInfoList(paramMap, page, pageSize);
129 - logger.warn("[func1=queryRealProductList][cost={}]", System.currentTimeMillis() - begin); 129 + logger.info("[func1=queryRealProductList][cost={}]", System.currentTimeMillis() - begin);
130 130
131 // 3)填充变价计划,并做品牌打散 131 // 3)填充变价计划,并做品牌打散
132 begin = System.currentTimeMillis(); 132 begin = System.currentTimeMillis();
133 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(recallProductInfoList.getProductInfoList()); 133 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(recallProductInfoList.getProductInfoList());
134 - // product_list =  
135 - // productListSortService.sortProductList(product_list, paramMap);  
136 - logger.warn("[func2=getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin); 134 + logger.info("[func2=getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin);
137 135
138 // 4)构造返回结果 136 // 4)构造返回结果
139 JSONObject dataMap = new JSONObject(); 137 JSONObject dataMap = new JSONObject();
@@ -201,7 +199,7 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -201,7 +199,7 @@ public class SortRecallSceneService extends AbstractRecallService {
201 } 199 }
202 realResults.add(productMap.get(produtSkn)); 200 realResults.add(productMap.get(produtSkn));
203 } 201 }
204 - logger.warn("[func=queryProductListWithSort][query by sknList][resultsize is {}][cost={}]", productList.size(), System.currentTimeMillis() - begin); 202 + logger.info("[func=queryProductListWithSort][query by sknList][resultsize is {}][cost={}]", productList.size(), System.currentTimeMillis() - begin);
205 return realResults; 203 return realResults;
206 } 204 }
207 205
@@ -236,7 +234,7 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -236,7 +234,7 @@ public class SortRecallSceneService extends AbstractRecallService {
236 234
237 // 4、查询es 235 // 4、查询es
238 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); 236 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
239 - logger.warn("[func=queryProductListWithDefault][resultsize is {}][cost={}]", searchResult.getTotal(), System.currentTimeMillis() - begin); 237 + logger.info("[func=queryProductListWithDefault][resultsize is {}][cost={}]", searchResult.getTotal(), System.currentTimeMillis() - begin);
240 return searchResult.getResultList(); 238 return searchResult.getResultList();
241 } 239 }
242 240
@@ -258,13 +256,13 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -258,13 +256,13 @@ public class SortRecallSceneService extends AbstractRecallService {
258 String uid = MapUtils.getString(paramMap, "uid", "0"); 256 String uid = MapUtils.getString(paramMap, "uid", "0");
259 String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion(); 257 String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion();
260 String userGlobalBrandIds = bigDataRedisService.getUserGlobalFaveriteBrand(uid, vectorFeatureVersion); 258 String userGlobalBrandIds = bigDataRedisService.getUserGlobalFaveriteBrand(uid, vectorFeatureVersion);
261 - logger.warn("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds); 259 + logger.info("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds);
262 JSONArray brandJsonArray = JSON.parseArray(userGlobalBrandIds); 260 JSONArray brandJsonArray = JSON.parseArray(userGlobalBrandIds);
263 List<Integer> results = new ArrayList<Integer>(); 261 List<Integer> results = new ArrayList<Integer>();
264 for (int i = 0; i < brandJsonArray.size(); i++) { 262 for (int i = 0; i < brandJsonArray.size(); i++) {
265 results.add(Integer.valueOf(brandJsonArray.getString(i))); 263 results.add(Integer.valueOf(brandJsonArray.getString(i)));
266 } 264 }
267 - logger.warn("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results); 265 + logger.info("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results);
268 return results; 266 return results;
269 } catch (Exception e) { 267 } catch (Exception e) {
270 logger.error(e.getMessage(), e); 268 logger.error(e.getMessage(), e);
@@ -330,7 +328,7 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -330,7 +328,7 @@ public class SortRecallSceneService extends AbstractRecallService {
330 for (Map<String, Object> result : results) { 328 for (Map<String, Object> result : results) {
331 brandIds.add(MapUtils.getInteger(result, "id")); 329 brandIds.add(MapUtils.getInteger(result, "id"));
332 } 330 }
333 - logger.warn("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds); 331 + logger.info("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds);
334 return brandIds; 332 return brandIds;
335 } catch (Exception e) { 333 } catch (Exception e) {
336 logger.error(e.getMessage(), e); 334 logger.error(e.getMessage(), e);
@@ -349,8 +347,12 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -349,8 +347,12 @@ public class SortRecallSceneService extends AbstractRecallService {
349 List<IRecallStrategy> recallStrategy = new ArrayList<IRecallStrategy>(); 347 List<IRecallStrategy> recallStrategy = new ArrayList<IRecallStrategy>();
350 int pageSize = this.getPageSize(paramMap); 348 int pageSize = this.getPageSize(paramMap);
351 // 0、获取用户偏好品牌 349 // 0、获取用户偏好品牌
352 - // List<Integer> brandIds = this.getUserGlobalBrandIds(paramMap);  
353 - List<Integer> brandIds = this.getUserLikeBrandIds(paramMap); 350 + List<Integer> brandIds = null;
  351 + if(searchDynamicConfigService.isSortPageRecallUseGlobalBrand()){
  352 + brandIds = this.getUserGlobalBrandIds(paramMap);
  353 + }else{
  354 + brandIds = this.getUserLikeBrandIds(paramMap);
  355 + }
354 // 1、支持firstProductSkn的召回 356 // 1、支持firstProductSkn的召回
355 recallStrategy.add(new FirstProductSknStrategy(1, this.getFirstProductSkns(paramMap))); 357 recallStrategy.add(new FirstProductSknStrategy(1, this.getFirstProductSkns(paramMap)));
356 // 2、支持直通车的召回-随机召回 358 // 2、支持直通车的召回-随机召回
@@ -383,7 +385,7 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -383,7 +385,7 @@ public class SortRecallSceneService extends AbstractRecallService {
383 protected RecallResult doSketchyRank(Map<String, String> paramMap, RecallResult recallResult) { 385 protected RecallResult doSketchyRank(Map<String, String> paramMap, RecallResult recallResult) {
384 Set<String> existProductSkns = new HashSet<String>(); 386 Set<String> existProductSkns = new HashSet<String>();
385 for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) { 387 for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {
386 - logger.warn("[func=doSketchyRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size()); 388 + logger.info("[func=doSketchyRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
387 Iterator<Map<String, Object>> iterator = recallSearchResult.getResultList().iterator(); 389 Iterator<Map<String, Object>> iterator = recallSearchResult.getResultList().iterator();
388 while (iterator.hasNext()) { 390 while (iterator.hasNext()) {
389 Map<String, Object> product = iterator.next(); 391 Map<String, Object> product = iterator.next();
@@ -403,7 +405,7 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -403,7 +405,7 @@ public class SortRecallSceneService extends AbstractRecallService {
403 // 1、数据组装 405 // 1、数据组装
404 List<Map<String, Object>> productList = new ArrayList<Map<String, Object>>(); 406 List<Map<String, Object>> productList = new ArrayList<Map<String, Object>>();
405 for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) { 407 for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {
406 - logger.warn("[func=doCarefulRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size()); 408 + logger.info("[func=doCarefulRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
407 for (Map<String, Object> product : recallSearchResult.getResultList()) { 409 for (Map<String, Object> product : recallSearchResult.getResultList()) {
408 product.put("recallType", recallSearchResult.getRecallType()); 410 product.put("recallType", recallSearchResult.getRecallType());
409 productList.add(product); 411 productList.add(product);
@@ -462,7 +464,7 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -462,7 +464,7 @@ public class SortRecallSceneService extends AbstractRecallService {
462 int count = newProductList.size(); 464 int count = newProductList.size();
463 int maxPage = count / pageSize; 465 int maxPage = count / pageSize;
464 recallResult.setProductList(newProductList.subList(0, maxPage * pageSize)); 466 recallResult.setProductList(newProductList.subList(0, maxPage * pageSize));
465 - logger.warn("[func=doReRank][total product size is ={}]", recallResult.getProductList().size()); 467 + logger.info("[func=doReRank][total product size is ={}]", recallResult.getProductList().size());
466 return recallResult; 468 return recallResult;
467 } 469 }
468 470