...
|
...
|
@@ -2,6 +2,7 @@ package com.yoho.search.service.scene.recall; |
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.Iterator;
|
...
|
...
|
@@ -20,8 +21,6 @@ import org.elasticsearch.script.ScriptType; |
|
|
import org.elasticsearch.search.sort.SortBuilder;
|
|
|
import org.elasticsearch.search.sort.SortBuilders;
|
|
|
import org.elasticsearch.search.sort.SortOrder;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
...
|
...
|
@@ -42,6 +41,7 @@ import com.yoho.search.service.base.SearchCommonService; |
|
|
import com.yoho.search.service.base.SearchDynamicConfigService;
|
|
|
import com.yoho.search.service.base.SearchRequestParams;
|
|
|
import com.yoho.search.service.base.index.ProductIndexBaseService;
|
|
|
import com.yoho.search.service.helper.SearchCommonHelper;
|
|
|
import com.yoho.search.service.helper.SearchParamHelper;
|
|
|
import com.yoho.search.service.helper.SearchServiceHelper;
|
|
|
import com.yoho.search.service.helper.SearchSortHelper;
|
...
|
...
|
@@ -64,8 +64,6 @@ import com.yoho.search.service.service.IProductIndexService; |
|
|
@Service
|
|
|
public class SortRecallSceneService extends AbstractRecallService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger("RECALL");
|
|
|
|
|
|
@Autowired
|
|
|
private SearchCacheService searchCacheService;
|
|
|
@Autowired
|
...
|
...
|
@@ -86,6 +84,8 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
private BigDataRedisService bigDataRedisService;
|
|
|
@Autowired
|
|
|
private ProductListSortService productListSortService;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
|
|
|
/**
|
|
|
* @品类页商品召回接口
|
...
|
...
|
@@ -119,19 +119,22 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
*/
|
|
|
public SearchApiResult productList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1)验证查询条数
|
|
|
// 0)日志打印检查
|
|
|
super.setLogEnableThreadLocal(paramMap);
|
|
|
|
|
|
// 1)验证查询条数
|
|
|
int page = this.getPage(paramMap);
|
|
|
int pageSize = this.getPageSize(paramMap);
|
|
|
|
|
|
// 2)获取商品列表
|
|
|
long begin = System.currentTimeMillis();
|
|
|
RecallProductInfoList recallProductInfoList = this.queryRecallProductInfoList(paramMap, page, pageSize);
|
|
|
logger.info("[func1=SortRecallSceneService.queryRealProductList][cost={}]", System.currentTimeMillis() - begin);
|
|
|
super.doLogInfo("[func1=SortRecallSceneService.queryRealProductList][cost={}]", System.currentTimeMillis() - begin);
|
|
|
|
|
|
// 3)填充变价计划,并做品牌打散
|
|
|
begin = System.currentTimeMillis();
|
|
|
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(recallProductInfoList.getProductInfoList());
|
|
|
logger.info("[func2=SortRecallSceneService.getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin);
|
|
|
super.doLogInfo("[func2=SortRecallSceneService.getProductListWithPricePlan][cost={}]", System.currentTimeMillis() - begin);
|
|
|
|
|
|
// 4)构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
...
|
...
|
@@ -142,14 +145,16 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
dataMap.put("product_list", product_list);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
super.doLogError(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(new JSONObject()).setMessage("SortProductList Exception").setCode(500);
|
|
|
} finally {
|
|
|
super.removelogEnableThreadLocal();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private RecallProductInfoList queryRecallProductInfoList(Map<String, String> paramMap, int page, int pageSize) throws Exception {
|
|
|
// 1、获取召回的skn列表
|
|
|
RecallProductSknList recallProductList = this.queryRecallProductSknList(paramMap);
|
|
|
RecallProductSknList recallProductList = super.queryRecallProductSknList(paramMap);
|
|
|
|
|
|
// 2、获取SKN列表
|
|
|
List<Integer> productSknList = recallProductList.getProductSknList();
|
...
|
...
|
@@ -157,10 +162,13 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
// 3、判断召回的productSkn是否包含当前页码
|
|
|
int maxPage = productSknList.size() / pageSize;
|
|
|
List<Map<String, Object>> productInfoList = null;
|
|
|
long begin = System.currentTimeMillis();
|
|
|
if (page <= maxPage) {
|
|
|
productInfoList = this.queryProductListWithSort(productSknList.subList((page - 1) * pageSize, page * pageSize));
|
|
|
super.doLogInfo("[func=queryProductListWithSort][resultsize is {}][cost={}]", productInfoList.size(), System.currentTimeMillis() - begin);
|
|
|
} else {
|
|
|
productInfoList = this.queryProductListWithDefault(productSknList, paramMap, page, pageSize);
|
|
|
super.doLogInfo("[func=queryProductListWithDefault][resultsize is {}][cost={}]", productInfoList.size(), System.currentTimeMillis() - begin);
|
|
|
}
|
|
|
// 4、返回结果
|
|
|
return new RecallProductInfoList(recallProductList.getTotal(), productInfoList);
|
...
|
...
|
@@ -174,7 +182,6 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
* @return
|
|
|
*/
|
|
|
private List<Map<String, Object>> queryProductListWithSort(List<Integer> querySknList) {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
// 1.构造搜索参数
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setFiter(QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, querySknList)));
|
...
|
...
|
@@ -199,7 +206,6 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
}
|
|
|
realResults.add(productMap.get(produtSkn));
|
|
|
}
|
|
|
logger.info("[func=queryProductListWithSort][query by sknList][resultsize is {}][cost={}]", productList.size(), System.currentTimeMillis() - begin);
|
|
|
return realResults;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -212,7 +218,6 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
* @throws Exception
|
|
|
*/
|
|
|
private List<Map<String, Object>> queryProductListWithDefault(List<Integer> notProductSkns, Map<String, String> paramMap, int page, int pageSize) throws Exception {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
// 1.构造filter
|
|
|
BoolQueryBuilder mustFilter = QueryBuilders.boolQuery();
|
|
|
int realPage = page;
|
...
|
...
|
@@ -220,7 +225,6 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
mustFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, notProductSkns));
|
|
|
realPage = realPage - notProductSkns.size() / pageSize;
|
|
|
}
|
|
|
|
|
|
// 2、构造参数
|
|
|
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false, mustFilter);
|
|
|
searchParam.setOffset((realPage - 1) * pageSize);
|
...
|
...
|
@@ -234,7 +238,6 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
|
|
|
// 4、查询es
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
logger.info("[func=queryProductListWithDefault][resultsize is {}][cost={}]", searchResult.getTotal(), System.currentTimeMillis() - begin);
|
|
|
return searchResult.getResultList();
|
|
|
}
|
|
|
|
...
|
...
|
@@ -256,16 +259,16 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
String uid = MapUtils.getString(paramMap, "uid", "0");
|
|
|
String vectorFeatureVersion = searchDynamicConfigService.personalizedSearchVersion();
|
|
|
String userGlobalBrandIds = bigDataRedisService.getUserGlobalFaveriteBrand(uid, vectorFeatureVersion);
|
|
|
logger.info("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds);
|
|
|
super.doLogInfo("uid is [{}],vectorFeatureVersion is [{}], userGlobalBrandIds is [{}]", uid, vectorFeatureVersion, userGlobalBrandIds);
|
|
|
JSONArray brandJsonArray = JSON.parseArray(userGlobalBrandIds);
|
|
|
List<Integer> results = new ArrayList<Integer>();
|
|
|
for (int i = 0; i < brandJsonArray.size(); i++) {
|
|
|
results.add(Integer.valueOf(brandJsonArray.getString(i)));
|
|
|
}
|
|
|
logger.info("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results);
|
|
|
super.doLogInfo("[getUserGlobalBrandIds,uid is[{}], brandIds is [{}] ]", uid, results);
|
|
|
return results;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
super.doLogError(e.getMessage(), e);
|
|
|
return new ArrayList<Integer>();
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -328,10 +331,10 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
for (Map<String, Object> result : results) {
|
|
|
brandIds.add(MapUtils.getInteger(result, "id"));
|
|
|
}
|
|
|
logger.info("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds);
|
|
|
super.doLogInfo("[getUserLikeBrandIds,uid is[{}], brandIds is [{}] ]", uid, brandIds);
|
|
|
return brandIds;
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(), e);
|
|
|
super.doLogError(e.getMessage(), e);
|
|
|
return new ArrayList<Integer>();
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -384,8 +387,8 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
@Override
|
|
|
protected RecallResult doSketchyRank(Map<String, String> paramMap, RecallResult recallResult) {
|
|
|
Set<String> existProductSkns = new HashSet<String>();
|
|
|
List<Map<String, Object>> productList = new ArrayList<Map<String, Object>>();
|
|
|
for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {
|
|
|
logger.info("[func=doSketchyRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
|
|
|
Iterator<Map<String, Object>> iterator = recallSearchResult.getResultList().iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
Map<String, Object> product = iterator.next();
|
...
|
...
|
@@ -394,27 +397,24 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
iterator.remove();
|
|
|
} else {
|
|
|
existProductSkns.add(productSkn);
|
|
|
product.put("recallType", recallSearchResult.getRecallType());
|
|
|
productList.add(product);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
recallResult.setProductList(productList);
|
|
|
return recallResult;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected RecallResult doCarefulRank(Map<String, String> paramMap, RecallResult recallResult) {
|
|
|
// 1、数据组装
|
|
|
List<Map<String, Object>> productList = new ArrayList<Map<String, Object>>();
|
|
|
for (RecallSearchResult recallSearchResult : recallResult.getRecallSearchResult()) {
|
|
|
logger.info("[func=doCarefulRank][type={}][results={}]", recallSearchResult.getRecallType(), recallSearchResult.getResultList().size());
|
|
|
for (Map<String, Object> product : recallSearchResult.getResultList()) {
|
|
|
product.put("recallType", recallSearchResult.getRecallType());
|
|
|
productList.add(product);
|
|
|
}
|
|
|
}
|
|
|
// 1、获取productList
|
|
|
List<Map<String, Object>> productList = recallResult.getProductList();
|
|
|
// 2、精排
|
|
|
// Collections.shuffle(productList);
|
|
|
Collections.shuffle(productList);
|
|
|
// 3、TODO 品牌打散
|
|
|
// 4、设置productList
|
|
|
|
|
|
// 4、回设productList
|
|
|
recallResult.setProductList(productList);
|
|
|
return recallResult;
|
|
|
}
|
...
|
...
|
@@ -464,7 +464,6 @@ public class SortRecallSceneService extends AbstractRecallService { |
|
|
int count = newProductList.size();
|
|
|
int maxPage = count / pageSize;
|
|
|
recallResult.setProductList(newProductList.subList(0, maxPage * pageSize));
|
|
|
logger.info("[func=doReRank][total product size is ={}]", recallResult.getProductList().size());
|
|
|
return recallResult;
|
|
|
}
|
|
|
|
...
|
...
|
|