Authored by hugufei

拆包

Showing 13 changed files with 179 additions and 199 deletions
1 -package com.yoho.search.recall.scene.request; 1 +package com.yoho.search.recall.scene;
2 2
3 -import com.yoho.search.recall.scene.models.RecallParams;  
4 -import com.yoho.search.recall.scene.models.RecallRequest; 3 +import com.yoho.search.recall.scene.builder.request.BrandRecallRequestBuilder;
  4 +import com.yoho.search.recall.scene.builder.request.CommonRecallRequestBuilder;
  5 +import com.yoho.search.recall.scene.builder.request.SortPriceRecallRequestBuilder;
  6 +import com.yoho.search.recall.scene.builder.response.RecallResponseBatchBuilder;
  7 +import com.yoho.search.recall.scene.builder.response.RecallSknResultBuilder;
  8 +import com.yoho.search.recall.scene.component.BatchRecallComponent;
  9 +import com.yoho.search.recall.scene.models.*;
5 import com.yoho.search.recall.scene.persional.PersionalFactor; 10 import com.yoho.search.recall.scene.persional.PersionalFactor;
6 -import com.yoho.search.recall.scene.request.BrandRecallRequestBuilder;  
7 -import com.yoho.search.recall.scene.request.CommonRecallRequestBuilder;  
8 -import com.yoho.search.recall.scene.request.SortPriceRecallRequestBuilder; 11 +import com.yoho.search.recall.scene.persional.RecallPersionalService;
9 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Component; 13 import org.springframework.stereotype.Component;
11 14
@@ -13,22 +16,54 @@ import java.util.ArrayList; @@ -13,22 +16,54 @@ import java.util.ArrayList;
13 import java.util.List; 16 import java.util.List;
14 17
15 @Component 18 @Component
16 -public class BatchRequestsBuilder { 19 +public class RecallService {
17 20
18 @Autowired 21 @Autowired
  22 + private RecallPersionalService recallPersionalService;
  23 + @Autowired
  24 + private BatchRecallComponent bacthRecallComponent;
  25 + @Autowired
  26 + private RecallResponseBatchBuilder recallResponseBatchBuilder;
  27 + @Autowired
  28 + private RecallSknResultBuilder recallSknResultBuilder;
  29 + @Autowired
19 private CommonRecallRequestBuilder commonRequestBuilder; 30 private CommonRecallRequestBuilder commonRequestBuilder;
20 @Autowired 31 @Autowired
21 private BrandRecallRequestBuilder brandRequestBuilder; 32 private BrandRecallRequestBuilder brandRequestBuilder;
22 @Autowired 33 @Autowired
23 private SortPriceRecallRequestBuilder sortPriceRequestBuilder; 34 private SortPriceRecallRequestBuilder sortPriceRequestBuilder;
24 35
  36 + public RecallSknResult getRecallSknResult(RecallSknParams recallSknParams){
  37 + RecallSknResult recallSknResult = this.doRecall(recallSknParams);
  38 + return recallSknResult;
  39 + }
  40 +
  41 + /**
  42 + * 召回入口
  43 + * @param param
  44 + * @return
  45 + */
  46 + private RecallSknResult doRecall(RecallSknParams param) {
  47 + //1、获取个性化因子
  48 + PersionalFactor persionalFactor = recallPersionalService.queryPersionalFactor(param);
  49 + //2、构造请求
  50 + List<RecallRequest> batchRequests = this.buildBatchRequests(param, persionalFactor);
  51 + //3、批量召回
  52 + List<CacheRecallRequestResponse> requestResponses = bacthRecallComponent.batchRecallAndCache(batchRequests);
  53 + //4、获取skn列表[去重]
  54 + RecallResponseBatch recallResponseBatch = recallResponseBatchBuilder.buildRecallResponseBatch(requestResponses);
  55 + //5、构造真实结果[排序,截取skn]
  56 + RecallSknResult recallSknResult = recallSknResultBuilder.builderRecallResult(recallResponseBatch, param, persionalFactor);
  57 + return recallSknResult;
  58 + }
  59 +
25 /** 60 /**
26 - * 批量请求构造器 61 + * 批量构造请求
27 * @param param 62 * @param param
28 * @param persionalFactor 63 * @param persionalFactor
29 * @return 64 * @return
30 */ 65 */
31 - public List<RecallRequest> buildBatchRequests(RecallParams param,PersionalFactor persionalFactor) { 66 + public List<RecallRequest> buildBatchRequests(RecallSknParams param, PersionalFactor persionalFactor) {
32 //1、构造召回请求 67 //1、构造召回请求
33 List<RecallRequest> allRequests = new ArrayList<>(); 68 List<RecallRequest> allRequests = new ArrayList<>();
34 //2、构造非个性化的请求 69 //2、构造非个性化的请求
1 package com.yoho.search.recall.scene; 1 package com.yoho.search.recall.scene;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.yoho.search.base.utils.CollectionUtils;
4 import com.yoho.search.base.utils.ISearchConstants; 5 import com.yoho.search.base.utils.ISearchConstants;
5 import com.yoho.search.base.utils.ProductIndexEsField; 6 import com.yoho.search.base.utils.ProductIndexEsField;
6 import com.yoho.search.core.es.model.SearchParam; 7 import com.yoho.search.core.es.model.SearchParam;
@@ -9,13 +10,7 @@ import com.yoho.search.models.SearchApiResult; @@ -9,13 +10,7 @@ import com.yoho.search.models.SearchApiResult;
9 import com.yoho.search.recall.scene.component.*; 10 import com.yoho.search.recall.scene.component.*;
10 import com.yoho.search.recall.scene.helper.SortBuilderHelper; 11 import com.yoho.search.recall.scene.helper.SortBuilderHelper;
11 import com.yoho.search.recall.scene.models.*; 12 import com.yoho.search.recall.scene.models.*;
12 -import com.yoho.search.recall.scene.models.CacheRecallRequestResponse;  
13 -import com.yoho.search.recall.scene.persional.PersionalFactor;  
14 -import com.yoho.search.recall.scene.persional.RecallPersionalService;  
15 -import com.yoho.search.recall.scene.request.BatchRequestsBuilder;  
16 -import com.yoho.search.recall.scene.request.BatchResponseBuilder;  
17 -import com.yoho.search.recall.scene.request.RecallParamsBuilder;  
18 -import com.yoho.search.recall.scene.request.RecallResultBuilder; 13 +import com.yoho.search.recall.scene.builder.request.RecallParamsBuilder;
19 import com.yoho.search.service.base.SearchCommonService; 14 import com.yoho.search.service.base.SearchCommonService;
20 import com.yoho.search.service.base.index.ProductIndexBaseService; 15 import com.yoho.search.service.base.index.ProductIndexBaseService;
21 import com.yoho.search.service.helper.SearchCommonHelper; 16 import com.yoho.search.service.helper.SearchCommonHelper;
@@ -40,16 +35,6 @@ public class SceneRecallService { @@ -40,16 +35,6 @@ public class SceneRecallService {
40 @Autowired 35 @Autowired
41 private RecallParamsBuilder recallParamsBuilder; 36 private RecallParamsBuilder recallParamsBuilder;
42 @Autowired 37 @Autowired
43 - private RecallPersionalService recallPersionalService;  
44 - @Autowired  
45 - private BatchRequestsBuilder batchRequestsBuilder;  
46 - @Autowired  
47 - private BatchRecallComponent bacthRecallComponent;  
48 - @Autowired  
49 - private BatchResponseBuilder batchResponseBuilder;  
50 - @Autowired  
51 - private RecallResultBuilder recallResultBuilder;  
52 - @Autowired  
53 private SearchCommonHelper searchCommonHelper; 38 private SearchCommonHelper searchCommonHelper;
54 @Autowired 39 @Autowired
55 private ProductIndexBaseService productIndexBaseService; 40 private ProductIndexBaseService productIndexBaseService;
@@ -57,6 +42,9 @@ public class SceneRecallService { @@ -57,6 +42,9 @@ public class SceneRecallService {
57 private SearchCommonService searchCommonService; 42 private SearchCommonService searchCommonService;
58 @Autowired 43 @Autowired
59 private BacthSknInfoComponent bacthSknInfoComponent; 44 private BacthSknInfoComponent bacthSknInfoComponent;
  45 + @Autowired
  46 + private RecallService recallService;
  47 +
60 48
61 public SearchApiResult sceneRecall(Map<String, String> paramMap) { 49 public SearchApiResult sceneRecall(Map<String, String> paramMap) {
62 try { 50 try {
@@ -67,19 +55,17 @@ public class SceneRecallService { @@ -67,19 +55,17 @@ public class SceneRecallService {
67 return new SearchApiResult().setCode(400).setMessage("分页参数不合法"); 55 return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
68 } 56 }
69 //2、构造召回相关参数 57 //2、构造召回相关参数
70 - RecallParams recallParams = recallParamsBuilder.buildRecallParams(paramMap);  
71 - //3、获取个性化因子  
72 - PersionalFactor persionalFactor = recallPersionalService.queryPersionalFactor(recallParams);  
73 - //4、执行召回  
74 - RecallResult recallResult = this.doRecall(recallParams, persionalFactor);  
75 - //5、根据召回结果查询商品信息  
76 - List<Map<String, Object>> productList = this.queryProductList(recallParams,recallResult); 58 + RecallSknParams recallSknParams = recallParamsBuilder.buildRecallParams(paramMap);
  59 + //3、执行召回
  60 + RecallSknResult recallSknResult = recallService.getRecallSknResult(recallSknParams);
  61 + //4、根据召回结果查询商品信息
  62 + List<Map<String, Object>> productList = this.queryProductList(recallSknParams, recallSknResult,page,pageSize);
77 //6、构造返回结果 63 //6、构造返回结果
78 JSONObject dataMap = new JSONObject(); 64 JSONObject dataMap = new JSONObject();
79 - dataMap.put("total", recallResult.getTotal());  
80 - dataMap.put("page", recallParams.getPage());  
81 - dataMap.put("page_size", recallParams.getPageSize());  
82 - dataMap.put("page_total", searchCommonHelper.getTotalPage(recallResult.getTotal(), recallParams.getPageSize())); 65 + dataMap.put("total", recallSknResult.getTotal());
  66 + dataMap.put("page", page);
  67 + dataMap.put("page_size", recallSknParams.getPageSize());
  68 + dataMap.put("page_total", searchCommonHelper.getTotalPage(recallSknResult.getTotal(), recallSknParams.getPageSize()));
83 dataMap.put("product_list", productList); 69 dataMap.put("product_list", productList);
84 return new SearchApiResult().setData(dataMap); 70 return new SearchApiResult().setData(dataMap);
85 } catch (Exception e) { 71 } catch (Exception e) {
@@ -88,46 +74,31 @@ public class SceneRecallService { @@ -88,46 +74,31 @@ public class SceneRecallService {
88 } 74 }
89 } 75 }
90 76
91 - /**  
92 - * 召回入口  
93 - *  
94 - * @param param  
95 - * @param persionalFactor  
96 - * @return  
97 - */  
98 - private RecallResult doRecall(RecallParams param, PersionalFactor persionalFactor) {  
99 - //1、构造请求  
100 - List<RecallRequest> batchRequests = batchRequestsBuilder.buildBatchRequests(param, persionalFactor);  
101 - //2、批量召回  
102 - List<CacheRecallRequestResponse> requestResponses = bacthRecallComponent.batchRecallAndCache(batchRequests);  
103 - //3、获取skn列表[去重]  
104 - RecallResponseBatch recallResponseBatch = batchResponseBuilder.buildRecallResponseBatch(requestResponses);  
105 - //4、构造真实结果[排序,截取skn]  
106 - RecallResult recallResult = recallResultBuilder.builderRecallResult(recallResponseBatch, param, persionalFactor);  
107 - return recallResult;  
108 - }  
109 77
110 - private List<Map<String, Object>> queryProductList(RecallParams recallParams,RecallResult recallResult) {  
111 - //1、  
112 - List<Integer> productSkns = recallResult.getSknList();  
113 - if (productSkns != null && !productSkns.isEmpty()) { 78 + private List<Map<String, Object>> queryProductList(RecallSknParams recallSknParams, RecallSknResult recallSknResult,int page,int pageSize) {
  79 + //1、判断当前页码是否在召回的页码里
  80 + int recallTotalPage = recallSknResult.getRecallTotalPage();
  81 + //2、在召回结果中则直接根据skn去查询
  82 + if(page<=recallTotalPage){
  83 + List<Integer> productSkns = CollectionUtils.safeSubList(recallSknResult.getSknList(),(page-1)*pageSize,page*pageSize);
114 return bacthSknInfoComponent.queryProductListBySkn(productSkns,productSkns.size()); 84 return bacthSknInfoComponent.queryProductListBySkn(productSkns,productSkns.size());
115 - }else{  
116 - return this.queryProductByFilterSkn(recallResult.getNotProductSkn(),recallResult.getRealPage(),recallParams.getPageSize());  
117 } 85 }
  86 + //3、过滤召回的skn,修改真实页码,执行查询
  87 + int realPage = page - recallTotalPage;
  88 + return this.queryProductByFilterSkn(recallSknResult.getSknList(), realPage, pageSize);
118 } 89 }
119 90
120 /** 91 /**
121 * 过滤掉已召回的skn,并按人气排序 92 * 过滤掉已召回的skn,并按人气排序
122 * @param notProductSkns 93 * @param notProductSkns
123 - * @param page 94 + * @param realPage
124 * @param pageSize 95 * @param pageSize
125 * @return 96 * @return
126 */ 97 */
127 - private List<Map<String, Object>> queryProductByFilterSkn(List<Integer> notProductSkns,int page,int pageSize){ 98 + private List<Map<String, Object>> queryProductByFilterSkn(List<Integer> notProductSkns,int realPage,int pageSize){
128 SearchParam searchParam = new SearchParam(); 99 SearchParam searchParam = new SearchParam();
129 //设置分页参数 100 //设置分页参数
130 - searchParam.setOffset((page-1)*pageSize); 101 + searchParam.setOffset((realPage-1)*pageSize);
131 searchParam.setSize(pageSize); 102 searchParam.setSize(pageSize);
132 103
133 //设置filter 104 //设置filter
@@ -147,8 +118,4 @@ public class SceneRecallService { @@ -147,8 +118,4 @@ public class SceneRecallService {
147 return productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList()); 118 return productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
148 } 119 }
149 120
150 -  
151 -  
152 -  
153 -  
154 } 121 }
1 -package com.yoho.search.recall.scene.request; 1 +package com.yoho.search.recall.scene.builder.request;
2 2
3 import com.yoho.search.recall.scene.constants.SknCountConstants; 3 import com.yoho.search.recall.scene.constants.SknCountConstants;
4 import com.yoho.search.recall.scene.models.ParamQueryFilter; 4 import com.yoho.search.recall.scene.models.ParamQueryFilter;
@@ -13,7 +13,7 @@ import java.util.ArrayList; @@ -13,7 +13,7 @@ import java.util.ArrayList;
13 import java.util.List; 13 import java.util.List;
14 14
15 @Component 15 @Component
16 -public class BrandRecallRequestBuilder extends BaseRecallRequest{ 16 +public class BrandRecallRequestBuilder{
17 17
18 /** 18 /**
19 * 按偏好品牌批量召回 19 * 按偏好品牌批量召回
@@ -52,8 +52,8 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{ @@ -52,8 +52,8 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{
52 * @return 52 * @return
53 */ 53 */
54 private RecallRequest buildBrandHeatValueRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) { 54 private RecallRequest buildBrandHeatValueRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) {
55 - BrandHeatValueStrategy strage = new BrandHeatValueStrategy(brandId, size);  
56 - return this.buildRecallRequest(paramQueryFilter, strage); 55 + BrandHeatValueStrategy strategy = new BrandHeatValueStrategy(brandId, size);
  56 + return new RecallRequest(paramQueryFilter, strategy);
57 } 57 }
58 58
59 /** 59 /**
@@ -66,7 +66,7 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{ @@ -66,7 +66,7 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{
66 */ 66 */
67 private RecallRequest buildBrandNewShelveRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) { 67 private RecallRequest buildBrandNewShelveRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) {
68 BrandNewShelveStrategy strage = new BrandNewShelveStrategy(brandId, size); 68 BrandNewShelveStrategy strage = new BrandNewShelveStrategy(brandId, size);
69 - return this.buildRecallRequest(paramQueryFilter, strage); 69 + return new RecallRequest(paramQueryFilter, strage);
70 } 70 }
71 71
72 /** 72 /**
@@ -79,7 +79,7 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{ @@ -79,7 +79,7 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{
79 */ 79 */
80 private RecallRequest buildBrandNewReducePriceRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) { 80 private RecallRequest buildBrandNewReducePriceRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) {
81 BrandReducePriceStrategy strage = new BrandReducePriceStrategy(brandId, size); 81 BrandReducePriceStrategy strage = new BrandReducePriceStrategy(brandId, size);
82 - return this.buildRecallRequest(paramQueryFilter, strage); 82 + return new RecallRequest(paramQueryFilter, strage);
83 } 83 }
84 84
85 /** 85 /**
@@ -92,7 +92,7 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{ @@ -92,7 +92,7 @@ public class BrandRecallRequestBuilder extends BaseRecallRequest{
92 */ 92 */
93 private RecallRequest buildBrandNewPromotionRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) { 93 private RecallRequest buildBrandNewPromotionRequest(ParamQueryFilter paramQueryFilter, Integer brandId, int size) {
94 BrandPromotionStrategy strage = new BrandPromotionStrategy(brandId, size); 94 BrandPromotionStrategy strage = new BrandPromotionStrategy(brandId, size);
95 - return this.buildRecallRequest(paramQueryFilter, strage); 95 + return new RecallRequest(paramQueryFilter, strage);
96 } 96 }
97 97
98 } 98 }
1 -package com.yoho.search.recall.scene.request; 1 +package com.yoho.search.recall.scene.builder.request;
2 2
3 3
4 import com.yoho.search.recall.scene.constants.SknCountConstants; 4 import com.yoho.search.recall.scene.constants.SknCountConstants;
@@ -11,7 +11,7 @@ import java.util.ArrayList; @@ -11,7 +11,7 @@ import java.util.ArrayList;
11 import java.util.List; 11 import java.util.List;
12 12
13 @Component 13 @Component
14 -public class CommonRecallRequestBuilder extends BaseRecallRequest { 14 +public class CommonRecallRequestBuilder{
15 15
16 /** 16 /**
17 * 批量召回业务需求 17 * 批量召回业务需求
@@ -45,8 +45,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest { @@ -45,8 +45,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest {
45 * @return 45 * @return
46 */ 46 */
47 private RecallRequest buildCommonRequest(ParamQueryFilter paramQueryFilter, int size) { 47 private RecallRequest buildCommonRequest(ParamQueryFilter paramQueryFilter, int size) {
48 - CommonHeatValueStrategy strage = new CommonHeatValueStrategy(size);  
49 - return this.buildRecallRequest(paramQueryFilter, strage); 48 + CommonHeatValueStrategy strategy = new CommonHeatValueStrategy(size);
  49 + return new RecallRequest(paramQueryFilter, strategy);
50 } 50 }
51 51
52 /** 52 /**
@@ -58,8 +58,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest { @@ -58,8 +58,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest {
58 * @return 58 * @return
59 */ 59 */
60 private RecallRequest buildFirstSknRequest(ParamQueryFilter paramQueryFilter, List<String> firstProductSkns, int size) { 60 private RecallRequest buildFirstSknRequest(ParamQueryFilter paramQueryFilter, List<String> firstProductSkns, int size) {
61 - CommonFirstSknStrategy strage = new CommonFirstSknStrategy(size, firstProductSkns);  
62 - return this.buildRecallRequest(paramQueryFilter, strage); 61 + CommonFirstSknStrategy strategy = new CommonFirstSknStrategy(size, firstProductSkns);
  62 + return new RecallRequest(paramQueryFilter, strategy);
63 } 63 }
64 64
65 /** 65 /**
@@ -70,8 +70,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest { @@ -70,8 +70,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest {
70 * @return 70 * @return
71 */ 71 */
72 private RecallRequest buildDirectTrainRequest(ParamQueryFilter paramQueryFilter, int size) { 72 private RecallRequest buildDirectTrainRequest(ParamQueryFilter paramQueryFilter, int size) {
73 - CommonDirectTrainStrategy strage = new CommonDirectTrainStrategy(size);  
74 - return this.buildRecallRequest(paramQueryFilter, strage); 73 + CommonDirectTrainStrategy strategy = new CommonDirectTrainStrategy(size);
  74 + return new RecallRequest(paramQueryFilter, strategy);
75 } 75 }
76 76
77 /** 77 /**
@@ -82,8 +82,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest { @@ -82,8 +82,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest {
82 * @return 82 * @return
83 */ 83 */
84 private RecallRequest buildNewShopRequest(ParamQueryFilter paramQueryFilter, int size) { 84 private RecallRequest buildNewShopRequest(ParamQueryFilter paramQueryFilter, int size) {
85 - CommonNewShopStrategy strage = new CommonNewShopStrategy(size);  
86 - return this.buildRecallRequest(paramQueryFilter, strage); 85 + CommonNewShopStrategy strategy = new CommonNewShopStrategy(size);
  86 + return new RecallRequest(paramQueryFilter, strategy);
87 } 87 }
88 88
89 /** 89 /**
@@ -94,8 +94,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest { @@ -94,8 +94,8 @@ public class CommonRecallRequestBuilder extends BaseRecallRequest {
94 * @return 94 * @return
95 */ 95 */
96 private RecallRequest buildAddFlowRequest(ParamQueryFilter paramQueryFilter, int size) { 96 private RecallRequest buildAddFlowRequest(ParamQueryFilter paramQueryFilter, int size) {
97 - CommonAddFlowStrategy strage = new CommonAddFlowStrategy(size);  
98 - return this.buildRecallRequest(paramQueryFilter, strage); 97 + CommonAddFlowStrategy strategy = new CommonAddFlowStrategy(size);
  98 + return new RecallRequest(paramQueryFilter, strategy);
99 } 99 }
100 100
101 } 101 }
1 -package com.yoho.search.recall.scene.request; 1 +package com.yoho.search.recall.scene.builder.request;
2 2
3 import com.yoho.search.recall.scene.models.ParamQueryFilter; 3 import com.yoho.search.recall.scene.models.ParamQueryFilter;
4 -import com.yoho.search.recall.scene.models.RecallParams; 4 +import com.yoho.search.recall.scene.models.RecallSknParams;
5 import com.yoho.search.recall.sort.helper.RecallServiceHelper; 5 import com.yoho.search.recall.sort.helper.RecallServiceHelper;
6 import com.yoho.search.service.helper.SearchServiceHelper; 6 import com.yoho.search.service.helper.SearchServiceHelper;
7 import org.apache.commons.collections.MapUtils; 7 import org.apache.commons.collections.MapUtils;
@@ -21,14 +21,13 @@ public class RecallParamsBuilder { @@ -21,14 +21,13 @@ public class RecallParamsBuilder {
21 @Autowired 21 @Autowired
22 private RecallServiceHelper recallServiceHelper; 22 private RecallServiceHelper recallServiceHelper;
23 23
24 - public RecallParams buildRecallParams(Map<String, String> paramMap) throws Exception { 24 + public RecallSknParams buildRecallParams(Map<String, String> paramMap) throws Exception {
25 //1、获取链接中的query和filter参数 25 //1、获取链接中的query和filter参数
26 QueryBuilder query = searchServiceHelepr.constructQueryBuilder(paramMap); 26 QueryBuilder query = searchServiceHelepr.constructQueryBuilder(paramMap);
27 BoolQueryBuilder filter = searchServiceHelepr.constructFilterBuilder(paramMap, null); 27 BoolQueryBuilder filter = searchServiceHelepr.constructFilterBuilder(paramMap, null);
28 ParamQueryFilter queryFilter = new ParamQueryFilter(query,filter); 28 ParamQueryFilter queryFilter = new ParamQueryFilter(query,filter);
29 29
30 //2、获取分页参数 30 //2、获取分页参数
31 - int page = MapUtils.getIntValue(paramMap, "page", 1);  
32 int pageSize = MapUtils.getIntValue(paramMap, "viewNum", 10); 31 int pageSize = MapUtils.getIntValue(paramMap, "viewNum", 10);
33 32
34 //3、获取firstSkn参数 33 //3、获取firstSkn参数
@@ -38,6 +37,6 @@ public class RecallParamsBuilder { @@ -38,6 +37,6 @@ public class RecallParamsBuilder {
38 int uid = MapUtils.getIntValue(paramMap, "uid", 1); 37 int uid = MapUtils.getIntValue(paramMap, "uid", 1);
39 String udid = MapUtils.getString(paramMap, "udid", ""); 38 String udid = MapUtils.getString(paramMap, "udid", "");
40 39
41 - return new RecallParams(queryFilter,page,pageSize, firstProductSkns , uid, udid); 40 + return new RecallSknParams(queryFilter,pageSize, firstProductSkns , uid, udid);
42 } 41 }
43 } 42 }
1 -package com.yoho.search.recall.scene.request; 1 +package com.yoho.search.recall.scene.builder.request;
2 2
3 import com.yoho.search.recall.scene.constants.SknCountConstants; 3 import com.yoho.search.recall.scene.constants.SknCountConstants;
4 import com.yoho.search.recall.scene.models.ParamQueryFilter; 4 import com.yoho.search.recall.scene.models.ParamQueryFilter;
@@ -11,7 +11,7 @@ import java.util.ArrayList; @@ -11,7 +11,7 @@ import java.util.ArrayList;
11 import java.util.List; 11 import java.util.List;
12 12
13 @Component 13 @Component
14 -public class SortPriceRecallRequestBuilder extends BaseRecallRequest{ 14 +public class SortPriceRecallRequestBuilder{
15 15
16 /** 16 /**
17 * 基于用户的品类价格带召回 17 * 基于用户的品类价格带召回
@@ -28,9 +28,8 @@ public class SortPriceRecallRequestBuilder extends BaseRecallRequest{ @@ -28,9 +28,8 @@ public class SortPriceRecallRequestBuilder extends BaseRecallRequest{
28 } 28 }
29 29
30 private RecallRequest buildSortPriceRecallRequest(ParamQueryFilter paramQueryFilter, PersionalFactor.SortPriceArea sortPriceArea, int size){ 30 private RecallRequest buildSortPriceRecallRequest(ParamQueryFilter paramQueryFilter, PersionalFactor.SortPriceArea sortPriceArea, int size){
31 - SortPriceStrategy strage = new SortPriceStrategy(sortPriceArea,size);  
32 - return this.buildRecallRequest(paramQueryFilter,strage); 31 + SortPriceStrategy strategy = new SortPriceStrategy(sortPriceArea,size);
  32 + return new RecallRequest(paramQueryFilter, strategy);
33 } 33 }
34 34
35 -  
36 } 35 }
1 -package com.yoho.search.recall.scene.request; 1 +package com.yoho.search.recall.scene.builder.response;
2 2
3 import com.yoho.search.recall.scene.models.RecallRequest; 3 import com.yoho.search.recall.scene.models.RecallRequest;
4 import com.yoho.search.recall.scene.models.CacheRecallRequestResponse; 4 import com.yoho.search.recall.scene.models.CacheRecallRequestResponse;
@@ -13,7 +13,7 @@ import java.util.List; @@ -13,7 +13,7 @@ import java.util.List;
13 import java.util.Map; 13 import java.util.Map;
14 14
15 @Component 15 @Component
16 -public class BatchResponseBuilder { 16 +public class RecallResponseBatchBuilder {
17 17
18 /** 18 /**
19 * 召回结果构造器 19 * 召回结果构造器
1 -package com.yoho.search.recall.scene.request; 1 +package com.yoho.search.recall.scene.builder.response;
2 2
3 import com.yoho.search.base.utils.CollectionUtils; 3 import com.yoho.search.base.utils.CollectionUtils;
4 -import com.yoho.search.recall.scene.models.RecallParams; 4 +import com.yoho.search.recall.scene.models.RecallSknParams;
5 import com.yoho.search.recall.scene.models.RecallResponseBatch; 5 import com.yoho.search.recall.scene.models.RecallResponseBatch;
6 -import com.yoho.search.recall.scene.models.RecallResult; 6 +import com.yoho.search.recall.scene.models.RecallSknResult;
7 import com.yoho.search.recall.scene.persional.PersionalFactor; 7 import com.yoho.search.recall.scene.persional.PersionalFactor;
8 import com.yoho.search.recall.scene.strategy.StrategyNameEnum; 8 import com.yoho.search.recall.scene.strategy.StrategyNameEnum;
9 import com.yoho.search.service.base.ProductListSortKey; 9 import com.yoho.search.service.base.ProductListSortKey;
@@ -17,16 +17,14 @@ import java.util.Comparator; @@ -17,16 +17,14 @@ import java.util.Comparator;
17 import java.util.List; 17 import java.util.List;
18 18
19 @Component 19 @Component
20 -public class RecallResultBuilder { 20 +public class RecallSknResultBuilder {
21 21
22 @Autowired 22 @Autowired
23 private ProductListSortService productListSortService; 23 private ProductListSortService productListSortService;
24 24
25 - public RecallResult builderRecallResult(RecallResponseBatch recallResponseBatch, RecallParams param, PersionalFactor persionalFactor){ 25 + public RecallSknResult builderRecallResult(RecallResponseBatch recallResponseBatch, RecallSknParams param, PersionalFactor persionalFactor){
26 //1、构造结果中的分页信息 26 //1、构造结果中的分页信息
27 final long total = recallResponseBatch.getTotal(); 27 final long total = recallResponseBatch.getTotal();
28 - final int page = param.getPage();  
29 - final int pageSize = param.getPageSize();  
30 28
31 //2、获取召回结果中的最大整数页码 29 //2、获取召回结果中的最大整数页码
32 List<RecallResponseBatch.SknResult> sknResultList = recallResponseBatch.getSknList(); 30 List<RecallResponseBatch.SknResult> sknResultList = recallResponseBatch.getSknList();
@@ -55,33 +53,24 @@ public class RecallResultBuilder { @@ -55,33 +53,24 @@ public class RecallResultBuilder {
55 }); 53 });
56 54
57 //TODO 6、处理直通车 55 //TODO 6、处理直通车
58 -  
59 //7、截取整数页 56 //7、截取整数页
60 - int recallMaxPage = (sknResultList.size() / pageSize);  
61 - if (recallMaxPage == 0) {  
62 - recallMaxPage = 1; 57 + int pageSize = param.getPageSize();
  58 + int recallTotalPage = (sknResultList.size() / pageSize);
  59 + if (recallTotalPage == 0) {
  60 + recallTotalPage = 1;
63 } 61 }
64 - if (recallMaxPage > 5) {  
65 - recallMaxPage = 5; 62 + if (recallTotalPage > 5) {
  63 + recallTotalPage = 5;
66 } 64 }
67 - sknResultList = CollectionUtils.safeSubList(sknResultList,0,recallMaxPage * pageSize);  
68 - final long recallTotal = sknResultList.size();  
69 -  
70 - //8、判断当前页码是否在召回结果中  
71 - int realPage;  
72 - List<Integer> sknList = null;  
73 - List<Integer> notProductSkn = null; 65 + sknResultList = CollectionUtils.safeSubList(sknResultList,0,recallTotalPage * param.getPageSize());
74 66
75 - if(page > recallMaxPage) {  
76 - realPage = page - recallMaxPage;  
77 - notProductSkn = this.getSknList(sknResultList);//notProductKlsn  
78 - }else{  
79 - realPage = page;  
80 - sknList = this.getSknList(CollectionUtils.safeSubList(sknResultList,(page-1)*pageSize,page *pageSize));  
81 - }  
82 - return new RecallResult(total,recallTotal,recallMaxPage,realPage,sknList,notProductSkn); 67 + //8、构造返回结果
  68 + List<Integer> sknList = this.getSknList(sknResultList);
  69 + int recallTotal = sknResultList.size();
  70 + return new RecallSknResult(total,recallTotal,recallTotalPage,sknList);
83 } 71 }
84 72
  73 +
85 private void doCalScore(List<RecallResponseBatch.SknResult> sknResultList,PersionalFactor persionalFactor) { 74 private void doCalScore(List<RecallResponseBatch.SknResult> sknResultList,PersionalFactor persionalFactor) {
86 String userFactor = persionalFactor.getUserFactor(); 75 String userFactor = persionalFactor.getUserFactor();
87 for (RecallResponseBatch.SknResult sknResult : sknResultList) { 76 for (RecallResponseBatch.SknResult sknResult : sknResultList) {
1 -package com.yoho.search.recall.scene.models;  
2 -  
3 -import java.util.List;  
4 -  
5 -public class RecallResult {  
6 - private final long total;  
7 - private final long recallTotal;  
8 - private final long recallPageTotal;  
9 - private final int realPage;  
10 - private final List<Integer> sknList;//查询的页码在召回的范围内,则返回这些skn  
11 - private final List<Integer> notProductSkn;//查询的页码不在召回的范围内,则返回全部召回的skn,外层过滤这些skn  
12 -  
13 - public RecallResult(long total,long recallTotal,long recallPageTotal, int realPage,List<Integer> sknList,List<Integer> notProductSkn) {  
14 - this.total = total;  
15 - this.recallTotal = recallTotal;  
16 - this.recallPageTotal = recallPageTotal;  
17 - this.realPage = realPage;  
18 - this.sknList = sknList;  
19 - this.notProductSkn = notProductSkn;  
20 - }  
21 -  
22 - public long getTotal() {  
23 - return total;  
24 - }  
25 -  
26 - public long getRecallTotal() {  
27 - return recallTotal;  
28 - }  
29 -  
30 - public long getRecallPageTotal() {  
31 - return recallPageTotal;  
32 - }  
33 -  
34 - public int getRealPage() {  
35 - return realPage;  
36 - }  
37 -  
38 - public List<Integer> getSknList() {  
39 - return sknList;  
40 - }  
41 -  
42 - public List<Integer> getNotProductSkn() {  
43 - return notProductSkn;  
44 - }  
45 -}  
@@ -2,19 +2,17 @@ package com.yoho.search.recall.scene.models; @@ -2,19 +2,17 @@ package com.yoho.search.recall.scene.models;
2 2
3 import java.util.List; 3 import java.util.List;
4 4
5 -public class RecallParams { 5 +public class RecallSknParams {
6 6
7 private final ParamQueryFilter paramQueryFilter; 7 private final ParamQueryFilter paramQueryFilter;
8 - private final int page;  
9 private final int pageSize; 8 private final int pageSize;
10 private final List<String> firstProductSkns; 9 private final List<String> firstProductSkns;
11 private final int uid; 10 private final int uid;
12 private final String udid; 11 private final String udid;
13 12
14 - public RecallParams(ParamQueryFilter paramQueryFilter,int page, int pageSize,List<String> firstProductSkns, int uid, String udid) { 13 + public RecallSknParams(ParamQueryFilter paramQueryFilter, int pageSize, List<String> firstProductSkns, int uid, String udid) {
15 this.paramQueryFilter = paramQueryFilter; 14 this.paramQueryFilter = paramQueryFilter;
16 this.firstProductSkns = firstProductSkns; 15 this.firstProductSkns = firstProductSkns;
17 - this.page = page;  
18 this.pageSize = pageSize; 16 this.pageSize = pageSize;
19 this.uid = uid; 17 this.uid = uid;
20 this.udid = udid; 18 this.udid = udid;
@@ -24,10 +22,6 @@ public class RecallParams { @@ -24,10 +22,6 @@ public class RecallParams {
24 return paramQueryFilter; 22 return paramQueryFilter;
25 } 23 }
26 24
27 - public int getPage() {  
28 - return page;  
29 - }  
30 -  
31 public int getPageSize() { 25 public int getPageSize() {
32 return pageSize; 26 return pageSize;
33 } 27 }
  1 +package com.yoho.search.recall.scene.models;
  2 +
  3 +import java.io.Serializable;
  4 +import java.util.List;
  5 +
  6 +public class RecallSknResult implements Serializable{
  7 +
  8 + private static final long serialVersionUID = -5692239509936546967L;
  9 +
  10 + private long total;
  11 + private int recallTotal;
  12 + private int recallTotalPage;
  13 + private List<Integer> sknList;
  14 +
  15 + public RecallSknResult() {
  16 + }
  17 +
  18 + public RecallSknResult(long total, int recallTotal, int recallTotalPage, List<Integer> sknList) {
  19 + this.total = total;
  20 + this.recallTotal = recallTotal;
  21 + this.recallTotalPage = recallTotalPage;
  22 + this.sknList = sknList;
  23 + }
  24 +
  25 + public long getTotal() {
  26 + return total;
  27 + }
  28 +
  29 + public void setTotal(long total) {
  30 + this.total = total;
  31 + }
  32 +
  33 + public int getRecallTotal() {
  34 + return recallTotal;
  35 + }
  36 +
  37 + public void setRecallTotal(int recallTotal) {
  38 + this.recallTotal = recallTotal;
  39 + }
  40 +
  41 + public int getRecallTotalPage() {
  42 + return recallTotalPage;
  43 + }
  44 +
  45 + public void setRecallTotalPage(int recallTotalPage) {
  46 + this.recallTotalPage = recallTotalPage;
  47 + }
  48 +
  49 + public List<Integer> getSknList() {
  50 + return sknList;
  51 + }
  52 +
  53 + public void setSknList(List<Integer> sknList) {
  54 + this.sknList = sknList;
  55 + }
  56 +}
1 package com.yoho.search.recall.scene.persional; 1 package com.yoho.search.recall.scene.persional;
2 2
3 -import com.yoho.search.recall.scene.models.ParamQueryFilter;  
4 -import com.yoho.search.recall.scene.models.RecallParams; 3 +import com.yoho.search.recall.scene.models.RecallSknParams;
5 import org.slf4j.Logger; 4 import org.slf4j.Logger;
6 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
7 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,15 +22,15 @@ public class RecallPersionalService { @@ -23,15 +22,15 @@ public class RecallPersionalService {
23 /** 22 /**
24 * 获取个性化因子 23 * 获取个性化因子
25 * 24 *
26 - * @param recallParams 25 + * @param recallSknParams
27 * @return 26 * @return
28 */ 27 */
29 - public PersionalFactor queryPersionalFactor(RecallParams recallParams) { 28 + public PersionalFactor queryPersionalFactor(RecallSknParams recallSknParams) {
30 try { 29 try {
31 //1、获取页面上的个性化因子 30 //1、获取页面上的个性化因子
32 - PersionalFactor pageFactor = pageComponent.queryPagePersionalFactor(recallParams.getParamQueryFilter()); 31 + PersionalFactor pageFactor = pageComponent.queryPagePersionalFactor(recallSknParams.getParamQueryFilter());
33 //2、获取用户的个性化因子 32 //2、获取用户的个性化因子
34 - PersionalFactor userFactor = userComponent.queryUserPersionalFactor(recallParams.getUid(), recallParams.getUdid()); 33 + PersionalFactor userFactor = userComponent.queryUserPersionalFactor(recallSknParams.getUid(), recallSknParams.getUdid());
35 //3、join获取最终的结果 34 //3、join获取最终的结果
36 List<Integer> brandIds = this.innerJoin(pageFactor.getBrandIds(),userFactor.getBrandIds(),10); 35 List<Integer> brandIds = this.innerJoin(pageFactor.getBrandIds(),userFactor.getBrandIds(),10);
37 List<PersionalFactor.SortPriceArea> sortPriceAreas = this.innerJoin(pageFactor.getSortPriceAreas(),userFactor.getSortPriceAreas(),5); 36 List<PersionalFactor.SortPriceArea> sortPriceAreas = this.innerJoin(pageFactor.getSortPriceAreas(),userFactor.getSortPriceAreas(),5);
1 -package com.yoho.search.recall.scene.request;  
2 -  
3 -import com.yoho.search.recall.scene.models.ParamQueryFilter;  
4 -import com.yoho.search.recall.scene.models.RecallRequest;  
5 -import com.yoho.search.recall.scene.strategy.IStrategy;  
6 -  
7 -public abstract class BaseRecallRequest {  
8 -  
9 - protected RecallRequest buildRecallRequest(ParamQueryFilter paramQueryFilter, IStrategy strategy) {  
10 - return new RecallRequest(paramQueryFilter, strategy);  
11 - }  
12 -  
13 -}