Authored by hugufei

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

@@ -4,15 +4,17 @@ import com.alibaba.fastjson.JSONObject; @@ -4,15 +4,17 @@ import com.alibaba.fastjson.JSONObject;
4 import com.yoho.search.base.utils.CollectionUtils; 4 import com.yoho.search.base.utils.CollectionUtils;
5 import com.yoho.search.base.utils.ISearchConstants; 5 import com.yoho.search.base.utils.ISearchConstants;
6 import com.yoho.search.base.utils.ProductIndexEsField; 6 import com.yoho.search.base.utils.ProductIndexEsField;
  7 +import com.yoho.search.base.utils.Transfer;
7 import com.yoho.search.core.es.model.SearchParam; 8 import com.yoho.search.core.es.model.SearchParam;
8 import com.yoho.search.core.es.model.SearchResult; 9 import com.yoho.search.core.es.model.SearchResult;
9 import com.yoho.search.models.SearchApiResult; 10 import com.yoho.search.models.SearchApiResult;
10 -import com.yoho.search.recall.scene.beans.cache.QueryRecallResultCacheBean; 11 +import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;
11 import com.yoho.search.recall.scene.beans.cache.QueryProductInfoCacheBean; 12 import com.yoho.search.recall.scene.beans.cache.QueryProductInfoCacheBean;
  13 +import com.yoho.search.recall.scene.beans.cache.QueryRecallResultCacheBean;
12 import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper; 14 import com.yoho.search.recall.scene.beans.helper.SortBuilderHelper;
13 -import com.yoho.search.recall.scene.models.*;  
14 -import com.yoho.search.recall.scene.beans.builder.RecallParamsBuilder;  
15 import com.yoho.search.recall.scene.models.RecallParams; 15 import com.yoho.search.recall.scene.models.RecallParams;
  16 +import com.yoho.search.recall.scene.models.RecallResult;
  17 +import com.yoho.search.recall.scene.models.RecallSknInfo;
16 import com.yoho.search.service.base.SearchCommonService; 18 import com.yoho.search.service.base.SearchCommonService;
17 import com.yoho.search.service.helper.SearchCommonHelper; 19 import com.yoho.search.service.helper.SearchCommonHelper;
18 import org.apache.commons.collections.MapUtils; 20 import org.apache.commons.collections.MapUtils;
@@ -73,34 +75,67 @@ public class SceneRecallProductListService { @@ -73,34 +75,67 @@ public class SceneRecallProductListService {
73 } 75 }
74 } 76 }
75 77
  78 + private List<Integer> getProductSknList(List<RecallSknInfo> recallSknInfos){
  79 + List<Integer> productSknList = new ArrayList<>();
  80 + for (RecallSknInfo recallSknInfo:recallSknInfos ){
  81 + productSknList.add(recallSknInfo.getProductSkn());
  82 + }
  83 + return productSknList;
  84 + }
  85 +
76 private List<Map<String, Object>> queryProductList(RecallParams recallParams, RecallResult recallResult, int page, int pageSize) { 86 private List<Map<String, Object>> queryProductList(RecallParams recallParams, RecallResult recallResult, int page, int pageSize) {
77 //1、判断当前页码是否在召回的页码里 87 //1、判断当前页码是否在召回的页码里
78 int recallTotalPage = recallResult.getRecallTotalPage(); 88 int recallTotalPage = recallResult.getRecallTotalPage();
79 //2、在召回结果中则直接根据skn去查询 89 //2、在召回结果中则直接根据skn去查询
80 - List<Integer> productSkns = null; 90 + List<RecallSknInfo> recallSknInfos = null;
81 if(page<=recallTotalPage){ 91 if(page<=recallTotalPage){
82 - productSkns = CollectionUtils.safeSubList(recallResult.getSknList(),(page-1)*pageSize,page*pageSize); 92 + recallSknInfos = CollectionUtils.safeSubList(recallResult.getSknList(),(page-1)*pageSize,page*pageSize);
83 }else{ 93 }else{
84 //3、过滤召回的skn,修改真实页码,执行查询 94 //3、过滤召回的skn,修改真实页码,执行查询
85 - productSkns = this.queryProductSknByFilterSkn(recallParams, recallResult.getSknList(), recallTotalPage-page, pageSize); 95 + recallSknInfos = this.queryProductSknByFilterSkn(recallParams, recallResult.getSknList(), recallTotalPage-page, pageSize);
86 } 96 }
87 - return queryProductInfoCacheBean.queryProductListBySkn(productSkns,productSkns.size()); 97 + //3、获取召回结果的skn
  98 + List<Integer> productSknList = this.getProductSknList(recallSknInfos);
  99 +
  100 + //4、获取商品的返回信息
  101 + List<Map<String, Object>> productInfoList = queryProductInfoCacheBean.queryProductListBySkn(productSknList,productSknList.size());
  102 +
  103 + //5、填充召回类型
  104 + Map<Integer,RecallSknInfo> sknRecallTypeMap = CollectionUtils.toMap(recallSknInfos, new Transfer<RecallSknInfo, Integer>() {
  105 + @Override
  106 + public Integer transfer(RecallSknInfo recallSknInfo) {
  107 + return recallSknInfo.getProductSkn();
  108 + }
  109 + });
  110 + for(Map<String, Object> productInfo: productInfoList){
  111 + int productSkn = MapUtils.getIntValue(productInfo,"product_skn",0);
  112 + RecallSknInfo recallSknInfo = sknRecallTypeMap.get(productSkn);
  113 + if(recallSknInfo==null || recallSknInfo.getRecallType()==null){
  114 + productInfo.put("recall_type","default");
  115 + }else{
  116 + productInfo.put("recall_type",recallSknInfo.getRecallType());
  117 + }
  118 + }
  119 + return productInfoList;
88 } 120 }
89 121
90 /** 122 /**
91 * 过滤掉已召回的skn,并按人气排序 123 * 过滤掉已召回的skn,并按人气排序
92 - * @param notProductSkns 124 + * @param recallSknInfos
93 * @param realPage 125 * @param realPage
94 * @param pageSize 126 * @param pageSize
95 * @return 127 * @return
96 */ 128 */
97 - private List<Integer> queryProductSknByFilterSkn(RecallParams recallParams, List<Integer> notProductSkns, int realPage, int pageSize){ 129 + private List<RecallSknInfo> queryProductSknByFilterSkn(RecallParams recallParams, List<RecallSknInfo> recallSknInfos, int realPage, int pageSize){
98 SearchParam searchParam = new SearchParam(); 130 SearchParam searchParam = new SearchParam();
99 -  
100 //1、设置query 131 //1、设置query
101 searchParam.setQuery(recallParams.getParamQueryFilter().getParamQuery()); 132 searchParam.setQuery(recallParams.getParamQueryFilter().getParamQuery());
102 133
103 //2、设置filter 134 //2、设置filter
  135 + List<Integer> notProductSkns = new ArrayList<>();
  136 + for (RecallSknInfo recallSknInfo:recallSknInfos ){
  137 + notProductSkns.add(recallSknInfo.getProductSkn());
  138 + }
104 BoolQueryBuilder filter = recallParams.getParamQueryFilter().getParamFilter(); 139 BoolQueryBuilder filter = recallParams.getParamQueryFilter().getParamFilter();
105 filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns)); 140 filter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn,notProductSkns));
106 searchParam.setFiter(filter); 141 searchParam.setFiter(filter);
@@ -119,9 +154,10 @@ public class SceneRecallProductListService { @@ -119,9 +154,10 @@ public class SceneRecallProductListService {
119 searchParam.setSortBuilders(sortBuilders); 154 searchParam.setSortBuilders(sortBuilders);
120 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_BASE_INDEX,searchParam); 155 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_BASE_INDEX,searchParam);
121 156
122 - List<Integer> results = new ArrayList<>(); 157 + //6、构造返回结果
  158 + List<RecallSknInfo> results = new ArrayList<>();
123 for (Map<String, Object> product : searchResult.getResultList()) { 159 for (Map<String, Object> product : searchResult.getResultList()) {
124 - results.add(MapUtils.getIntValue(product,ProductIndexEsField.productSkn,0)); 160 + results.add(new RecallSknInfo(MapUtils.getIntValue(product,ProductIndexEsField.productSkn,0),"DEFAULT"));
125 } 161 }
126 return results; 162 return results;
127 } 163 }
@@ -2,10 +2,11 @@ package com.yoho.search.recall.scene.beans.builder; @@ -2,10 +2,11 @@ package com.yoho.search.recall.scene.beans.builder;
2 2
3 import com.yoho.search.base.utils.CollectionUtils; 3 import com.yoho.search.base.utils.CollectionUtils;
4 import com.yoho.search.core.personalized.models.UserPersonalFactorRsp; 4 import com.yoho.search.core.personalized.models.UserPersonalFactorRsp;
5 -import com.yoho.search.recall.scene.models.RecallParams; 5 +import com.yoho.search.recall.scene.beans.strategy.StrategyNameEnum;
6 import com.yoho.search.recall.scene.models.RecallMergerResult; 6 import com.yoho.search.recall.scene.models.RecallMergerResult;
  7 +import com.yoho.search.recall.scene.models.RecallParams;
7 import com.yoho.search.recall.scene.models.RecallResult; 8 import com.yoho.search.recall.scene.models.RecallResult;
8 -import com.yoho.search.recall.scene.beans.strategy.StrategyNameEnum; 9 +import com.yoho.search.recall.scene.models.RecallSknInfo;
9 import com.yoho.search.service.base.ProductListSortKey; 10 import com.yoho.search.service.base.ProductListSortKey;
10 import com.yoho.search.service.base.ProductListSortService; 11 import com.yoho.search.service.base.ProductListSortService;
11 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,10 +24,10 @@ public class RecallResultBuilder { @@ -23,10 +24,10 @@ public class RecallResultBuilder {
23 private ProductListSortService productListSortService; 24 private ProductListSortService productListSortService;
24 25
25 public RecallResult builderRecallResult(RecallMergerResult recallMergerResult, RecallParams param, UserPersonalFactorRsp userPersonalFactorRsp){ 26 public RecallResult builderRecallResult(RecallMergerResult recallMergerResult, RecallParams param, UserPersonalFactorRsp userPersonalFactorRsp){
26 - //1、构造结果中的分页信息 27 + //1、获取总数
27 final long total = recallMergerResult.getTotal(); 28 final long total = recallMergerResult.getTotal();
28 29
29 - //2、获取召回结果中的最大整数页码 30 + //2、获取召回结果中的所有skn
30 List<RecallMergerResult.SknResult> sknResultList = recallMergerResult.getSknList(); 31 List<RecallMergerResult.SknResult> sknResultList = recallMergerResult.getSknList();
31 32
32 //3、计算得分 33 //3、计算得分
@@ -65,14 +66,13 @@ public class RecallResultBuilder { @@ -65,14 +66,13 @@ public class RecallResultBuilder {
65 sknResultList = CollectionUtils.safeSubList(sknResultList,0,recallTotalPage * param.getPageSize()); 66 sknResultList = CollectionUtils.safeSubList(sknResultList,0,recallTotalPage * param.getPageSize());
66 67
67 //8、构造返回结果 68 //8、构造返回结果
68 - List<Integer> sknList = this.getSknList(sknResultList); 69 + List<RecallSknInfo> sknList = this.getSknList(sknResultList);
69 int recallTotal = sknResultList.size(); 70 int recallTotal = sknResultList.size();
70 return new RecallResult(total,recallTotal,recallTotalPage,sknList); 71 return new RecallResult(total,recallTotal,recallTotalPage,sknList);
71 } 72 }
72 73
73 -  
74 private void doCalScore(List<RecallMergerResult.SknResult> sknResultList, UserPersonalFactorRsp userPersonalFactorRsp) { 74 private void doCalScore(List<RecallMergerResult.SknResult> sknResultList, UserPersonalFactorRsp userPersonalFactorRsp) {
75 - String vector = userPersonalFactorRsp.getVector(); 75 + String vector = userPersonalFactorRsp.getVector();//TODO
76 for (RecallMergerResult.SknResult sknResult : sknResultList) { 76 for (RecallMergerResult.SknResult sknResult : sknResultList) {
77 if (sknResult.getRequestTypes().contains(StrategyNameEnum.FIRST_PRODUCT_SKN.name())) { 77 if (sknResult.getRequestTypes().contains(StrategyNameEnum.FIRST_PRODUCT_SKN.name())) {
78 sknResult.setScore(10000d);// firstSkn排第一个 78 sknResult.setScore(10000d);// firstSkn排第一个
@@ -82,10 +82,10 @@ public class RecallResultBuilder { @@ -82,10 +82,10 @@ public class RecallResultBuilder {
82 } 82 }
83 } 83 }
84 84
85 - private List<Integer> getSknList(List<RecallMergerResult.SknResult> sknResultList){  
86 - List<Integer> sknList = new ArrayList<>(); 85 + private List<RecallSknInfo> getSknList(List<RecallMergerResult.SknResult> sknResultList){
  86 + List<RecallSknInfo> sknList = new ArrayList<>();
87 for (RecallMergerResult.SknResult sknResult:sknResultList){ 87 for (RecallMergerResult.SknResult sknResult:sknResultList){
88 - sknList.add(sknResult.getProductSkn()); 88 + sknList.add(new RecallSknInfo(sknResult.getProductSkn(),sknResult.getRequestTypes().get(0)));
89 } 89 }
90 return sknList; 90 return sknList;
91 } 91 }
@@ -10,12 +10,13 @@ public class RecallResult implements Serializable{ @@ -10,12 +10,13 @@ public class RecallResult implements Serializable{
10 private long total; 10 private long total;
11 private int recallTotal; 11 private int recallTotal;
12 private int recallTotalPage; 12 private int recallTotalPage;
13 - private List<Integer> sknList; 13 + private List<RecallSknInfo> sknList;
14 14
15 public RecallResult() { 15 public RecallResult() {
  16 +
16 } 17 }
17 18
18 - public RecallResult(long total, int recallTotal, int recallTotalPage, List<Integer> sknList) { 19 + public RecallResult(long total, int recallTotal, int recallTotalPage, List<RecallSknInfo> sknList) {
19 this.total = total; 20 this.total = total;
20 this.recallTotal = recallTotal; 21 this.recallTotal = recallTotal;
21 this.recallTotalPage = recallTotalPage; 22 this.recallTotalPage = recallTotalPage;
@@ -46,11 +47,12 @@ public class RecallResult implements Serializable{ @@ -46,11 +47,12 @@ public class RecallResult implements Serializable{
46 this.recallTotalPage = recallTotalPage; 47 this.recallTotalPage = recallTotalPage;
47 } 48 }
48 49
49 - public List<Integer> getSknList() { 50 + public List<RecallSknInfo> getSknList() {
50 return sknList; 51 return sknList;
51 } 52 }
52 53
53 - public void setSknList(List<Integer> sknList) { 54 + public void setSknList(List<RecallSknInfo> sknList) {
54 this.sknList = sknList; 55 this.sknList = sknList;
55 } 56 }
  57 +
56 } 58 }
  1 +package com.yoho.search.recall.scene.models;
  2 +
  3 +import java.io.Serializable;
  4 +
  5 +public class RecallSknInfo implements Serializable{
  6 +
  7 + private static final long serialVersionUID = 7041576005343129736L;
  8 +
  9 + private Integer productSkn;
  10 + private String recallType;
  11 +
  12 + public RecallSknInfo() {
  13 + }
  14 +
  15 + public RecallSknInfo(Integer productSkn, String recallType) {
  16 + this.productSkn = productSkn;
  17 + this.recallType = recallType;
  18 + }
  19 +
  20 + public Integer getProductSkn() {
  21 + return productSkn;
  22 + }
  23 +
  24 + public void setProductSkn(Integer productSkn) {
  25 + this.productSkn = productSkn;
  26 + }
  27 +
  28 + public String getRecallType() {
  29 + return recallType;
  30 + }
  31 +
  32 + public void setRecallType(String recallType) {
  33 + this.recallType = recallType;
  34 + }
  35 +}
@@ -51,7 +51,8 @@ public class ProductListSwitchService { @@ -51,7 +51,8 @@ public class ProductListSwitchService {
51 return sortRecallProductListService.productList(paramMap); 51 return sortRecallProductListService.productList(paramMap);
52 } 52 }
53 // 4、全部使用新的召回策略 53 // 4、全部使用新的召回策略
54 - boolean searchPersionalNewStrategyOpen = searchDynamicConfigService.searchPersionalNewStrategyOpen(); 54 + //boolean searchPersionalNewStrategyOpen = searchDynamicConfigService.searchPersionalNewStrategyOpen();
  55 + boolean searchPersionalNewStrategyOpen = true;
55 if (searchPersionalNewStrategyOpen) { 56 if (searchPersionalNewStrategyOpen) {
56 return sceneRecallProductListService.productList(paramMap); 57 return sceneRecallProductListService.productList(paramMap);
57 } 58 }