Authored by wangnan9279

productList by skn

... ... @@ -52,20 +52,6 @@ public class ProductListHelper {
return this.innerBuildProductListSearchParam(paramMap, false, true);
}
public SearchParam buildProductListBySknSearchParam(Map<String, String> paramMap,int size) throws Exception {
// 1)构建基本查询参数
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false);
searchParam.setAggregationBuilders(null);
searchParam.setSize(size);
searchParam.setOffset(0);
// 2)设置排序字段
searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));
// 3)设置返回的结果
List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
searchParam.setIncludeFields(includeFields);
return searchParam;
}
private SearchParam innerBuildProductListSearchParam(Map<String, String> paramMap, boolean needPersional, boolean containPhrase) throws Exception {
// 1)验证查询条数
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;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.helper.ProductListHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.index.ProductIndexBaseService;
import com.yoho.search.service.recall.beans.strategy.NotRecallTypeEnum;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
... ... @@ -23,6 +25,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.joining;
/**
* @author wangnan
* @version 2018/10/15
... ... @@ -36,6 +40,10 @@ public class ProductListBySknService {
private SearchCommonService searchCommonService;
@Autowired
private ProductListHelper productListHelper;
@Autowired
private SearchParamHelper searchParamHelper;
@Autowired
private ProductIndexBaseService productIndexBaseService;
@SearchCacheAble(cacheInMinute = 10, cacheName = "PRODUCT_LIST_BY_SKN")
public SearchApiResult productListBySkn(Map<String, String> paramMap) {
... ... @@ -48,7 +56,14 @@ public class ProductListBySknService {
// 1)构造搜索参数
List<String> sknList = Arrays.asList(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN).split(","));
sknList = sknList.size() > 100 ? sknList.subList(0, 100) : sknList;
SearchParam searchParam = productListHelper.buildProductListBySknSearchParam(paramMap, sknList.size());
String productSknParam = sknList.stream().collect(joining(","));
paramMap.put(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN,productSknParam);
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false);
searchParam.setAggregationBuilders(null);
searchParam.setSize(100);
searchParam.setOffset(0);
List<String> includeFields = productIndexBaseService.getProductIndexIncludeFields();
searchParam.setIncludeFields(includeFields);
// 2)查询ES
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
... ...