...
|
...
|
@@ -44,7 +44,7 @@ import com.yoho.search.service.scorer.personal.PersonalVectorFeatureSearch; |
|
|
public class CommonSceneProductListService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(CommonSceneProductListService.class);
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
private CommonPageRecallService commonRecallSceneService;
|
|
|
@Autowired
|
...
|
...
|
@@ -65,50 +65,6 @@ public class CommonSceneProductListService { |
|
|
private CacheAbleServiceHelper cacheAbleServiceHelper;
|
|
|
|
|
|
/**
|
|
|
* 非个性化的列表接口-去除uid缓存
|
|
|
*
|
|
|
* @order不为空,或者无uid
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
@SearchCacheAble(cacheName = "SCENE_PRODUCT_LIST_DEFAULT", cacheType=CacheType.EHCACHE, cacheInMinute = 10, excludeParams = { "uid" })
|
|
|
public SearchApiResult productListForDefault(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1)验证查询条数
|
|
|
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
if (page < 1 || pageSize < 0) {
|
|
|
throw new IllegalArgumentException("分页参数不合法");
|
|
|
}
|
|
|
if (pageSize > 100) {
|
|
|
pageSize = 100;
|
|
|
}
|
|
|
// 2)构建基本查询参数
|
|
|
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, true);
|
|
|
searchParam.setAggregationBuilders(null);
|
|
|
searchParam.setOffset((page - 1) * pageSize);
|
|
|
searchParam.setSize(pageSize);
|
|
|
// 3)设置排序字段
|
|
|
searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));
|
|
|
// 4)设置返回的参数【节省带宽】
|
|
|
List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
|
|
|
searchParam.setIncludeFields(includeFields);
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
// 5)构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", searchResult.getTotal());
|
|
|
dataMap.put("page", searchResult.getPage());
|
|
|
dataMap.put("page_size", searchParam.getSize());
|
|
|
dataMap.put("page_total", searchResult.getTotalPage());
|
|
|
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
|
|
|
dataMap.put("product_list", productListSortService.sortProductList(product_list, paramMap));// 处理一下商品的顺序;
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
} catch (Exception e) {
|
|
|
return new SearchApiResult().setData(null).setCode(500);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 个性化的列表接口
|
|
|
*
|
|
|
* @order为空并且有uid
|
...
|
...
|
@@ -118,28 +74,24 @@ public class CommonSceneProductListService { |
|
|
public SearchApiResult productListForPersional(Map<String, String> paramMap) {
|
|
|
// 1、召回整数页个skn
|
|
|
CommonRecallResult commonRecallResult = commonRecallSceneService.doCommonPageRecallBatch(paramMap);
|
|
|
// 2、查询这整数页个skn的全部信息-包含了变价计划
|
|
|
SearchApiResult productInfoMapResult = cacheAbleServiceHelper.queryProductInfoMap(commonRecallResult);
|
|
|
// 3、计算这些skn得分并排序
|
|
|
commonRecallResult = this.callUserScoreAndRank(paramMap, commonRecallResult);
|
|
|
// 4、获取分页参数
|
|
|
// 2、获取分页参数
|
|
|
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
int viewNum = StringUtils.isBlank(paramMap.get("viewNum")) ? 60 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
long total = commonRecallResult.getTotalCount();
|
|
|
// 5、为用户做列表截取-保留第一页数据
|
|
|
// 3、为用户做列表截取-保留第一页数据
|
|
|
int recallMaxPage = (int) (commonRecallResult.listCount() / viewNum);
|
|
|
if (recallMaxPage == 0) {
|
|
|
recallMaxPage = 1;
|
|
|
}
|
|
|
// 6、构造分页结果参数
|
|
|
// 4、构造分页结果参数
|
|
|
JSONObject results = new JSONObject();
|
|
|
results.put("total", total);
|
|
|
results.put("page", page);
|
|
|
results.put("page_size", viewNum);
|
|
|
results.put("page_total", this.getTotalPage(total, viewNum));
|
|
|
// 7、构造productList
|
|
|
// 5、构造productList
|
|
|
if (page <= recallMaxPage) {
|
|
|
results.put("product_list", this.getProductListFromCache(productInfoMapResult, commonRecallResult, page, viewNum));
|
|
|
results.put("product_list", this.queryProductListForPersional(commonRecallResult, paramMap, page, viewNum));
|
|
|
} else {
|
|
|
// 8、其他页码使用CommonRecallParamService去查询
|
|
|
results.put("product_list", this.queryProductListForOtherPageIndex(paramMap, commonRecallResult, page - recallMaxPage, viewNum).getData());
|
...
|
...
|
@@ -148,6 +100,35 @@ public class CommonSceneProductListService { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 召回页的处理方式
|
|
|
*
|
|
|
* @param commonRecallResult
|
|
|
* @param page
|
|
|
* @param viewNum
|
|
|
* @return
|
|
|
*/
|
|
|
private List<? extends Map<?, ?>> queryProductListForPersional(CommonRecallResult commonRecallResult, Map<String, String> paramMap, int page, int viewNum) {
|
|
|
// 1、查询这整数页个skn的全部信息-包含了变价计划
|
|
|
SearchApiResult productInfoMapResult = cacheAbleServiceHelper.queryProductInfoMap(commonRecallResult);
|
|
|
// 2、排序
|
|
|
commonRecallResult = this.callUserScoreAndRank(paramMap, commonRecallResult);
|
|
|
// 3、数量截取
|
|
|
JSONObject productInfoMap = (JSONObject) productInfoMapResult.getData();
|
|
|
List<JSONObject> results = new ArrayList<JSONObject>();
|
|
|
List<CommonRecallSkn> recallSknList = commonRecallResult.getRecallSknList();
|
|
|
int fromIndex = (page - 1) * viewNum;
|
|
|
int toIndex = page * viewNum;
|
|
|
if (toIndex > recallSknList.size()) {
|
|
|
toIndex = recallSknList.size();
|
|
|
}
|
|
|
recallSknList = recallSknList.subList(fromIndex, toIndex);
|
|
|
for (CommonRecallSkn commonRecallSkn : recallSknList) {
|
|
|
results.add(productInfoMap.getJSONObject(String.valueOf(commonRecallSkn.getProductSkn())));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 其他页码的处理方式
|
|
|
*
|
|
|
* @param paramMap
|
...
|
...
|
@@ -170,7 +151,7 @@ public class CommonSceneProductListService { |
|
|
// 4、执行查询
|
|
|
return cacheAbleServiceHelper.queryProductListByRecallParam(commonRecallParam);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage(),e);
|
|
|
logger.error(e.getMessage(), e);
|
|
|
return new SearchApiResult().setData(new ArrayList<>());
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -186,22 +167,6 @@ public class CommonSceneProductListService { |
|
|
return totalPage;
|
|
|
}
|
|
|
|
|
|
private List<? extends Map<?, ?>> getProductListFromCache(SearchApiResult productInfoMapResult, CommonRecallResult commonRecallResult, int page, int viewNum) {
|
|
|
JSONObject productInfoMap = (JSONObject) productInfoMapResult.getData();
|
|
|
List<JSONObject> results = new ArrayList<JSONObject>();
|
|
|
List<CommonRecallSkn> recallSknList = commonRecallResult.getRecallSknList();
|
|
|
int fromIndex = (page - 1) * viewNum;
|
|
|
int toIndex = page * viewNum;
|
|
|
if (toIndex > recallSknList.size()) {
|
|
|
toIndex = recallSknList.size();
|
|
|
}
|
|
|
recallSknList = recallSknList.subList(fromIndex, toIndex);
|
|
|
for (CommonRecallSkn commonRecallSkn : recallSknList) {
|
|
|
results.add(productInfoMap.getJSONObject(String.valueOf(commonRecallSkn.getProductSkn())));
|
|
|
}
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据向量计算得分并排序
|
|
|
*
|
...
|
...
|
@@ -223,4 +188,49 @@ public class CommonSceneProductListService { |
|
|
Collections.sort(commonRecallResult.getRecallSknList());
|
|
|
return commonRecallResult;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 非个性化的列表接口-去除uid缓存
|
|
|
*
|
|
|
* @order不为空,或者无uid
|
|
|
* @param paramMap
|
|
|
* @return
|
|
|
*/
|
|
|
@SearchCacheAble(cacheName = "SCENE_PRODUCT_LIST_DEFAULT", cacheType = CacheType.EHCACHE, cacheInMinute = 10, excludeParams = { "uid" })
|
|
|
public SearchApiResult productListForDefault(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1)验证查询条数
|
|
|
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
int page = StringUtils.isBlank(paramMap.get("page")) ? 1 : Integer.parseInt(paramMap.get("page"));
|
|
|
if (page < 1 || pageSize < 0) {
|
|
|
throw new IllegalArgumentException("分页参数不合法");
|
|
|
}
|
|
|
if (pageSize > 100) {
|
|
|
pageSize = 100;
|
|
|
}
|
|
|
// 2)构建基本查询参数
|
|
|
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, true);
|
|
|
searchParam.setAggregationBuilders(null);
|
|
|
searchParam.setOffset((page - 1) * pageSize);
|
|
|
searchParam.setSize(pageSize);
|
|
|
// 3)设置排序字段
|
|
|
searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));
|
|
|
// 4)设置返回的参数【节省带宽】
|
|
|
List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
|
|
|
searchParam.setIncludeFields(includeFields);
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
// 5)构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", searchResult.getTotal());
|
|
|
dataMap.put("page", searchResult.getPage());
|
|
|
dataMap.put("page_size", searchParam.getSize());
|
|
|
dataMap.put("page_total", searchResult.getTotalPage());
|
|
|
List<Map<String, Object>> product_list = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
|
|
|
dataMap.put("product_list", productListSortService.sortProductList(product_list, paramMap));// 处理一下商品的顺序;
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
} catch (Exception e) {
|
|
|
return new SearchApiResult().setData(null).setCode(500);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|