...
|
...
|
@@ -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()) {
|
...
|
...
|
|