Authored by hugufei

修改sort_size_products的接口

... ... @@ -41,7 +41,7 @@ public class SearchController {
public Map<String, Object> searchNew(HttpServletRequest request) {
Map<String, Object> paramMap = request.getParameterMap();
try {
Map<String, Object> jsonMap = searchService.searchNew(transParamType(paramMap));
Map<String, Object> jsonMap = searchService.searchNew(transParamType(paramMap),null);
return jsonMap;
} catch (Exception e) {
return errorReturn("searchNew", paramMap, e.getMessage());
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.search.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
... ... @@ -680,9 +681,17 @@ public class SearchService {
* @return
* @throws Exception
*/
public Map<String, Object> searchNew(Map<String, String> paramMap) throws Exception {
public Map<String, Object> searchNew(Map<String, String> paramMap,Collection<String> producSkns) throws Exception {
long begin = System.currentTimeMillis();
logger.info("[model=SearchService][func=searchWithWeight][param={}][begin={}]", paramMap.toString(), begin);
logger.info("[model=SearchService][func=searchNew][param={}][begin={}][producSkns.size={}]", paramMap.toString(), begin, producSkns == null ? "null" : producSkns.size());
if (producSkns != null) {
StringBuilder sb = new StringBuilder();
for (String productSkn : producSkns) {
sb.append(productSkn).append(",");
}
String productIds = sb.toString();
paramMap.put(ISearchConstans.PARAM_SYNC_SKN, productIds);
}
// 首先解析参数转化为检索条件--SearchParam
SearchParam searchParam = new SearchParam();
// 构造query
... ... @@ -709,7 +718,7 @@ public class SearchService {
String resultFields = paramMap.get("resultFields");
searchParam.setResultFields(Arrays.asList(resultFields.split(",")));
}
// 设置排序字段
searchParam.setSortFields(buildSort(paramMap));
// 进行检索
... ... @@ -717,25 +726,23 @@ public class SearchService {
SearchResult searchResult = doSearch(indexName, searchParam);
// 将searchResult转化为map返回--需要把aggregation转化为需要的结构
if (searchResult == null)
if (searchResult == null){
return null;
}
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("total", searchResult.getTotal());
dataMap.put("page", searchResult.getPage());
dataMap.put("page_total", searchResult.getTotalPage());
dataMap.put("product_list", makePageList(searchResult.getResultList()));
if (searchResult.getAggMaps() != null) {
Map<String, Aggregation> aggMaps = searchResult.getAggMaps();
dataMap.put("filter", buildFilterResult(aggMaps, preAggregationResult, paramMap));
}
Map<String, Object> jsonMap = new HashMap<String, Object>();
jsonMap.put("message", "Search List.");
jsonMap.put("code", 200);
jsonMap.put("data", dataMap);
logger.info("[model=SearchService][func=searchWithWeight][param={}][cost={}ms]", paramMap.toString(), System.currentTimeMillis() - begin);
return jsonMap;
}
... ... @@ -1925,6 +1932,11 @@ public class SearchService {
.should(FilterBuilders.rangeFilter("basePinRatio").from(3.5)));
}
}
if (paramMap.containsKey(ISearchConstans.PARAM_SYNC_SKN) && StringUtils.isNotBlank(paramMap.get(ISearchConstans.PARAM_SYNC_SKN))) {
String sknString = paramMap.get(ISearchConstans.PARAM_SYNC_SKN);
boolFilter.must(FilterBuilders.termsFilter("productSkn", sknString.split(",")));
}
// 增加过滤的请求
for (String key : paramMap.keySet()) {
... ...
... ... @@ -185,10 +185,8 @@ public class SearchSortSizeService {
if (!aggMaps.containsKey("productSknAgg")) {
return new HashMap<String, Object>();
}
// 构建聚合结果
Set<String> productSkns = new HashSet<String>();
MultiBucketsAggregation aggreation = (MultiBucketsAggregation) aggMaps.get("productSknAgg");
Iterator<? extends Bucket> iterator = aggreation.getBuckets().iterator();
while (iterator.hasNext()) {
... ... @@ -196,13 +194,7 @@ public class SearchSortSizeService {
productSkns.add(String.valueOf(sortBucket.getKey()));
}
logger.info("get productSkn from storagesku index productSkn size is{}", productSkns.size());
StringBuilder sb = new StringBuilder();
for (String productSkn : productSkns) {
sb.append(productSkn).append(",");
}
String productIds = sb.toString();
paramMap.put(ISearchConstans.PARAM_SYNC_SKN, productIds);
return searchService.searchNew(paramMap);
return searchService.searchNew(paramMap, productSkns);
}
/**
... ... @@ -255,14 +247,14 @@ public class SearchSortSizeService {
boolFilter.must(FilterBuilders.termFilter("status", 1));
if (StringUtils.isNotBlank(sizeSortReqBO.getIsdiscount())) {
boolFilter.must(FilterBuilders.termFilter("isDiscount", sizeSortReqBO.getIsdiscount()));
}
if (StringUtils.isNotBlank(sizeSortReqBO.getProductStatus())) {
boolFilter.must(FilterBuilders.termFilter("productStatus", sizeSortReqBO.getProductStatus()));
}
if (StringUtils.isNotBlank(sizeSortReqBO.getIsdiscount())) {
boolFilter.must(FilterBuilders.termFilter("isDiscount", sizeSortReqBO.getIsdiscount()));
}
if (StringUtils.isNotBlank(sizeSortReqBO.getAttribute_not())) {
boolFilter.mustNot(FilterBuilders.termFilter("attribute", sizeSortReqBO.getAttribute_not()));
}
... ... @@ -298,7 +290,9 @@ public class SearchSortSizeService {
boolFilter.must(FilterBuilders.termsFilter("gender", genderIds));
}
}
logger.debug("boolFilter:" + boolFilter.toString());
return boolFilter;
}
... ... @@ -339,5 +333,4 @@ public class SearchSortSizeService {
}
return sizeResult;
}
}
... ...