|
|
package com.yoho.search.service.servicenew.impl;
|
|
|
|
|
|
import static java.util.stream.Collectors.joining;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.base.utils.ProductIndexEsField;
|
...
|
...
|
@@ -20,19 +39,6 @@ import com.yoho.search.service.servicenew.ISimilarProductService; |
|
|
import com.yoho.search.service.utils.SearchApiResultUtils;
|
|
|
import com.yoho.search.service.utils.SearchRequestParams;
|
|
|
import com.yoho.search.service.vo.SearchApiResult;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.*;
|
|
|
|
|
|
import static java.util.stream.Collectors.joining;
|
|
|
|
|
|
/**
|
|
|
* Created by wangnan on 2017/5/26.
|
...
|
...
|
@@ -40,213 +46,205 @@ import static java.util.stream.Collectors.joining; |
|
|
@Service
|
|
|
public class ProductListWithSupplyServiceImpl implements IProductListWithSupplyService {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProductListWithSupplyServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private SearchSortHelper searchSortHelper;
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private SearchKeyWordService searchKeyWordService;
|
|
|
@Autowired
|
|
|
private ProductIndexBaseService productIndexBaseService;
|
|
|
@Autowired
|
|
|
private ISimilarProductService similarProductService;
|
|
|
@Autowired
|
|
|
private SearchCacheService searchCacheService;
|
|
|
@Autowired
|
|
|
private SearchCacheFactory searchCacheFactory;
|
|
|
@Autowired
|
|
|
private SearchParamHelper searchParamHelper;
|
|
|
|
|
|
private SearchCache productListSearchCache;
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
productListSearchCache = searchCacheFactory.getProductListSearchCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 不支持分页,最大传入skn数100,大于100只返回100条
|
|
|
*/
|
|
|
@Override
|
|
|
public SearchApiResult productListWithSupply(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
SearchApiResult searchResult = innerProductList(paramMap);
|
|
|
return searchResult;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("[func=productListWithSupply][params=" + paramMap + "]", e);
|
|
|
return SearchApiResultUtils.errorSearchApiResult("productListWithSupply", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private SearchApiResult innerProductList(Map<String, String> paramMap) throws Exception {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
logger.info("[func=productListWithSupply][param={}][begin={}]", paramMap, begin);
|
|
|
|
|
|
// 1)构造搜索参数
|
|
|
SearchParam searchParam = buildProductListSearchParam(paramMap);
|
|
|
|
|
|
// 2)从缓存中获取数据
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(productListSearchCache, indexName, searchParam);
|
|
|
if (cacheObject != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("/productindex/productListWithSupply.json", paramMap);
|
|
|
return new SearchApiResult().setData(cacheObject);
|
|
|
}
|
|
|
|
|
|
// 3)查询ES
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
|
|
if (searchResult == null) {
|
|
|
return new SearchApiResult().setCode(500).setMessage("execption");
|
|
|
}
|
|
|
|
|
|
// 4)记录关键字对应的查询结果
|
|
|
String queryWord = paramMap.get("query");
|
|
|
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySkn(queryWord)) {
|
|
|
searchKeyWordService.recordKeyWordByResultCount(queryWord, searchResult.getTotal());
|
|
|
}
|
|
|
|
|
|
// 5)补充SKN逻辑:记录传入的skn列表,调用搜索,把返回的product列表中的skn记录到一个列表,找出无效的skn,用这些skn查找相似的,加入到之前的返回列表中返回
|
|
|
List<Map<String, Object>> productList = supplySkn(paramMap, searchResult, searchParam);
|
|
|
|
|
|
// 6)构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", productList.size());
|
|
|
dataMap.put("page", 1);
|
|
|
dataMap.put("page_size", searchParam.getSize());
|
|
|
dataMap.put("page_total", 1);
|
|
|
dataMap.put("product_list", productList);
|
|
|
|
|
|
// 7)将结果存进缓存
|
|
|
searchCacheService.addJSONObjectToCache(productListSearchCache, indexName, searchParam, dataMap);
|
|
|
logger.info("[func=productListWithSupply][cost={}]", System.currentTimeMillis() - begin);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 补充相似的skn
|
|
|
*/
|
|
|
private List<Map<String, Object>> supplySkn(Map<String, String> paramMap, SearchResult searchResult, SearchParam searchParam) {
|
|
|
String inputSknListString = paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN, "");
|
|
|
// 输入skn参数列表
|
|
|
String[] inputSknList = inputSknListString.split(",");
|
|
|
List<Map<String, Object>> productList = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
|
|
|
// 搜索结果skn列表
|
|
|
Set<String> outputSknSet = new HashSet<>();
|
|
|
for (Map<String, Object> product : productList) {
|
|
|
String skn = product.get("product_skn").toString();
|
|
|
outputSknSet.add(skn);
|
|
|
}
|
|
|
// 无效的skn列表(比如不满足库存和状态等)
|
|
|
List<String> invalidSknList = new ArrayList<>();
|
|
|
for (int i = 0; i < inputSknList.length; i++) {
|
|
|
if (!outputSknSet.contains(inputSknList[i])) {
|
|
|
invalidSknList.add(inputSknList[i]);
|
|
|
}
|
|
|
}
|
|
|
//如果无效的skn满足isLimitbuy则保留
|
|
|
invalidSknList = validateSkn(invalidSknList, productList);
|
|
|
String sknString = invalidSknList.stream().collect(joining(","));
|
|
|
int pageSize = searchParam.getSize();
|
|
|
// 需要补充的skn个数
|
|
|
int supplySknNum = 0;
|
|
|
// 如果pageSize等于搜索返回的skn个数,不需要补充
|
|
|
int validSknCount = inputSknList.length - invalidSknList.size();
|
|
|
if (validSknCount < pageSize) {
|
|
|
// 补充的skn数要根据pageSize的大小来确定
|
|
|
// 如果pageSize大于等于输入skn数,补充skn数等于输入skn数减去有效skn数
|
|
|
// 如果pageSize小于输入skn数,补充数等于pageSize减去返回数
|
|
|
if (pageSize >= inputSknList.length) {
|
|
|
supplySknNum = inputSknList.length - validSknCount;
|
|
|
} else {
|
|
|
supplySknNum = pageSize - validSknCount;
|
|
|
}
|
|
|
}
|
|
|
// 如果需要补充数大于0,去调用找相似服务,获取补充数个结果
|
|
|
if (supplySknNum > 0) {
|
|
|
paramMap.put("viewNum", supplySknNum + "");
|
|
|
paramMap.put("product_skn", sknString);
|
|
|
SearchApiResult searchApiResult = similarProductService.similarProductList(paramMap);
|
|
|
JSONObject supplyDataMap = (JSONObject) searchApiResult.getData();
|
|
|
@SuppressWarnings("unchecked")
|
|
|
List<Map<String, Object>> supplyProductList = (List<Map<String, Object>>) supplyDataMap.get("product_list");
|
|
|
productList.addAll(supplyProductList);
|
|
|
}
|
|
|
return productList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 如果无效的skn列表中有isLimitbuy的skn,则保留
|
|
|
*/
|
|
|
private List<String> validateSkn(List<String> invalidSknList, List<Map<String, Object>> productList) {
|
|
|
String sknString = invalidSknList.stream().collect(joining(","));
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, sknString.split(",")));
|
|
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isLimitbuy, "Y"));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setQuery(QueryBuilders.matchAllQuery());
|
|
|
searchParam.setSize(invalidSknList.size());
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
|
|
List<Map<String, Object>> productListValidate = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
|
|
|
// 无效的skn列表(比如不满足库存和状态等)
|
|
|
List<String> trueInvalidSknList = new ArrayList<>();
|
|
|
Set<String> outputSknSet = new HashSet<>();
|
|
|
if(CollectionUtils.isNotEmpty(productListValidate)){
|
|
|
productList.addAll(productListValidate);
|
|
|
for (Map<String, Object> product : productListValidate) {
|
|
|
String skn = product.get("product_skn").toString();
|
|
|
outputSknSet.add(skn);
|
|
|
}
|
|
|
}
|
|
|
for (int i = 0; i < invalidSknList.size(); i++) {
|
|
|
if (!outputSknSet.contains(invalidSknList.get(i))) {
|
|
|
trueInvalidSknList.add(invalidSknList.get(i));
|
|
|
}
|
|
|
}
|
|
|
return trueInvalidSknList;
|
|
|
}
|
|
|
|
|
|
private SearchParam buildProductListSearchParam(Map<String, String> paramMap) throws Exception {
|
|
|
// 1)验证查询条数
|
|
|
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 100 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
int page = 1;
|
|
|
if (page < 1 || pageSize < 0) {
|
|
|
throw new IllegalArgumentException("分页参数不合法");
|
|
|
}
|
|
|
if (pageSize > 100) {
|
|
|
pageSize = 100;
|
|
|
}
|
|
|
|
|
|
// 2)构建基本查询参数
|
|
|
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
|
|
|
setHighlight(paramMap, searchParam);
|
|
|
searchParam.setAggregationBuilders(null);
|
|
|
searchParam.setPage(page);
|
|
|
searchParam.setOffset((page - 1) * pageSize);
|
|
|
searchParam.setSize(pageSize);
|
|
|
|
|
|
// 3)设置排序字段
|
|
|
searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));
|
|
|
|
|
|
// 4)设置查询结果返回字段
|
|
|
if (StringUtils.isNotBlank(paramMap.get("resultFields"))) {
|
|
|
String resultFields = paramMap.get("resultFields");
|
|
|
searchParam.setResultFields(Arrays.asList(resultFields.split(",")));
|
|
|
}
|
|
|
return searchParam;
|
|
|
}
|
|
|
|
|
|
private void setHighlight(final Map<String, String> paramMap, SearchParam searchParam) {
|
|
|
if (StringUtils.isNotBlank(paramMap.get("highlight")) && "1".equals(paramMap.get("highlight")) && StringUtils.isNotBlank(paramMap.get("query"))) {
|
|
|
searchParam.setHighlight(true);
|
|
|
List<String> highlightFields = new ArrayList<String>();
|
|
|
highlightFields.add("productName.productName_ansj");
|
|
|
searchParam.setHighlightFields(highlightFields);
|
|
|
}
|
|
|
}
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ProductListWithSupplyServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private SearchSortHelper searchSortHelper;
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private SearchKeyWordService searchKeyWordService;
|
|
|
@Autowired
|
|
|
private ProductIndexBaseService productIndexBaseService;
|
|
|
@Autowired
|
|
|
private ISimilarProductService similarProductService;
|
|
|
@Autowired
|
|
|
private SearchCacheService searchCacheService;
|
|
|
@Autowired
|
|
|
private SearchCacheFactory searchCacheFactory;
|
|
|
@Autowired
|
|
|
private SearchParamHelper searchParamHelper;
|
|
|
|
|
|
private SearchCache productListSearchCache;
|
|
|
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
productListSearchCache = searchCacheFactory.getProductListSearchCache();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 不支持分页,最大传入skn数100,大于100只返回100条
|
|
|
*/
|
|
|
@Override
|
|
|
public SearchApiResult productListWithSupply(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
SearchApiResult searchResult = innerProductList(paramMap);
|
|
|
return searchResult;
|
|
|
} catch (Exception e) {
|
|
|
logger.error("[func=productListWithSupply][params=" + paramMap + "]", e);
|
|
|
return SearchApiResultUtils.errorSearchApiResult("productListWithSupply", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private SearchApiResult innerProductList(Map<String, String> paramMap) throws Exception {
|
|
|
long begin = System.currentTimeMillis();
|
|
|
logger.info("[func=productListWithSupply][param={}][begin={}]", paramMap, begin);
|
|
|
|
|
|
// 1)构造搜索参数
|
|
|
SearchParam searchParam = buildProductListSearchParam(paramMap);
|
|
|
|
|
|
// 2)从缓存中获取数据
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(productListSearchCache, indexName, searchParam);
|
|
|
if (cacheObject != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("/productindex/productListWithSupply.json", paramMap);
|
|
|
return new SearchApiResult().setData(cacheObject);
|
|
|
}
|
|
|
|
|
|
// 3)查询ES
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
|
|
if (searchResult == null) {
|
|
|
return new SearchApiResult().setCode(500).setMessage("execption");
|
|
|
}
|
|
|
|
|
|
// 4)记录关键字对应的查询结果
|
|
|
String queryWord = paramMap.get("query");
|
|
|
if (!StringUtils.isBlank(queryWord) && !searchCommonHelper.isQuerySkn(queryWord)) {
|
|
|
searchKeyWordService.recordKeyWordByResultCount(queryWord, searchResult.getTotal());
|
|
|
}
|
|
|
|
|
|
// 5)补充SKN逻辑:记录传入的skn列表,调用搜索,把返回的product列表中的skn记录到一个列表,找出无效的skn,用这些skn查找相似的,加入到之前的返回列表中返回
|
|
|
List<Map<String, Object>> productList = supplySkn(paramMap, searchResult, searchParam);
|
|
|
|
|
|
// 6)构造返回结果
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
dataMap.put("total", productList.size());
|
|
|
dataMap.put("page", 1);
|
|
|
dataMap.put("page_size", searchParam.getSize());
|
|
|
dataMap.put("page_total", 1);
|
|
|
dataMap.put("product_list", productList);
|
|
|
|
|
|
// 7)将结果存进缓存
|
|
|
searchCacheService.addJSONObjectToCache(productListSearchCache, indexName, searchParam, dataMap);
|
|
|
logger.info("[func=productListWithSupply][cost={}]", System.currentTimeMillis() - begin);
|
|
|
return new SearchApiResult().setData(dataMap);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 补充相似的skn
|
|
|
*/
|
|
|
private List<Map<String, Object>> supplySkn(Map<String, String> paramMap, SearchResult searchResult, SearchParam searchParam) {
|
|
|
String inputSknListString = paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_PRODUCT_SKN, "");
|
|
|
// 输入skn参数列表
|
|
|
String[] inputSknList = inputSknListString.split(",");
|
|
|
List<Map<String, Object>> productList = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
|
|
|
// 搜索结果skn列表
|
|
|
Set<String> outputSknSet = new HashSet<>();
|
|
|
for (Map<String, Object> product : productList) {
|
|
|
String skn = product.get("product_skn").toString();
|
|
|
outputSknSet.add(skn);
|
|
|
}
|
|
|
// 无效的skn列表(比如不满足库存和状态等)
|
|
|
List<String> invalidSknList = new ArrayList<>();
|
|
|
for (int i = 0; i < inputSknList.length; i++) {
|
|
|
if (!outputSknSet.contains(inputSknList[i])) {
|
|
|
invalidSknList.add(inputSknList[i]);
|
|
|
}
|
|
|
}
|
|
|
// 如果无效的skn满足isLimitbuy则保留
|
|
|
invalidSknList = validateSkn(invalidSknList, productList);
|
|
|
String sknString = invalidSknList.stream().collect(joining(","));
|
|
|
int pageSize = searchParam.getSize();
|
|
|
// 需要补充的skn个数
|
|
|
int supplySknNum = 0;
|
|
|
// 如果pageSize等于搜索返回的skn个数,不需要补充
|
|
|
int validSknCount = inputSknList.length - invalidSknList.size();
|
|
|
if (validSknCount < pageSize) {
|
|
|
// 补充的skn数要根据pageSize的大小来确定
|
|
|
// 如果pageSize大于等于输入skn数,补充skn数等于输入skn数减去有效skn数
|
|
|
// 如果pageSize小于输入skn数,补充数等于pageSize减去返回数
|
|
|
if (pageSize >= inputSknList.length) {
|
|
|
supplySknNum = inputSknList.length - validSknCount;
|
|
|
} else {
|
|
|
supplySknNum = pageSize - validSknCount;
|
|
|
}
|
|
|
}
|
|
|
// 如果需要补充数大于0,去调用找相似服务,获取补充数个结果
|
|
|
if (supplySknNum > 0) {
|
|
|
paramMap.put("viewNum", supplySknNum + "");
|
|
|
paramMap.put("product_skn", sknString);
|
|
|
SearchApiResult searchApiResult = similarProductService.similarProductList(paramMap);
|
|
|
JSONObject supplyDataMap = (JSONObject) searchApiResult.getData();
|
|
|
@SuppressWarnings("unchecked")
|
|
|
List<Map<String, Object>> supplyProductList = (List<Map<String, Object>>) supplyDataMap.get("product_list");
|
|
|
productList.addAll(supplyProductList);
|
|
|
}
|
|
|
return productList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 如果无效的skn列表中有isLimitbuy的skn,则保留
|
|
|
*/
|
|
|
private List<String> validateSkn(List<String> invalidSknList, List<Map<String, Object>> productList) {
|
|
|
String sknString = invalidSknList.stream().collect(joining(","));
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, sknString.split(",")));
|
|
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isLimitbuy, "Y"));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setQuery(QueryBuilders.matchAllQuery());
|
|
|
searchParam.setSize(invalidSknList.size());
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam);
|
|
|
List<Map<String, Object>> productListValidate = productIndexBaseService.getProductListWithPricePlan(searchResult.getResultList());
|
|
|
// 无效的skn列表(比如不满足库存和状态等)
|
|
|
List<String> trueInvalidSknList = new ArrayList<>();
|
|
|
Set<String> outputSknSet = new HashSet<>();
|
|
|
if (CollectionUtils.isNotEmpty(productListValidate)) {
|
|
|
productList.addAll(productListValidate);
|
|
|
for (Map<String, Object> product : productListValidate) {
|
|
|
String skn = product.get("product_skn").toString();
|
|
|
outputSknSet.add(skn);
|
|
|
}
|
|
|
}
|
|
|
for (int i = 0; i < invalidSknList.size(); i++) {
|
|
|
if (!outputSknSet.contains(invalidSknList.get(i))) {
|
|
|
trueInvalidSknList.add(invalidSknList.get(i));
|
|
|
}
|
|
|
}
|
|
|
return trueInvalidSknList;
|
|
|
}
|
|
|
|
|
|
private SearchParam buildProductListSearchParam(Map<String, String> paramMap) throws Exception {
|
|
|
// 1)验证查询条数
|
|
|
int pageSize = StringUtils.isBlank(paramMap.get("viewNum")) ? 100 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
int page = 1;
|
|
|
if (page < 1 || pageSize < 0) {
|
|
|
throw new IllegalArgumentException("分页参数不合法");
|
|
|
}
|
|
|
if (pageSize > 100) {
|
|
|
pageSize = 100;
|
|
|
}
|
|
|
// 2)构建基本查询参数
|
|
|
SearchParam searchParam = searchParamHelper.buildDefault(paramMap);
|
|
|
setHighlight(paramMap, searchParam);
|
|
|
searchParam.setAggregationBuilders(null);
|
|
|
searchParam.setPage(page);
|
|
|
searchParam.setOffset((page - 1) * pageSize);
|
|
|
searchParam.setSize(pageSize);
|
|
|
// 3)设置排序字段
|
|
|
searchParam.setSortBuilders(searchSortHelper.buildSortList(paramMap));
|
|
|
return searchParam;
|
|
|
}
|
|
|
|
|
|
private void setHighlight(final Map<String, String> paramMap, SearchParam searchParam) {
|
|
|
if (StringUtils.isNotBlank(paramMap.get("highlight")) && "1".equals(paramMap.get("highlight")) && StringUtils.isNotBlank(paramMap.get("query"))) {
|
|
|
searchParam.setHighlight(true);
|
|
|
List<String> highlightFields = new ArrayList<String>();
|
|
|
highlightFields.add("productName.productName_ansj");
|
|
|
searchParam.setHighlightFields(highlightFields);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|