...
|
...
|
@@ -8,13 +8,13 @@ import com.yoho.search.base.utils.Transfer; |
|
|
import com.yoho.search.core.es.model.SearchParam;
|
|
|
import com.yoho.search.core.es.model.SearchResult;
|
|
|
import com.yoho.search.models.SearchApiResult;
|
|
|
import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;
|
|
|
import com.yoho.search.recall.scene.beans.builder.UserRecallRequestBuilder;
|
|
|
import com.yoho.search.recall.scene.beans.cache.QueryProductInfoCacheBean;
|
|
|
import com.yoho.search.recall.scene.beans.cache.QueryRecallResultCacheBean;
|
|
|
import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
|
|
|
import com.yoho.search.recall.scene.beans.strategy.StrategyNameEnum;
|
|
|
import com.yoho.search.recall.scene.models.req.RecallParamsRequest;
|
|
|
import com.yoho.search.recall.scene.models.req.RecallParamsResponse;
|
|
|
import com.yoho.search.recall.scene.models.req.UserRecallRequest;
|
|
|
import com.yoho.search.recall.scene.models.req.UserRecallResponse;
|
|
|
import com.yoho.search.recall.scene.models.common.RecallSknInfo;
|
|
|
import com.yoho.search.service.base.SearchCommonService;
|
|
|
import com.yoho.search.service.helper.SearchCommonHelper;
|
...
|
...
|
@@ -38,7 +38,7 @@ public class SceneRecallProductListService { |
|
|
private static final Logger RECALL_NEW_LOGGER = LoggerFactory.getLogger("RECALL");
|
|
|
|
|
|
@Autowired
|
|
|
private RecallParamsBuilder recallParamsBuilder;
|
|
|
private UserRecallRequestBuilder userRecallRequestBuilder;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
...
|
...
|
@@ -62,9 +62,9 @@ public class SceneRecallProductListService { |
|
|
return new SearchApiResult().setCode(400).setMessage("分页参数不合法");
|
|
|
}
|
|
|
//2、构造召回相关参数
|
|
|
RecallParamsRequest recallParamsRequest = recallParamsBuilder.buildRecallParams(paramMap, pageSize);
|
|
|
UserRecallRequest userRecallRequest = userRecallRequestBuilder.buildUserRecallRequest(paramMap, pageSize);
|
|
|
//3、执行召回
|
|
|
return this.recallProductList(recallParamsRequest, page);
|
|
|
return this.recallProductList(userRecallRequest, page);
|
|
|
} catch (Exception e) {
|
|
|
RECALL_NEW_LOGGER.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(null).setCode(500).setMessage("Exception");
|
...
|
...
|
@@ -73,45 +73,45 @@ public class SceneRecallProductListService { |
|
|
|
|
|
/**
|
|
|
* 个性化召回列表入口2
|
|
|
* @param recallParamsRequest
|
|
|
* @param userRecallRequest
|
|
|
* @param page
|
|
|
* @return
|
|
|
*/
|
|
|
public SearchApiResult recallProductList(RecallParamsRequest recallParamsRequest, int page) {
|
|
|
public SearchApiResult recallProductList(UserRecallRequest userRecallRequest, int page) {
|
|
|
//1、执行召回
|
|
|
long begin = System.currentTimeMillis();
|
|
|
RecallParamsResponse recallParamsResponse = queryRecallResultCacheBean.queryRecallResult(recallParamsRequest);
|
|
|
UserRecallResponse userRecallResponse = queryRecallResultCacheBean.queryRecallResult(userRecallRequest);
|
|
|
RECALL_NEW_LOGGER.info("RecallProductListService[1]-queryRecallResult,cost is [{}]", System.currentTimeMillis()-begin);
|
|
|
//2、根据召回结果查询商品信息
|
|
|
List<Map<String, Object>> productList = this.queryProductList(recallParamsRequest, recallParamsResponse,page, recallParamsRequest.getPageSize());
|
|
|
List<Map<String, Object>> productList = this.queryProductList(userRecallRequest, userRecallResponse,page, userRecallRequest.getPageSize());
|
|
|
//3、构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", recallParamsResponse.getTotal());
|
|
|
dataMap.put("total", userRecallResponse.getTotal());
|
|
|
dataMap.put("page", page);
|
|
|
dataMap.put("page_size", recallParamsRequest.getPageSize());
|
|
|
dataMap.put("page_total", searchCommonHelper.getTotalPage(recallParamsResponse.getTotal(), recallParamsRequest.getPageSize()));
|
|
|
dataMap.put("page_size", userRecallRequest.getPageSize());
|
|
|
dataMap.put("page_total", searchCommonHelper.getTotalPage(userRecallResponse.getTotal(), userRecallRequest.getPageSize()));
|
|
|
dataMap.put("product_list", productList);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据召回结果查询商品列表
|
|
|
* @param recallParamsRequest
|
|
|
* @param recallParamsResponse
|
|
|
* @param userRecallRequest
|
|
|
* @param userRecallResponse
|
|
|
* @param page
|
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
private List<Map<String, Object>> queryProductList(RecallParamsRequest recallParamsRequest, RecallParamsResponse recallParamsResponse, int page, int pageSize) {
|
|
|
private List<Map<String, Object>> queryProductList(UserRecallRequest userRecallRequest, UserRecallResponse userRecallResponse, int page, int pageSize) {
|
|
|
//1、判断当前页码是否在召回的页码里
|
|
|
int recallTotalPage = recallParamsResponse.getRecallTotalPage();
|
|
|
int recallTotalPage = userRecallResponse.getRecallTotalPage();
|
|
|
//2、在召回结果中则直接根据skn去查询
|
|
|
long begin = System.currentTimeMillis();
|
|
|
List<RecallSknInfo> recallSknInfos = null;
|
|
|
if(page<=recallTotalPage){
|
|
|
recallSknInfos = CollectionUtils.safeSubList(recallParamsResponse.getSknList(),(page-1)*pageSize,page*pageSize);
|
|
|
recallSknInfos = CollectionUtils.safeSubList(userRecallResponse.getSknList(),(page-1)*pageSize,page*pageSize);
|
|
|
}else{
|
|
|
recallSknInfos = this.queryProductSknByFilterSkn(recallParamsRequest, recallParamsResponse.getSknList(), page-recallTotalPage, pageSize);
|
|
|
recallSknInfos = this.queryProductSknByFilterSkn(userRecallRequest, userRecallResponse.getSknList(), page-recallTotalPage, pageSize);
|
|
|
}
|
|
|
RECALL_NEW_LOGGER.info("SceneRecallProductListService[2].getRecallSknInfos,cost is [{}]", System.currentTimeMillis()-begin);
|
|
|
|
...
|
...
|
@@ -149,18 +149,18 @@ public class SceneRecallProductListService { |
|
|
* @param pageSize
|
|
|
* @return
|
|
|
*/
|
|
|
private List<RecallSknInfo> queryProductSknByFilterSkn(RecallParamsRequest recallParamsRequest, List<RecallSknInfo> recallSknInfos, int realPage, int pageSize){
|
|
|
private List<RecallSknInfo> queryProductSknByFilterSkn(UserRecallRequest userRecallRequest, List<RecallSknInfo> recallSknInfos, int realPage, int pageSize){
|
|
|
long begin = System.currentTimeMillis();
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
//1、设置query
|
|
|
searchParam.setQuery(recallParamsRequest.getParamQueryFilter().getParamQuery());
|
|
|
searchParam.setQuery(userRecallRequest.getParamQueryFilter().getParamQuery());
|
|
|
|
|
|
//2、设置filter
|
|
|
List<Integer> notProductSkns = new ArrayList<>();
|
|
|
for (RecallSknInfo recallSknInfo:recallSknInfos ){
|
|
|
notProductSkns.add(recallSknInfo.getProductSkn());
|
|
|
}
|
|
|
BoolQueryBuilder filter = recallParamsRequest.getParamQueryFilter().getParamFilter();
|
|
|
BoolQueryBuilder filter = userRecallRequest.getParamQueryFilter().getParamFilter();
|
|
|
filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns));
|
|
|
searchParam.setFiter(filter);
|
|
|
|
...
|
...
|
|