|
|
package com.yoho.search.recall.scene;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.CollectionUtils;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
|
|
import com.yoho.search.core.es.model.SearchParam;
|
...
|
...
|
@@ -9,13 +10,7 @@ import com.yoho.search.models.SearchApiResult; |
|
|
import com.yoho.search.recall.scene.component.*;
|
|
|
import com.yoho.search.recall.scene.helper.SortBuilderHelper;
|
|
|
import com.yoho.search.recall.scene.models.*;
|
|
|
import com.yoho.search.recall.scene.models.CacheRecallRequestResponse;
|
|
|
import com.yoho.search.recall.scene.persional.PersionalFactor;
|
|
|
import com.yoho.search.recall.scene.persional.RecallPersionalService;
|
|
|
import com.yoho.search.recall.scene.request.BatchRequestsBuilder;
|
|
|
import com.yoho.search.recall.scene.request.BatchResponseBuilder;
|
|
|
import com.yoho.search.recall.scene.request.RecallParamsBuilder;
|
|
|
import com.yoho.search.recall.scene.request.RecallResultBuilder;
|
|
|
import com.yoho.search.recall.scene.builder.request.RecallParamsBuilder;
|
|
|
import com.yoho.search.service.base.SearchCommonService;
|
|
|
import com.yoho.search.service.base.index.ProductIndexBaseService;
|
|
|
import com.yoho.search.service.helper.SearchCommonHelper;
|
...
|
...
|
@@ -40,16 +35,6 @@ public class SceneRecallService { |
|
|
@Autowired
|
|
|
private RecallParamsBuilder recallParamsBuilder;
|
|
|
@Autowired
|
|
|
private RecallPersionalService recallPersionalService;
|
|
|
@Autowired
|
|
|
private BatchRequestsBuilder batchRequestsBuilder;
|
|
|
@Autowired
|
|
|
private BatchRecallComponent bacthRecallComponent;
|
|
|
@Autowired
|
|
|
private BatchResponseBuilder batchResponseBuilder;
|
|
|
@Autowired
|
|
|
private RecallResultBuilder recallResultBuilder;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private ProductIndexBaseService productIndexBaseService;
|
...
|
...
|
@@ -57,6 +42,9 @@ public class SceneRecallService { |
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private BacthSknInfoComponent bacthSknInfoComponent;
|
|
|
@Autowired
|
|
|
private RecallService recallService;
|
|
|
|
|
|
|
|
|
public SearchApiResult sceneRecall(Map<String, String> paramMap) {
|
|
|
try {
|
...
|
...
|
@@ -67,19 +55,17 @@ public class SceneRecallService { |
|
|
return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
|
|
|
}
|
|
|
//2、构造召回相关参数
|
|
|
RecallParams recallParams = recallParamsBuilder.buildRecallParams(paramMap);
|
|
|
//3、获取个性化因子
|
|
|
PersionalFactor persionalFactor = recallPersionalService.queryPersionalFactor(recallParams);
|
|
|
//4、执行召回
|
|
|
RecallResult recallResult = this.doRecall(recallParams, persionalFactor);
|
|
|
//5、根据召回结果查询商品信息
|
|
|
List<Map<String, Object>> productList = this.queryProductList(recallParams,recallResult);
|
|
|
RecallSknParams recallSknParams = recallParamsBuilder.buildRecallParams(paramMap);
|
|
|
//3、执行召回
|
|
|
RecallSknResult recallSknResult = recallService.getRecallSknResult(recallSknParams);
|
|
|
//4、根据召回结果查询商品信息
|
|
|
List<Map<String, Object>> productList = this.queryProductList(recallSknParams, recallSknResult,page,pageSize);
|
|
|
//6、构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", recallResult.getTotal());
|
|
|
dataMap.put("page", recallParams.getPage());
|
|
|
dataMap.put("page_size", recallParams.getPageSize());
|
|
|
dataMap.put("page_total", searchCommonHelper.getTotalPage(recallResult.getTotal(), recallParams.getPageSize()));
|
|
|
dataMap.put("total", recallSknResult.getTotal());
|
|
|
dataMap.put("page", page);
|
|
|
dataMap.put("page_size", recallSknParams.getPageSize());
|
|
|
dataMap.put("page_total", searchCommonHelper.getTotalPage(recallSknResult.getTotal(), recallSknParams.getPageSize()));
|
|
|
dataMap.put("product_list", productList);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
} catch (Exception e) {
|
...
|
...
|
@@ -88,46 +74,31 @@ public class SceneRecallService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 召回入口
|
|
|
*
|
|
|
* @param param
|
|
|
* @param persionalFactor
|
|
|
* @return
|
|
|
*/
|
|
|
private RecallResult doRecall(RecallParams param, PersionalFactor persionalFactor) {
|
|
|
//1、构造请求
|
|
|
List<RecallRequest> batchRequests = batchRequestsBuilder.buildBatchRequests(param, persionalFactor);
|
|
|
//2、批量召回
|
|
|
List<CacheRecallRequestResponse> requestResponses = bacthRecallComponent.batchRecallAndCache(batchRequests);
|
|
|
//3、获取skn列表[去重]
|
|
|
RecallResponseBatch recallResponseBatch = batchResponseBuilder.buildRecallResponseBatch(requestResponses);
|
|
|
//4、构造真实结果[排序,截取skn]
|
|
|
RecallResult recallResult = recallResultBuilder.builderRecallResult(recallResponseBatch, param, persionalFactor);
|
|
|
return recallResult;
|
|
|
}
|
|
|
|
|
|
private List<Map<String, Object>> queryProductList(RecallParams recallParams,RecallResult recallResult) {
|
|
|
//1、
|
|
|
List<Integer> productSkns = recallResult.getSknList();
|
|
|
if (productSkns != null && !productSkns.isEmpty()) {
|
|
|
private List<Map<String, Object>> queryProductList(RecallSknParams recallSknParams, RecallSknResult recallSknResult,int page,int pageSize) {
|
|
|
//1、判断当前页码是否在召回的页码里
|
|
|
int recallTotalPage = recallSknResult.getRecallTotalPage();
|
|
|
//2、在召回结果中则直接根据skn去查询
|
|
|
if(page<=recallTotalPage){
|
|
|
List<Integer> productSkns = CollectionUtils.safeSubList(recallSknResult.getSknList(),(page-1)*pageSize,page*pageSize);
|
|
|
return bacthSknInfoComponent.queryProductListBySkn(productSkns,productSkns.size());
|
|
|
}else{
|
|
|
return this.queryProductByFilterSkn(recallResult.getNotProductSkn(),recallResult.getRealPage(),recallParams.getPageSize());
|
|
|
}
|
|
|
//3、过滤召回的skn,修改真实页码,执行查询
|
|
|
int realPage = page - recallTotalPage;
|
|
|
return this.queryProductByFilterSkn(recallSknResult.getSknList(), realPage, pageSize);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 过滤掉已召回的skn,并按人气排序
|
|
|
* @param notProductSkns
|
|
|
* @param page
|
|
|
* @param realPage
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Map<String, Object>> queryProductByFilterSkn(List<Integer> notProductSkns,int page,int pageSize){
|
|
|
private List<Map<String, Object>> queryProductByFilterSkn(List<Integer> notProductSkns,int realPage,int pageSize){
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
//设置分页参数
|
|
|
searchParam.setOffset((page-1)*pageSize);
|
|
|
searchParam.setOffset((realPage-1)*pageSize);
|
|
|
searchParam.setSize(pageSize);
|
|
|
|
|
|
//设置filter
|
...
|
...
|
@@ -147,8 +118,4 @@ public class SceneRecallService { |
|
|
return productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|