Authored by hugufei

品类页召回日志优化

@@ -18,6 +18,7 @@ import org.elasticsearch.search.sort.SortOrder; @@ -18,6 +18,7 @@ import org.elasticsearch.search.sort.SortOrder;
18 import org.slf4j.Logger; 18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory; 19 import org.slf4j.LoggerFactory;
20 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
  21 +import org.springframework.core.NamedThreadLocal;
21 22
22 import com.alibaba.fastjson.JSON; 23 import com.alibaba.fastjson.JSON;
23 import com.alibaba.fastjson.JSONObject; 24 import com.alibaba.fastjson.JSONObject;
@@ -29,6 +30,7 @@ import com.yoho.search.core.es.model.SearchParam; @@ -29,6 +30,7 @@ import com.yoho.search.core.es.model.SearchParam;
29 import com.yoho.search.core.es.model.SearchResult; 30 import com.yoho.search.core.es.model.SearchResult;
30 import com.yoho.search.service.base.SearchCacheService; 31 import com.yoho.search.service.base.SearchCacheService;
31 import com.yoho.search.service.base.SearchCommonService; 32 import com.yoho.search.service.base.SearchCommonService;
  33 +import com.yoho.search.service.helper.SearchCommonHelper;
32 import com.yoho.search.service.helper.SearchServiceHelper; 34 import com.yoho.search.service.helper.SearchServiceHelper;
33 import com.yoho.search.service.scene.recall.model.RecallProductSknList; 35 import com.yoho.search.service.scene.recall.model.RecallProductSknList;
34 import com.yoho.search.service.scene.recall.model.RecallResult; 36 import com.yoho.search.service.scene.recall.model.RecallResult;
@@ -39,7 +41,9 @@ import com.yoho.search.service.scene.recall.type.RecallType; @@ -39,7 +41,9 @@ import com.yoho.search.service.scene.recall.type.RecallType;
39 41
40 public abstract class AbstractRecallService { 42 public abstract class AbstractRecallService {
41 43
42 - private static final Logger logger = LoggerFactory.getLogger("RECALL"); 44 + protected static final Logger RECALL_LOGGER = LoggerFactory.getLogger("RECALL");
  45 +
  46 + private static final ThreadLocal<Boolean> logEnableThreadLocal = new NamedThreadLocal<Boolean>("RECALL USER LOG ENABLE");
43 47
44 @Autowired 48 @Autowired
45 private SearchCommonService searchCommonService; 49 private SearchCommonService searchCommonService;
@@ -49,6 +53,8 @@ public abstract class AbstractRecallService { @@ -49,6 +53,8 @@ public abstract class AbstractRecallService {
49 private SearchCacheService searchCacheService; 53 private SearchCacheService searchCacheService;
50 @Autowired 54 @Autowired
51 private SearchCacheFactory searchCacheFactory; 55 private SearchCacheFactory searchCacheFactory;
  56 + @Autowired
  57 + private SearchCommonHelper searchCommonHelper;
52 58
53 private SearchCache searchCache; 59 private SearchCache searchCache;
54 60
@@ -57,6 +63,29 @@ public abstract class AbstractRecallService { @@ -57,6 +63,29 @@ public abstract class AbstractRecallService {
57 searchCache = searchCacheFactory.getRecallCache(); 63 searchCache = searchCacheFactory.getRecallCache();
58 } 64 }
59 65
  66 + protected void setLogEnableThreadLocal(Map<String, String> paramMap) {
  67 + int uid = searchCommonHelper.getUid(paramMap);
  68 + if (uid == 13420925) {
  69 + logEnableThreadLocal.set(true);
  70 + } else {
  71 + logEnableThreadLocal.set(false);
  72 + }
  73 + }
  74 +
  75 + protected void removelogEnableThreadLocal() {
  76 + logEnableThreadLocal.remove();
  77 + }
  78 +
  79 + protected void doLogInfo(String format, Object... arguments) {
  80 + if (logEnableThreadLocal.get() != null && logEnableThreadLocal.get().booleanValue()) {
  81 + RECALL_LOGGER.info(format, arguments);
  82 + }
  83 + }
  84 +
  85 + protected void doLogError(String msg, Throwable t) {
  86 + RECALL_LOGGER.error(msg, t);
  87 + }
  88 +
60 private List<SearchParam> getSearchpaParams(List<RecallSearchParam> recallSearchParams) { 89 private List<SearchParam> getSearchpaParams(List<RecallSearchParam> recallSearchParams) {
61 List<SearchParam> results = new ArrayList<SearchParam>(); 90 List<SearchParam> results = new ArrayList<SearchParam>();
62 for (RecallSearchParam recallSearchParam : recallSearchParams) { 91 for (RecallSearchParam recallSearchParam : recallSearchParams) {
@@ -75,12 +104,12 @@ public abstract class AbstractRecallService { @@ -75,12 +104,12 @@ public abstract class AbstractRecallService {
75 long begin = System.currentTimeMillis(); 104 long begin = System.currentTimeMillis();
76 // 1、获取召回策略 105 // 1、获取召回策略
77 List<IRecallStrategy> recallStrategys = this.getRecallStrategys(paramMap); 106 List<IRecallStrategy> recallStrategys = this.getRecallStrategys(paramMap);
78 - logger.info("[func=getRecallStrategys][cost={}ms]", System.currentTimeMillis() - begin); 107 + this.doLogInfo("[func=getRecallStrategys][cost={}ms]", System.currentTimeMillis() - begin);
79 108
80 // 2、获取召回参数 109 // 2、获取召回参数
81 begin = System.currentTimeMillis(); 110 begin = System.currentTimeMillis();
82 List<RecallSearchParam> recallSearchParams = this.getRecallSearchParams(paramMap, recallStrategys); 111 List<RecallSearchParam> recallSearchParams = this.getRecallSearchParams(paramMap, recallStrategys);
83 - logger.info("[func=getRecallSearchParams][cost={}ms]", System.currentTimeMillis() - begin); 112 + this.doLogInfo("[func=getRecallSearchParams][cost={}ms]", System.currentTimeMillis() - begin);
84 113
85 // 3、缓存中获取 114 // 3、缓存中获取
86 List<SearchParam> searchParams = this.getSearchpaParams(recallSearchParams); 115 List<SearchParam> searchParams = this.getSearchpaParams(recallSearchParams);
@@ -92,26 +121,26 @@ public abstract class AbstractRecallService { @@ -92,26 +121,26 @@ public abstract class AbstractRecallService {
92 // 4、查询 121 // 4、查询
93 begin = System.currentTimeMillis(); 122 begin = System.currentTimeMillis();
94 RecallResult recallResult = this.queryRecallResult(recallSearchParams); 123 RecallResult recallResult = this.queryRecallResult(recallSearchParams);
95 - logger.info("[func=queryRecallResult][cost={}ms]", System.currentTimeMillis() - begin); 124 + this.doLogInfo("[func=queryRecallResult][cost={}ms][info is {} ]", System.currentTimeMillis() - begin, recallResult.getRecallSearchResult());
96 125
97 // 5、从兜底策略中获取总数 126 // 5、从兜底策略中获取总数
98 long total = this.getTotalFromRecallResult(recallResult); 127 long total = this.getTotalFromRecallResult(recallResult);
99 128
100 - // 6、粗排 129 + // 6、粗排-去重
101 begin = System.currentTimeMillis(); 130 begin = System.currentTimeMillis();
102 recallResult = this.doSketchyRank(paramMap, recallResult); 131 recallResult = this.doSketchyRank(paramMap, recallResult);
103 - logger.info("[func=doSketchyRank][cost={}ms]", System.currentTimeMillis() - begin); 132 + this.doLogInfo("[func=doSketchyRank][total={}][cost={}ms]", recallResult.getProductList().size(), System.currentTimeMillis() - begin);
104 133
105 - // 7、精排 134 + // 7、精排-品牌打散
106 begin = System.currentTimeMillis(); 135 begin = System.currentTimeMillis();
107 recallResult = this.doCarefulRank(paramMap, recallResult); 136 recallResult = this.doCarefulRank(paramMap, recallResult);
108 - logger.info("[func=doCarefulRank][cost={}ms]", System.currentTimeMillis() - begin); 137 + this.doLogInfo("[func=doCarefulRank][total={}][cost={}ms]", recallResult.getProductList().size(), System.currentTimeMillis() - begin);
109 138
110 - // 8、重排 139 + // 8、重排-处理firstSkn和直通车
111 begin = System.currentTimeMillis(); 140 begin = System.currentTimeMillis();
112 recallResult = this.doReRank(paramMap, recallResult); 141 recallResult = this.doReRank(paramMap, recallResult);
113 - logger.info("[func=doReRank][cost={}ms]", System.currentTimeMillis() - begin);  
114 - 142 + this.doLogInfo("[func=doReRank][total=][cost={}ms]", recallResult.getProductList().size(), System.currentTimeMillis() - begin);
  143 +
115 // 9、构造返回结果 144 // 9、构造返回结果
116 begin = System.currentTimeMillis(); 145 begin = System.currentTimeMillis();
117 List<Integer> productSknList = new ArrayList<Integer>(); 146 List<Integer> productSknList = new ArrayList<Integer>();
@@ -153,7 +182,7 @@ public abstract class AbstractRecallService { @@ -153,7 +182,7 @@ public abstract class AbstractRecallService {
153 // 3、返回结果 182 // 3、返回结果
154 return recallSearchParams; 183 return recallSearchParams;
155 } catch (Exception e) { 184 } catch (Exception e) {
156 - logger.error(e.getMessage(), e); 185 + this.doLogError(e.getMessage(), e);
157 } 186 }
158 return new ArrayList<RecallSearchParam>(); 187 return new ArrayList<RecallSearchParam>();
159 } 188 }
@@ -171,7 +200,7 @@ public abstract class AbstractRecallService { @@ -171,7 +200,7 @@ public abstract class AbstractRecallService {
171 searchParams.add(recallSearchParam.getSearchParam()); 200 searchParams.add(recallSearchParam.getSearchParam());
172 } 201 }
173 List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams); 202 List<SearchResult> searchResults = searchCommonService.doMutiSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParams);
174 - logger.info("doMutiSearch cost is:[{}]", System.currentTimeMillis() - begin); 203 + this.doLogInfo("doMutiSearch cost is:[{}]", System.currentTimeMillis() - begin);
175 List<RecallSearchResult> recallSearchResults = new ArrayList<RecallSearchResult>(); 204 List<RecallSearchResult> recallSearchResults = new ArrayList<RecallSearchResult>();
176 for (int i = 0; i < recallSearchParams.size(); i++) { 205 for (int i = 0; i < recallSearchParams.size(); i++) {
177 recallSearchResults.add(new RecallSearchResult(recallSearchParams.get(i).getRecallType(), searchResults.get(i))); 206 recallSearchResults.add(new RecallSearchResult(recallSearchParams.get(i).getRecallType(), searchResults.get(i)));
@@ -2,6 +2,7 @@ package com.yoho.search.service.scene.recall; @@ -2,6 +2,7 @@ package com.yoho.search.service.scene.recall;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.Arrays; 4 import java.util.Arrays;
  5 +import java.util.Collections;
5 import java.util.HashMap; 6 import java.util.HashMap;
6 import java.util.HashSet; 7 import java.util.HashSet;
7 import java.util.Iterator; 8 import java.util.Iterator;
@@ -20,8 +21,6 @@ import org.elasticsearch.script.ScriptType; @@ -20,8 +21,6 @@ import org.elasticsearch.script.ScriptType;
20 import org.elasticsearch.search.sort.SortBuilder; 21 import org.elasticsearch.search.sort.SortBuilder;
21 import org.elasticsearch.search.sort.SortBuilders; 22 import org.elasticsearch.search.sort.SortBuilders;
22 import org.elasticsearch.search.sort.SortOrder; 23 import org.elasticsearch.search.sort.SortOrder;
23 -import org.slf4j.Logger;  
24 -import org.slf4j.LoggerFactory;  
25 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
26 import org.springframework.stereotype.Service; 25 import org.springframework.stereotype.Service;
27 26
@@ -42,6 +41,7 @@ import com.yoho.search.service.base.SearchCommonService; @@ -42,6 +41,7 @@ import com.yoho.search.service.base.SearchCommonService;
42 import com.yoho.search.service.base.SearchDynamicConfigService; 41 import com.yoho.search.service.base.SearchDynamicConfigService;
43 import com.yoho.search.service.base.SearchRequestParams; 42 import com.yoho.search.service.base.SearchRequestParams;
44 import com.yoho.search.service.base.index.ProductIndexBaseService; 43 import com.yoho.search.service.base.index.ProductIndexBaseService;
  44 +import com.yoho.search.service.helper.SearchCommonHelper;
45 import com.yoho.search.service.helper.SearchParamHelper; 45 import com.yoho.search.service.helper.SearchParamHelper;
46 import com.yoho.search.service.helper.SearchServiceHelper; 46 import com.yoho.search.service.helper.SearchServiceHelper;
47 import com.yoho.search.service.helper.SearchSortHelper; 47 import com.yoho.search.service.helper.SearchSortHelper;
@@ -64,8 +64,6 @@ import com.yoho.search.service.service.IProductIndexService; @@ -64,8 +64,6 @@ import com.yoho.search.service.service.IProductIndexService;
64 @Service 64 @Service
65 public class SortRecallSceneService extends AbstractRecallService { 65 public class SortRecallSceneService extends AbstractRecallService {
66 66
67 - private static final Logger logger = LoggerFactory.getLogger("RECALL");  
68 -  
69 @Autowired 67 @Autowired
70 private SearchCacheService searchCacheService; 68 private SearchCacheService searchCacheService;
71 @Autowired 69 @Autowired
@@ -86,6 +84,8 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -86,6 +84,8 @@ public class SortRecallSceneService extends AbstractRecallService {
86 private BigDataRedisService bigDataRedisService; 84 private BigDataRedisService bigDataRedisService;
87 @Autowired 85 @Autowired
88 private ProductListSortService productListSortService; 86 private ProductListSortService productListSortService;
  87 + @Autowired
  88 + private SearchCommonHelper searchCommonHelper;
89 89
90 /** 90 /**
91 * @品类页商品召回接口 91 * @品类页商品召回接口
@@ -119,19 +119,22 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -119,19 +119,22 @@ public class SortRecallSceneService extends AbstractRecallService {
119 */ 119 */
120 public SearchApiResult productList(Map<String, String> paramMap) { 120 public SearchApiResult productList(Map<String, String> paramMap) {
121 try { 121 try {
122 - // 1)验证查询条数 122 + // 0)日志打印检查
  123 + super.setLogEnableThreadLocal(paramMap);
  124 +
  125 + // 1)验证查询条数
123 int page = this.getPage(paramMap); 126 int page = this.getPage(paramMap);
124 int pageSize = this.getPageSize(paramMap); 127 int pageSize = this.getPageSize(paramMap);
125 128
126 // 2)获取商品列表 129 // 2)获取商品列表
127 long begin = System.currentTimeMillis(); 130 long begin = System.currentTimeMillis();
128 RecallProductInfoList recallProductInfoList = this.queryRecallProductInfoList(paramMap, page, pageSize); 131 RecallProductInfoList recallProductInfoList = this.queryRecallProductInfoList(paramMap, page, pageSize);
129 - logger.info("[func1=SortRecallSceneService.queryRealProductList][cost={}]", System.currentTimeMillis() - begin); 132 + super.doLogInfo("[func1=SortRecallSceneService.queryRealProductList][cost={}]", System.currentTimeMillis() - begin);
130 133
131 // 3)填充变价计划,并做品牌打散 134 // 3)填充变价计划,并做品牌打散
132 begin = System.currentTimeMillis(); 135 begin = System.currentTimeMillis();
133 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(recallProductInfoList.getProductInfoList()); 136 List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(recallProductInfoList.getProductInfoList());
134 - logger.info("[func2=SortRecallSceneService.getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin); 137 + super.doLogInfo("[func2=SortRecallSceneService.getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin);
135 138
136 // 4)构造返回结果 139 // 4)构造返回结果
137 JSONObject dataMap = new JSONObject(); 140 JSONObject dataMap = new JSONObject();
@@ -142,14 +145,16 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -142,14 +145,16 @@ public class SortRecallSceneService extends AbstractRecallService {
142 dataMap.put("product_list", product_list); 145 dataMap.put("product_list", product_list);
143 return new SearchApiResult().setData(dataMap); 146 return new SearchApiResult().setData(dataMap);
144 } catch (Exception e) { 147 } catch (Exception e) {
145 - logger.error(e.getMessage(), e); 148 + super.doLogError(e.getMessage(), e);
146 return new SearchApiResult().setData(new JSONObject()).setMessage("SortProductList Exception").setCode(500); 149 return new SearchApiResult().setData(new JSONObject()).setMessage("SortProductList Exception").setCode(500);
  150 + } finally {
  151 + super.removelogEnableThreadLocal();
147 } 152 }
148 } 153 }
149 154
150 private RecallProductInfoList queryRecallProductInfoList(Map<String, String> paramMap, int page, int pageSize) throws Exception { 155 private RecallProductInfoList queryRecallProductInfoList(Map<String, String> paramMap, int page, int pageSize) throws Exception {
151 // 1、获取召回的skn列表 156 // 1、获取召回的skn列表
152 - RecallProductSknList recallProductList = this.queryRecallProductSknList(paramMap); 157 + RecallProductSknList recallProductList = super.queryRecallProductSknList(paramMap);
153 158
154 // 2、获取SKN列表 159 // 2、获取SKN列表
155 List<Integer> productSknList = recallProductList.getProductSknList(); 160 List<Integer> productSknList = recallProductList.getProductSknList();
@@ -157,10 +162,13 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -157,10 +162,13 @@ public class SortRecallSceneService extends AbstractRecallService {
157 // 3、判断召回的productSkn是否包含当前页码 162 // 3、判断召回的productSkn是否包含当前页码
158 int maxPage = productSknList.size() / pageSize; 163 int maxPage = productSknList.size() / pageSize;
159 List<Map<String, Object>> productInfoList = null; 164 List<Map<String, Object>> productInfoList = null;
  165 + long begin = System.currentTimeMillis();
160 if (page <= maxPage) { 166 if (page <= maxPage) {
161 productInfoList = this.queryProductListWithSort(productSknList.subList((page - 1) * pageSize, page * pageSize)); 167 productInfoList = this.queryProductListWithSort(productSknList.subList((page - 1) * pageSize, page * pageSize));
  168 + super.doLogInfo("[func=queryProductListWithSort][resultsize is {}][cost={}]", productInfoList.size(), System.currentTimeMillis() - begin);
162 } else { 169 } else {
163 productInfoList = this.queryProductListWithDefault(productSknList, paramMap, page, pageSize); 170 productInfoList = this.queryProductListWithDefault(productSknList, paramMap, page, pageSize);
  171 + super.doLogInfo("[func=queryProductListWithDefault][resultsize is {}][cost={}]", productInfoList.size(), System.currentTimeMillis() - begin);
164 } 172 }
165 // 4、返回结果 173 // 4、返回结果
166 return new RecallProductInfoList(recallProductList.getTotal(), productInfoList); 174 return new RecallProductInfoList(recallProductList.getTotal(), productInfoList);
@@ -174,7 +182,6 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -174,7 +182,6 @@ public class SortRecallSceneService extends AbstractRecallService {
174 * @return 182 * @return
175 */ 183 */
176 private List<Map<String, Object>> queryProductListWithSort(List<Integer> querySknList) { 184 private List<Map<String, Object>> queryProductListWithSort(List<Integer> querySknList) {
177 - long begin = System.currentTimeMillis();  
178 // 1.构造搜索参数 185 // 1.构造搜索参数
179 SearchParam searchParam = new SearchParam(); 186 SearchParam searchParam = new SearchParam();
180 searchParam.setFiter(QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, querySknList))); 187 searchParam.setFiter(QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, querySknList)));
@@ -199,7 +206,6 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -199,7 +206,6 @@ public class SortRecallSceneService extends AbstractRecallService {
199 } 206 }
200 realResults.add(productMap.get(produtSkn)); 207 realResults.add(productMap.get(produtSkn));
201 } 208 }
202 - logger.info("[func=queryProductListWithSort][query by sknList][resultsize is {}][cost={}]", productList.size(), System.currentTimeMillis() - begin);  
203 return realResults; 209 return realResults;
204 } 210 }
205 211
@@ -212,7 +218,6 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -212,7 +218,6 @@ public class SortRecallSceneService extends AbstractRecallService {
212 * @throws Exception 218 * @throws Exception
213 */ 219 */
214 private List<Map<String, Object>> queryProductListWithDefault(List<Integer> notProductSkns, Map<String, String> paramMap, int page, int pageSize) throws Exception { 220 private List<Map<String, Object>> queryProductListWithDefault(List<Integer> notProductSkns, Map<String, String> paramMap, int page, int pageSize) throws Exception {
215 - long begin = System.currentTimeMillis();  
216 // 1.构造filter 221 // 1.构造filter
217 BoolQueryBuilder mustFilter = QueryBuilders.boolQuery(); 222 BoolQueryBuilder mustFilter = QueryBuilders.boolQuery();
218 int realPage = page; 223 int realPage = page;
@@ -220,7 +225,6 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -220,7 +225,6 @@ public class SortRecallSceneService extends AbstractRecallService {
220 mustFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, notProductSkns)); 225 mustFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, notProductSkns));
221 realPage = realPage - notProductSkns.size() / pageSize; 226 realPage = realPage - notProductSkns.size() / pageSize;
222 } 227 }
223 -  
224 // 2、构造参数 228 // 2、构造参数
225 SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false, mustFilter); 229 SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false, mustFilter);
226 searchParam.setOffset((realPage - 1) * pageSize); 230 searchParam.setOffset((realPage - 1) * pageSize);
@@ -234,7 +238,6 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -234,7 +238,6 @@ public class SortRecallSceneService extends AbstractRecallService {
234 238
235 // 4、查询es 239 // 4、查询es
236 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); 240 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
237 - logger.info("[func=queryProductListWithDefault][resultsize is {}][cost={}]", searchResult.getTotal(), System.currentTimeMillis() - begin);  
238 return searchResult.getResultList(); 241 return searchResult.getResultList();
239 } 242 }
240 243
@@ -256,16 +259,16 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -256,16 +259,16 @@ public class SortRecallSceneService extends AbstractRecallService {
256 String uid = MapUtils.getString(paramMap, "uid", "0"); 259 String uid = MapUtils.getString(paramMap, "uid", "0");
257 String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion(); 260 String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion();
258 String userGlobalBrandIds = bigDataRedisService.getUserGlobalFaveriteBrand(uid, vectorFeatureVersion); 261 String userGlobalBrandIds = bigDataRedisService.getUserGlobalFaveriteBrand(uid, vectorFeatureVersion);
259 - logger.info("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds); 262 + super.doLogInfo("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds);
260 JSONArray brandJsonArray = JSON.parseArray(userGlobalBrandIds); 263 JSONArray brandJsonArray = JSON.parseArray(userGlobalBrandIds);
261 List<Integer> results = new ArrayList<Integer>(); 264 List<Integer> results = new ArrayList<Integer>();
262 for (int i = 0; i < brandJsonArray.size(); i++) { 265 for (int i = 0; i < brandJsonArray.size(); i++) {
263 results.add(Integer.valueOf(brandJsonArray.getString(i))); 266 results.add(Integer.valueOf(brandJsonArray.getString(i)));
264 } 267 }
265 - logger.info("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results); 268 + super.doLogInfo("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results);
266 return results; 269 return results;
267 } catch (Exception e) { 270 } catch (Exception e) {
268 - logger.error(e.getMessage(), e); 271 + super.doLogError(e.getMessage(), e);
269 return new ArrayList<Integer>(); 272 return new ArrayList<Integer>();
270 } 273 }
271 } 274 }
@@ -328,10 +331,10 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -328,10 +331,10 @@ public class SortRecallSceneService extends AbstractRecallService {
328 for (Map<String, Object> result : results) { 331 for (Map<String, Object> result : results) {
329 brandIds.add(MapUtils.getInteger(result, "id")); 332 brandIds.add(MapUtils.getInteger(result, "id"));
330 } 333 }
331 - logger.info("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds); 334 + super.doLogInfo("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds);
332 return brandIds; 335 return brandIds;
333 } catch (Exception e) { 336 } catch (Exception e) {
334 - logger.error(e.getMessage(), e); 337 + super.doLogError(e.getMessage(), e);
335 return new ArrayList<Integer>(); 338 return new ArrayList<Integer>();
336 } 339 }
337 } 340 }
@@ -384,8 +387,8 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -384,8 +387,8 @@ public class SortRecallSceneService extends AbstractRecallService {
384 @Override 387 @Override
385 protected RecallResult doSketchyRank(Map<String, String> paramMap, RecallResult recallResult) { 388 protected RecallResult doSketchyRank(Map<String, String> paramMap, RecallResult recallResult) {
386 Set<String> existProductSkns = new HashSet<String>(); 389 Set<String> existProductSkns = new HashSet<String>();
  390 + List<Map<String, Object>> productList = new ArrayList<Map<String, Object>>();
387 for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) { 391 for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {
388 - logger.info("[func=doSketchyRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());  
389 Iterator<Map<String, Object>> iterator = recallSearchResult.getResultList().iterator(); 392 Iterator<Map<String, Object>> iterator = recallSearchResult.getResultList().iterator();
390 while (iterator.hasNext()) { 393 while (iterator.hasNext()) {
391 Map<String, Object> product = iterator.next(); 394 Map<String, Object> product = iterator.next();
@@ -394,27 +397,24 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -394,27 +397,24 @@ public class SortRecallSceneService extends AbstractRecallService {
394 iterator.remove(); 397 iterator.remove();
395 } else { 398 } else {
396 existProductSkns.add(productSkn); 399 existProductSkns.add(productSkn);
  400 + product.put("recallType", recallSearchResult.getRecallType());
  401 + productList.add(product);
397 } 402 }
398 } 403 }
399 } 404 }
  405 + recallResult.setProductList(productList);
400 return recallResult; 406 return recallResult;
401 } 407 }
402 408
403 @Override 409 @Override
404 protected RecallResult doCarefulRank(Map<String, String> paramMap, RecallResult recallResult) { 410 protected RecallResult doCarefulRank(Map<String, String> paramMap, RecallResult recallResult) {
405 - // 1、数据组装  
406 - List<Map<String, Object>> productList = new ArrayList<Map<String, Object>>();  
407 - for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {  
408 - logger.info("[func=doCarefulRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());  
409 - for (Map<String, Object> product : recallSearchResult.getResultList()) {  
410 - product.put("recallType", recallSearchResult.getRecallType());  
411 - productList.add(product);  
412 - }  
413 - } 411 + // 1、获取productList
  412 + List<Map<String, Object>> productList = recallResult.getProductList();
414 // 2、精排 413 // 2、精排
415 - // Collections.shuffle(productList); 414 + Collections.shuffle(productList);
416 // 3、TODO 品牌打散 415 // 3、TODO 品牌打散
417 - // 4、设置productList 416 +
  417 + // 4、回设productList
418 recallResult.setProductList(productList); 418 recallResult.setProductList(productList);
419 return recallResult; 419 return recallResult;
420 } 420 }
@@ -464,7 +464,6 @@ public class SortRecallSceneService extends AbstractRecallService { @@ -464,7 +464,6 @@ public class SortRecallSceneService extends AbstractRecallService {
464 int count = newProductList.size(); 464 int count = newProductList.size();
465 int maxPage = count / pageSize; 465 int maxPage = count / pageSize;
466 recallResult.setProductList(newProductList.subList(0, maxPage * pageSize)); 466 recallResult.setProductList(newProductList.subList(0, maxPage * pageSize));
467 - logger.info("[func=doReRank][total product size is ={}]", recallResult.getProductList().size());  
468 return recallResult; 467 return recallResult;
469 } 468 }
470 469
@@ -4,15 +4,15 @@ import java.util.List; @@ -4,15 +4,15 @@ import java.util.List;
4 import java.util.Map; 4 import java.util.Map;
5 5
6 public class RecallResult { 6 public class RecallResult {
7 - 7 +
8 private List<RecallSearchResult> recallSearchResult; 8 private List<RecallSearchResult> recallSearchResult;
9 private List<Map<String, Object>> productList; 9 private List<Map<String, Object>> productList;
10 - 10 +
11 public RecallResult(List<RecallSearchResult> recallSearchResult) { 11 public RecallResult(List<RecallSearchResult> recallSearchResult) {
12 super(); 12 super();
13 this.recallSearchResult = recallSearchResult; 13 this.recallSearchResult = recallSearchResult;
14 } 14 }
15 - 15 +
16 public List<RecallSearchResult> getRecallSearchResult() { 16 public List<RecallSearchResult> getRecallSearchResult() {
17 return recallSearchResult; 17 return recallSearchResult;
18 } 18 }
@@ -20,9 +20,20 @@ public class RecallResult { @@ -20,9 +20,20 @@ public class RecallResult {
20 public List<Map<String, Object>> getProductList() { 20 public List<Map<String, Object>> getProductList() {
21 return productList; 21 return productList;
22 } 22 }
23 - 23 +
24 public void setProductList(List<Map<String, Object>> productList) { 24 public void setProductList(List<Map<String, Object>> productList) {
25 this.productList = productList; 25 this.productList = productList;
26 } 26 }
27 27
  28 + public String doGetRecallSearchResultInfo() {
  29 + if (recallSearchResult == null) {
  30 + return "";
  31 + }
  32 + StringBuilder logInfo = new StringBuilder();
  33 + for (RecallSearchResult recallSearchResult : recallSearchResult) {
  34 + logInfo.append(String.format("[type:%s,total:%s,size:%s]", recallSearchResult.getRecallType().name(),recallSearchResult.getTotal(),recallSearchResult.getResultList().size()));
  35 + }
  36 + return logInfo.toString();
  37 + }
  38 +
28 } 39 }