Authored by hugufei

添加searchLikeForSaleOut接口

... ... @@ -51,6 +51,13 @@ public class SearchLikeSecneController {
return searchLikeService.searchLike(paramMap);
}
@RequestMapping(method = RequestMethod.GET, value = "/searchLikeForSaleOut")
@ResponseBody
public SearchApiResult searchLikeForSaleOut(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return searchLikeService.searchLikeForSaleOut(paramMap);
}
@RequestMapping(method = RequestMethod.GET, value = "/searchLikeInShop")
@ResponseBody
public SearchApiResult searchLikeInShop(HttpServletRequest request) {
... ...
... ... @@ -192,4 +192,79 @@ public class SearchLikeSceneService {
}
}
/**
* @售罄商品全站找相似功能
*/
@SearchCacheAble(cacheInMinute = 600, cacheName = "SEARCH_LIKE_FOR_SALE_OUT", includeParams = { "product_skn", "viewNum" })
public SearchApiResult searchLikeForSaleOut(Map<String, String> paramMap) {
try {
// 1、获取参数
String productSkn = paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN);
if (StringUtils.isBlank(productSkn)) {
return new SearchApiResult().setCode(400).setMessage("请输入SKN");
}
// 2、检测分页参数【默认30条,最多60条】
int pageSize = searchLikeHelper.getPageSize(paramMap);
// 3、获取当前查询的SKN的基本信息
JSONObject productInfoInEs = searchLikeHelper.getProductInfoInEs(productSkn);
if (productInfoInEs == null) {
return new SearchApiResult().setCode(400).setMessage("SKN不存在");
}
// 4、设置第一步SearchParam
List<SearchParam> searchParams = new ArrayList<SearchParam>();
searchParams.add(this.buildSearchLikeForSaleOutParam(productInfoInEs,pageSize));
// 5、获取搜索结果[并截取条数]
List<Map<String, Object>> tempProductList = searchLikeHelper.queryProductList(searchParams);
if (tempProductList.size() > pageSize) {
tempProductList = CollectionUtils.safeSubList(tempProductList,0, pageSize);
}
// 6、构造真实返回结果
List<Map<String, Object>> productListResults = new ArrayList<Map<String, Object>>();
if (!tempProductList.isEmpty()) {
productListResults = productIndexBaseService.getProductListWithPricePlan(tempProductList);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("page", 1);
jsonObject.put("page_total", 1);
jsonObject.put("page_size", pageSize);
jsonObject.put("total", productListResults.size());
jsonObject.put("product_info", searchLikeHelper.genProductInfoResult(productInfoInEs));
jsonObject.put("product_list", productListResults);
return new SearchApiResult().setData(jsonObject);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setData(null).setMessage("searchLike Exception").setCode(500);
}
}
private SearchParam buildSearchLikeForSaleOutParam(JSONObject productInfoInEs, int limitCount) {
SearchParam searchParam = new SearchParam();
// 1、构建Query
String queryString = searchLikeHelper.genYohoQueryStringWithBrandName(productInfoInEs);
QueryBuilder queryBuilder = searchLikeHelper.genSearchLikeQueryBuilder(queryString, "20%", null);
searchParam.setQuery(queryBuilder);
// 2、设置过滤条件
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(Arrays.asList(productInfoInEs.getString("productSkn")), false);
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, Arrays.asList("1","2")));
searchParam.setFiter(boolFilter);
// 3、设置排序规则[按打分排序]
List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 4、设置分页参数
searchParam.setOffset(0);
searchParam.setSize(limitCount);
// 5设置返回的参数【节省带宽】
List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
searchParam.setIncludeFields(includeFields);
return searchParam;
}
}
... ...