Authored by unknown

优化返回参数的代码

package com.yoho.search.service.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
... ... @@ -60,12 +58,9 @@ public class AggregationService implements ApplicationEventPublisherAware {
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
}
private SearchResult doSearchForAggregation(IAggregation aggregation, SearchParam searchParam) {
SearchParam searchParamClone = searchParam.clone();
List<String> resultFields = new ArrayList<String>();
resultFields.add("id");
searchParamClone.setResultFields(resultFields);
searchParamClone.setPage(1);
searchParamClone.setOffset(1);
searchParamClone.setSize(0);
... ...
package com.yoho.search.service.service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
... ... @@ -69,11 +68,6 @@ public class TblProductService {
if (boolFilterBuilder.hasClauses()) {
searchParam.setFiter(boolFilterBuilder);
}
// 设置查询结果返回字段
if (StringUtils.isNotBlank(paramMap.get("resultFields"))) {
String resultFields = paramMap.get("resultFields");
searchParam.setResultFields(Arrays.asList(resultFields.split(",")));
}
// 设置分页参数
int offset = StringUtils.isBlank(paramMap.get("offset")) ? 0 : Integer.parseInt(paramMap.get("offset"));
int limit = StringUtils.isBlank(paramMap.get("limit")) ? 10 : Integer.parseInt(paramMap.get("limit"));
... ...
... ... @@ -268,15 +268,12 @@ public class ProductListServiceImpl implements IProductListService {
setHighlight(paramMap, searchParam);
searchParam.setAggregationBuilders(null);
searchParam.setPage(page);
searchParam.setOffset((page - 1) * pageSize);
searchParam.setSize(pageSize);
searchParam.setOffset((page - 1) * 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(",")));
}
// 4)设置不返回的结果
searchParam.setExcludeFields(Arrays.asList("standardNames","style","specialSearchField*"));
return searchParam;
}
... ...
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);
}
}
}
... ...
... ... @@ -6,7 +6,6 @@ import java.util.Map;
import javax.annotation.PostConstruct;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
... ... @@ -82,7 +81,6 @@ public class SearchSortGroupService implements ISearchSortGroupService, Applicat
* @return
* @throws Exception
*/
@SuppressWarnings("deprecation")
public SearchApiResult sortGroup(Map<String, String> paramMap) {
try {
long begin = System.currentTimeMillis();
... ... @@ -117,11 +115,10 @@ public class SearchSortGroupService implements ISearchSortGroupService, Applicat
sortGroupBuilders.add(sortGroupAggregation.getBuilder());
searchParam.setAggregationBuilders(sortGroupBuilders);
// 设置查询结果返回字段
List<String> resultFields = new ArrayList<String>();
resultFields.add("id");
searchParam.setResultFields(resultFields);
searchParam.setSearchType(SearchType.COUNT);
// 设置查询结果
searchParam.setPage(1);
searchParam.setOffset(1);
searchParam.setSize(0);
// 构造返回结果
SearchApiResult searchApiResult = new SearchApiResult();
... ... @@ -176,10 +173,7 @@ public class SearchSortGroupService implements ISearchSortGroupService, Applicat
sortGroupBuilders.add(sortGroupAggregation.getBuilder());
searchParam.setAggregationBuilders(sortGroupBuilders);
// 设置查询结果返回字段
List<String> resultFields = new ArrayList<String>();
resultFields.add("id");
searchParam.setResultFields(resultFields);
// 设置返回结果为0
searchParam.setSize(0);
// 先从缓存中获取,如果能取到,则直接返回
... ...
... ... @@ -75,9 +75,6 @@ public class SelectionForAppImpl implements ISelectionsForApp {
searchParam.setAggregationBuilders(this.getAllAggregationBuilders(paramMap));
// 构造其他参数
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
List<String> resultFields = new ArrayList<String>();
resultFields.add("id");
searchParam.setResultFields(resultFields);
searchParam.setPage(1);
searchParam.setOffset(1);
searchParam.setSize(0);
... ...
... ... @@ -92,9 +92,6 @@ public class SelectionsForPcImpl implements ISelectionsForPc {
public SearchApiResult getSelectionsForPc(Map<String, String> paramMap, BoolQueryBuilder mustFilter) throws Exception {
// 1)构造SearchParam
SearchParam searchParam = searchParamHelper.buildWithMustFilter(paramMap, mustFilter);
List<String> resultFields = new ArrayList<String>();
resultFields.add("id");
searchParam.setResultFields(resultFields);
searchParam.setPage(1);
searchParam.setOffset(1);
searchParam.setSize(0);
... ...
... ... @@ -307,7 +307,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl
sortBuilders.add(SortBuilders.fieldSort("_score").order(SortOrder.DESC));
searchParam.setSortBuilders(sortBuilders);
// 结果只返回shopId
searchParam.setResultFields(Arrays.asList(esFieldName));
searchParam.setIncludeFields(Arrays.asList(esFieldName));
// 查询ES
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
... ...
package com.yoho.search.service.servicenew.scene.common;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
... ... @@ -114,11 +113,6 @@ public class SceneProductListService extends BaseService {
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;
}
... ...
... ... @@ -197,9 +197,6 @@ public class SceneSelectionsService extends BaseService {
searchParam.setAggregationBuilders(this.getAggregationBuilders(aggregations));
// 2)构造其他参数
final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
List<String> resultFields = new ArrayList<String>();
resultFields.add("id");
searchParam.setResultFields(resultFields);
searchParam.setPage(0);
searchParam.setOffset(100);// just for cache
searchParam.setSize(0);
... ...