|
@@ -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
|
|