Authored by hugufei

走召回逻辑时列表返回召回类型

... ... @@ -4,15 +4,17 @@ 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.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.cache.QueryRecallResultCacheBean;
import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;
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.models.*;
import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;
import com.yoho.search.recall.scene.models.RecallParams;
import com.yoho.search.recall.scene.models.RecallResult;
import com.yoho.search.recall.scene.models.RecallSknInfo;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.helper.SearchCommonHelper;
import org.apache.commons.collections.MapUtils;
... ... @@ -73,34 +75,67 @@ public class SceneRecallProductListService {
}
}
private List<Integer> getProductSknList(List<RecallSknInfo> recallSknInfos){
List<Integer> productSknList = new ArrayList<>();
for (RecallSknInfo recallSknInfo:recallSknInfos ){
productSknList.add(recallSknInfo.getProductSkn());
}
return productSknList;
}
private List<Map<String, Object>> queryProductList(RecallParams recallParams, RecallResult recallResult, int page, int pageSize) {
//1、判断当前页码是否在召回的页码里
int recallTotalPage = recallResult.getRecallTotalPage();
//2、在召回结果中则直接根据skn去查询
List<Integer> productSkns = null;
List<RecallSknInfo> recallSknInfos = null;
if(page<=recallTotalPage){
productSkns = CollectionUtils.safeSubList(recallResult.getSknList(),(page-1)*pageSize,page*pageSize);
recallSknInfos = CollectionUtils.safeSubList(recallResult.getSknList(),(page-1)*pageSize,page*pageSize);
}else{
//3、过滤召回的skn,修改真实页码,执行查询
productSkns = this.queryProductSknByFilterSkn(recallParams, recallResult.getSknList(), recallTotalPage-page, pageSize);
recallSknInfos = this.queryProductSknByFilterSkn(recallParams, recallResult.getSknList(), recallTotalPage-page, pageSize);
}
return queryProductInfoCacheBean.queryProductListBySkn(productSkns,productSkns.size());
//3、获取召回结果的skn
List<Integer> productSknList = this.getProductSknList(recallSknInfos);
//4、获取商品的返回信息
List<Map<String, Object>> productInfoList = queryProductInfoCacheBean.queryProductListBySkn(productSknList,productSknList.size());
//5、填充召回类型
Map<Integer,RecallSknInfo> sknRecallTypeMap = CollectionUtils.toMap(recallSknInfos, new Transfer<RecallSknInfo, Integer>() {
@Override
public Integer transfer(RecallSknInfo recallSknInfo) {
return recallSknInfo.getProductSkn();
}
});
for(Map<String, Object> productInfo: productInfoList){
int productSkn = MapUtils.getIntValue(productInfo,"product_skn",0);
RecallSknInfo recallSknInfo = sknRecallTypeMap.get(productSkn);
if(recallSknInfo==null || recallSknInfo.getRecallType()==null){
productInfo.put("recall_type","default");
}else{
productInfo.put("recall_type",recallSknInfo.getRecallType());
}
}
return productInfoList;
}
/**
* 过滤掉已召回的skn,并按人气排序
* @param notProductSkns
* @param recallSknInfos
* @param realPage
* @param pageSize
* @return
*/
private List<Integer> queryProductSknByFilterSkn(RecallParams recallParams, List<Integer> notProductSkns, int realPage, int pageSize){
private List<RecallSknInfo> queryProductSknByFilterSkn(RecallParams recallParams, List<RecallSknInfo> recallSknInfos, int realPage, int pageSize){
SearchParam searchParam = new SearchParam();
//1、设置query
searchParam.setQuery(recallParams.getParamQueryFilter().getParamQuery());
//2、设置filter
List<Integer> notProductSkns = new ArrayList<>();
for (RecallSknInfo recallSknInfo:recallSknInfos ){
notProductSkns.add(recallSknInfo.getProductSkn());
}
BoolQueryBuilder filter = recallParams.getParamQueryFilter().getParamFilter();
filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns));
searchParam.setFiter(filter);
... ... @@ -119,9 +154,10 @@ public class SceneRecallProductListService {
searchParam.setSortBuilders(sortBuilders);
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_BASE_INDEX,searchParam);
List<Integer> results = new ArrayList<>();
//6、构造返回结果
List<RecallSknInfo> results = new ArrayList<>();
for (Map<String, Object> product : searchResult.getResultList()) {
results.add(MapUtils.getIntValue(product,ProductIndexEsField.productSkn,0));
results.add(new RecallSknInfo(MapUtils.getIntValue(product,ProductIndexEsField.productSkn,0),"DEFAULT"));
}
return results;
}
... ...
... ... @@ -2,10 +2,11 @@ package com.yoho.search.recall.scene.beans.builder;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.core.personalized.models.UserPersonalFactorRsp;
import com.yoho.search.recall.scene.models.RecallParams;
import com.yoho.search.recall.scene.beans.strategy.StrategyNameEnum;
import com.yoho.search.recall.scene.models.RecallMergerResult;
import com.yoho.search.recall.scene.models.RecallParams;
import com.yoho.search.recall.scene.models.RecallResult;
import com.yoho.search.recall.scene.beans.strategy.StrategyNameEnum;
import com.yoho.search.recall.scene.models.RecallSknInfo;
import com.yoho.search.service.base.ProductListSortKey;
import com.yoho.search.service.base.ProductListSortService;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -23,10 +24,10 @@ public class RecallResultBuilder {
private ProductListSortService productListSortService;
public RecallResult builderRecallResult(RecallMergerResult recallMergerResult, RecallParams param, UserPersonalFactorRsp userPersonalFactorRsp){
//1、构造结果中的分页信息
//1、获取总数
final long total = recallMergerResult.getTotal();
//2、获取召回结果中的最大整数页码
//2、获取召回结果中的所有skn
List<RecallMergerResult.SknResult> sknResultList = recallMergerResult.getSknList();
//3、计算得分
... ... @@ -65,14 +66,13 @@ public class RecallResultBuilder {
sknResultList = CollectionUtils.safeSubList(sknResultList,0,recallTotalPage * param.getPageSize());
//8、构造返回结果
List<Integer> sknList = this.getSknList(sknResultList);
List<RecallSknInfo> sknList = this.getSknList(sknResultList);
int recallTotal = sknResultList.size();
return new RecallResult(total,recallTotal,recallTotalPage,sknList);
}
private void doCalScore(List<RecallMergerResult.SknResult> sknResultList, UserPersonalFactorRsp userPersonalFactorRsp) {
String vector = userPersonalFactorRsp.getVector();
String vector = userPersonalFactorRsp.getVector();//TODO
for (RecallMergerResult.SknResult sknResult : sknResultList) {
if (sknResult.getRequestTypes().contains(StrategyNameEnum.FIRST_PRODUCT_SKN.name())) {
sknResult.setScore(10000d);// firstSkn排第一个
... ... @@ -82,10 +82,10 @@ public class RecallResultBuilder {
}
}
private List<Integer> getSknList(List<RecallMergerResult.SknResult> sknResultList){
List<Integer> sknList = new ArrayList<>();
private List<RecallSknInfo> getSknList(List<RecallMergerResult.SknResult> sknResultList){
List<RecallSknInfo> sknList = new ArrayList<>();
for (RecallMergerResult.SknResult sknResult:sknResultList){
sknList.add(sknResult.getProductSkn());
sknList.add(new RecallSknInfo(sknResult.getProductSkn(),sknResult.getRequestTypes().get(0)));
}
return sknList;
}
... ...
... ... @@ -10,12 +10,13 @@ public class RecallResult implements Serializable{
private long total;
private int recallTotal;
private int recallTotalPage;
private List<Integer> sknList;
private List<RecallSknInfo> sknList;
public RecallResult() {
}
public RecallResult(long total, int recallTotal, int recallTotalPage, List<Integer> sknList) {
public RecallResult(long total, int recallTotal, int recallTotalPage, List<RecallSknInfo> sknList) {
this.total = total;
this.recallTotal = recallTotal;
this.recallTotalPage = recallTotalPage;
... ... @@ -46,11 +47,12 @@ public class RecallResult implements Serializable{
this.recallTotalPage = recallTotalPage;
}
public List<Integer> getSknList() {
public List<RecallSknInfo> getSknList() {
return sknList;
}
public void setSknList(List<Integer> sknList) {
public void setSknList(List<RecallSknInfo> sknList) {
this.sknList = sknList;
}
}
... ...
package com.yoho.search.recall.scene.models;
import java.io.Serializable;
public class RecallSknInfo implements Serializable{
private static final long serialVersionUID = 7041576005343129736L;
private Integer productSkn;
private String recallType;
public RecallSknInfo() {
}
public RecallSknInfo(Integer productSkn, String recallType) {
this.productSkn = productSkn;
this.recallType = recallType;
}
public Integer getProductSkn() {
return productSkn;
}
public void setProductSkn(Integer productSkn) {
this.productSkn = productSkn;
}
public String getRecallType() {
return recallType;
}
public void setRecallType(String recallType) {
this.recallType = recallType;
}
}
... ...
... ... @@ -51,7 +51,8 @@ public class ProductListSwitchService {
return sortRecallProductListService.productList(paramMap);
}
// 4、全部使用新的召回策略
boolean searchPersionalNewStrategyOpen = searchDynamicConfigService.searchPersionalNewStrategyOpen();
//boolean searchPersionalNewStrategyOpen = searchDynamicConfigService.searchPersionalNewStrategyOpen();
boolean searchPersionalNewStrategyOpen = true;
if (searchPersionalNewStrategyOpen) {
return sceneRecallProductListService.productList(paramMap);
}
... ...