Authored by wangnan9279

productList by skn

@@ -52,20 +52,6 @@ public class ProductListHelper { @@ -52,20 +52,6 @@ public class ProductListHelper {
52 return this.innerBuildProductListSearchParam(paramMap, false, true); 52 return this.innerBuildProductListSearchParam(paramMap, false, true);
53 } 53 }
54 54
55 - public SearchParam buildProductListBySknSearchParam(Map<String, String> paramMap,int size) throws Exception {  
56 - // 1)构建基本查询参数  
57 - SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false);  
58 - searchParam.setAggregationBuilders(null);  
59 - searchParam.setSize(size);  
60 - searchParam.setOffset(0);  
61 - // 2)设置排序字段  
62 - searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));  
63 - // 3)设置返回的结果  
64 - List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();  
65 - searchParam.setIncludeFields(includeFields);  
66 - return searchParam;  
67 - }  
68 -  
69 private SearchParam innerBuildProductListSearchParam(Map<String, String> paramMap, boolean needPersional, boolean containPhrase) throws Exception { 55 private SearchParam innerBuildProductListSearchParam(Map<String, String> paramMap, boolean needPersional, boolean containPhrase) throws Exception {
70 // 1)验证查询条数 56 // 1)验证查询条数
71 int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); 57 int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
@@ -10,6 +10,8 @@ import com.yoho.search.core.es.model.SearchParam; @@ -10,6 +10,8 @@ import com.yoho.search.core.es.model.SearchParam;
10 import com.yoho.search.core.es.model.SearchResult; 10 import com.yoho.search.core.es.model.SearchResult;
11 import com.yoho.search.models.SearchApiResult; 11 import com.yoho.search.models.SearchApiResult;
12 import com.yoho.search.service.helper.ProductListHelper; 12 import com.yoho.search.service.helper.ProductListHelper;
  13 +import com.yoho.search.service.helper.SearchParamHelper;
  14 +import com.yoho.search.service.index.ProductIndexBaseService;
13 import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum; 15 import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;
14 import org.apache.commons.lang.StringUtils; 16 import org.apache.commons.lang.StringUtils;
15 import org.slf4j.Logger; 17 import org.slf4j.Logger;
@@ -23,6 +25,8 @@ import java.util.List; @@ -23,6 +25,8 @@ import java.util.List;
23 import java.util.Map; 25 import java.util.Map;
24 import java.util.stream.Collectors; 26 import java.util.stream.Collectors;
25 27
  28 +import static java.util.stream.Collectors.joining;
  29 +
26 /** 30 /**
27 * @author wangnan 31 * @author wangnan
28 * @version 2018/10/15 32 * @version 2018/10/15
@@ -36,6 +40,10 @@ public class ProductListBySknService { @@ -36,6 +40,10 @@ public class ProductListBySknService {
36 private SearchCommonService searchCommonService; 40 private SearchCommonService searchCommonService;
37 @Autowired 41 @Autowired
38 private ProductListHelper productListHelper; 42 private ProductListHelper productListHelper;
  43 + @Autowired
  44 + private SearchParamHelper searchParamHelper;
  45 + @Autowired
  46 + private ProductIndexBaseService productIndexBaseService;
39 47
40 @SearchCacheAble(cacheInMinute = 10, cacheName = "PRODUCT_LIST_BY_SKN") 48 @SearchCacheAble(cacheInMinute = 10, cacheName = "PRODUCT_LIST_BY_SKN")
41 public SearchApiResult productListBySkn(Map<String, String> paramMap) { 49 public SearchApiResult productListBySkn(Map<String, String> paramMap) {
@@ -48,7 +56,14 @@ public class ProductListBySknService { @@ -48,7 +56,14 @@ public class ProductListBySknService {
48 // 1)构造搜索参数 56 // 1)构造搜索参数
49 List<String> sknList = Arrays.asList(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN).split(",")); 57 List<String> sknList = Arrays.asList(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN).split(","));
50 sknList = sknList.size() > 100 ? sknList.subList(0, 100) : sknList; 58 sknList = sknList.size() > 100 ? sknList.subList(0, 100) : sknList;
51 - SearchParam searchParam = productListHelper.buildProductListBySknSearchParam(paramMap, sknList.size()); 59 + String productSknParam = sknList.stream().collect(joining(","));
  60 + paramMap.put(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN,productSknParam);
  61 + SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false);
  62 + searchParam.setAggregationBuilders(null);
  63 + searchParam.setSize(100);
  64 + searchParam.setOffset(0);
  65 + List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
  66 + searchParam.setIncludeFields(includeFields);
52 67
53 // 2)查询ES 68 // 2)查询ES
54 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); 69 SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);