...
|
...
|
@@ -46,230 +46,228 @@ import java.util.*; |
|
|
@Service
|
|
|
public class ShopsServiceImpl extends BaseService implements IShopsService, ApplicationEventPublisherAware {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ShopsServiceImpl.class);
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ShopsServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private IShopListService shopListService;
|
|
|
@Autowired
|
|
|
private AggregationService aggregationService;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private AggregationFactoryService aggregationFactoryService;
|
|
|
@Autowired
|
|
|
private SearchParamHelper searchParamHelper;
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private IShopListService shopListService;
|
|
|
@Autowired
|
|
|
private AggregationService aggregationService;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
|
|
private AggregationFactoryService aggregationFactoryService;
|
|
|
@Autowired
|
|
|
private SearchParamHelper searchParamHelper;
|
|
|
|
|
|
private ApplicationEventPublisher publisher;
|
|
|
private ApplicationEventPublisher publisher;
|
|
|
|
|
|
@Override
|
|
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
this.publisher = applicationEventPublisher;
|
|
|
}
|
|
|
@Override
|
|
|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
|
|
|
this.publisher = applicationEventPublisher;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = { "page", "order" })
|
|
|
public SearchApiResult group_shops(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、获取topHitCount
|
|
|
int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
// 2、获取聚合的排序规则
|
|
|
String topHitOrder = "heatValue:desc";
|
|
|
if (topHitCount > 0 && searchCommonHelper.isNeedPersonalSearch(paramMap)) {
|
|
|
topHitOrder = "_score:desc";
|
|
|
}
|
|
|
// 3、获取聚合条件
|
|
|
IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount);
|
|
|
// 4、构建searchParam
|
|
|
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false);
|
|
|
searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder()));
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(0);
|
|
|
// 5、从ES中获取
|
|
|
JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam);
|
|
|
if (aggNameAndResponse == null) {
|
|
|
return new SearchApiResult().setData(500).setMessage("exception");
|
|
|
}
|
|
|
// 6、返回生成结果
|
|
|
JSONObject realResult = new JSONObject();
|
|
|
realResult.put("total", aggNameAndResponse.getOrDefault("total", 0));
|
|
|
realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject()));
|
|
|
return new SearchApiResult().setData(realResult).setMessage("groupShops new List.");
|
|
|
} catch (Exception e) {
|
|
|
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getFunctionName(),
|
|
|
EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
|
|
|
return SearchApiResultUtils.errorSearchApiResult("group_shops", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = {"page", "order", "uid", "udid"})
|
|
|
public SearchApiResult group_shops(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、获取topHitCount
|
|
|
int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum"));
|
|
|
// 2、获取聚合的排序规则
|
|
|
String topHitOrder = "heatValue:desc";
|
|
|
|
|
|
@Override
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = { "keyword", "is_encode"})
|
|
|
public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、参数校验
|
|
|
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
if (StringUtils.isBlank(keyword)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
}
|
|
|
|
|
|
// 2、配置keyword的查询字段以及权重设置
|
|
|
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
|
|
|
queryBuilder.operator(Operator.OR);
|
|
|
queryBuilder.field("brandName.brandName_ansj", 100).field("brandName.brandName_pinyin").field("brandNameCn.brandNameCn_ansj").field("brandNameCn.brandNameCn_pinyin")
|
|
|
.field("brandNameEn").field("brandDomain", 50);
|
|
|
queryBuilder.minimumShouldMatch("100%");
|
|
|
// 3、构建searchParam
|
|
|
SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false);
|
|
|
IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount);
|
|
|
searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder()));
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(0);
|
|
|
|
|
|
// 3、构建SearchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
boolFilter.must(QueryBuilders.termQuery("status", 1));
|
|
|
boolFilter.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setSize(5);
|
|
|
// 4、从ES中获取
|
|
|
JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam);
|
|
|
if (aggNameAndResponse == null) {
|
|
|
return new SearchApiResult().setData(500).setMessage("exception");
|
|
|
}
|
|
|
// 5、返回生成结果
|
|
|
JSONObject realResult = new JSONObject();
|
|
|
realResult.put("total", aggNameAndResponse.getOrDefault("total", 0));
|
|
|
realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject()));
|
|
|
return new SearchApiResult().setData(realResult).setMessage("groupShops new List.");
|
|
|
} catch (Exception e) {
|
|
|
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getFunctionName(),
|
|
|
EventReportEnum.SEARCHCONTROLLER_GROUP_SHOPS.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
|
|
|
return SearchApiResultUtils.errorSearchApiResult("group_shops", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 4、根据searchParam查询ES
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
|
|
|
List<String> brandIds = new ArrayList<String>();
|
|
|
Map<String, Map<String, Object>> brandInfoMap = new HashMap<String, Map<String, Object>>();
|
|
|
if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) {
|
|
|
List<Map<String, Object>> result = searchResult.getResultList();
|
|
|
for (Map<String, Object> brandInfo : result) {
|
|
|
String brandId = brandInfo.get("id").toString();
|
|
|
brandInfoMap.put(brandId, brandInfo);
|
|
|
brandIds.add(brandId);
|
|
|
}
|
|
|
}
|
|
|
// 6、判断能否查出符合条件的品牌
|
|
|
String brandId = this.getMaxScoreIdFromPi(brandIds, "brandId");
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
if (StringUtils.isNotBlank(brandId)) {
|
|
|
Map<String, Object> brandInfo = brandInfoMap.get(brandId);
|
|
|
dataMap.put("id", brandInfo.getOrDefault("id", 0));
|
|
|
dataMap.put("brand_name", brandInfo.getOrDefault("brandName", ""));
|
|
|
dataMap.put("brand_ico", brandInfo.getOrDefault("brandIco", ""));
|
|
|
dataMap.put("brand_domain", brandInfo.getOrDefault("brandDomain", ""));
|
|
|
}
|
|
|
return new SearchApiResult().setMessage("shops info").setData(dataMap);
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult("searchShops", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
@Override
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = {"keyword", "is_encode"})
|
|
|
public SearchApiResult searchYohoBrand(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
// 1、参数校验
|
|
|
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
if (StringUtils.isBlank(keyword)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = { "keyword", "is_encode"})
|
|
|
public SearchApiResult searchShopsNew(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
|
|
|
// 1、参数校验
|
|
|
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
if (StringUtils.isBlank(keyword)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
}
|
|
|
// 2、构造返回对象
|
|
|
SearchApiResult searchApiResult = new SearchApiResult();
|
|
|
JSONObject returnMap = new JSONObject();
|
|
|
returnMap.put("shop", null);
|
|
|
returnMap.put("brand", null);
|
|
|
returnMap.put("tblBrand", null);
|
|
|
// 2、配置keyword的查询字段以及权重设置
|
|
|
MultiMatchQueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(keyword);
|
|
|
queryBuilder.operator(Operator.OR);
|
|
|
queryBuilder.field("brandName.brandName_ansj", 100).field("brandName.brandName_pinyin").field("brandNameCn.brandNameCn_ansj").field("brandNameCn.brandNameCn_pinyin")
|
|
|
.field("brandNameEn").field("brandDomain", 50);
|
|
|
queryBuilder.minimumShouldMatch("100%");
|
|
|
|
|
|
// 3、查询店铺和全球购品牌
|
|
|
SearchApiResult shopListApiResult = shopListService.searchShopList(paramMap);
|
|
|
if (shopListApiResult != null) {
|
|
|
JSONObject jsonObject = (JSONObject) shopListApiResult.getData();
|
|
|
JSONArray shop_list = jsonObject.getJSONArray("shop_list");
|
|
|
if (shop_list != null && !shop_list.isEmpty()) {
|
|
|
for (int i = 0; i < shop_list.size(); i++) {
|
|
|
JSONObject shop_info = shop_list.getJSONObject(0);
|
|
|
if (shop_info.getJSONObject("yoho_shop") != null) {
|
|
|
JSONObject yohoShop = this.getShopDataMapFromMap(shop_info.getJSONObject("yoho_shop"));
|
|
|
returnMap.put("shop", yohoShop);
|
|
|
return searchApiResult.setData(returnMap);
|
|
|
}
|
|
|
if (shop_info.getJSONObject("tbl_brand") != null) {
|
|
|
JSONObject tblBrand = this.getTblBrandFromMap(shop_info.getJSONObject("tbl_brand"));
|
|
|
returnMap.put("tblBrand", tblBrand);
|
|
|
return searchApiResult.setData(returnMap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 4、否則获取有货品牌信息
|
|
|
returnMap.put("brand", this.getYohoBrand(paramMap));
|
|
|
// 3、构建SearchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
searchParam.setQuery(queryBuilder);
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
boolFilter.must(QueryBuilders.termQuery("status", 1));
|
|
|
boolFilter.mustNot(QueryBuilders.termQuery("isGlobal", "Y"));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setSize(5);
|
|
|
|
|
|
// 5、返回结果
|
|
|
return searchApiResult.setData(returnMap);
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult("searchShopsNew", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
// 4、根据searchParam查询ES
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_BRAND, searchParam);
|
|
|
List<String> brandIds = new ArrayList<String>();
|
|
|
Map<String, Map<String, Object>> brandInfoMap = new HashMap<String, Map<String, Object>>();
|
|
|
if (searchResult != null && searchResult.getResultList() != null && !searchResult.getResultList().isEmpty()) {
|
|
|
List<Map<String, Object>> result = searchResult.getResultList();
|
|
|
for (Map<String, Object> brandInfo : result) {
|
|
|
String brandId = brandInfo.get("id").toString();
|
|
|
brandInfoMap.put(brandId, brandInfo);
|
|
|
brandIds.add(brandId);
|
|
|
}
|
|
|
}
|
|
|
// 6、判断能否查出符合条件的品牌
|
|
|
String brandId = this.getMaxScoreIdFromPi(brandIds, "brandId");
|
|
|
JSONObject dataMap = new JSONObject();
|
|
|
if (StringUtils.isNotBlank(brandId)) {
|
|
|
Map<String, Object> brandInfo = brandInfoMap.get(brandId);
|
|
|
dataMap.put("id", brandInfo.getOrDefault("id", 0));
|
|
|
dataMap.put("brand_name", brandInfo.getOrDefault("brandName", ""));
|
|
|
dataMap.put("brand_ico", brandInfo.getOrDefault("brandIco", ""));
|
|
|
dataMap.put("brand_domain", brandInfo.getOrDefault("brandDomain", ""));
|
|
|
}
|
|
|
return new SearchApiResult().setMessage("shops info").setData(dataMap);
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult("searchShops", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private JSONObject getShopDataMapFromMap(Map<String, Object> shopInfo) {
|
|
|
JSONObject shopDataMap = new JSONObject();
|
|
|
shopDataMap.put("shop_id", shopInfo.getOrDefault("shop_id", 0));
|
|
|
shopDataMap.put("shop_name", shopInfo.getOrDefault("shop_name", ""));
|
|
|
shopDataMap.put("shop_logo", shopInfo.getOrDefault("shop_logo", ""));
|
|
|
shopDataMap.put("shop_domain", shopInfo.getOrDefault("shop_domain", ""));
|
|
|
shopDataMap.put("shop_type", shopInfo.getOrDefault("shop_type", 0));
|
|
|
shopDataMap.put("decorator_template_type", shopInfo.getOrDefault("decorator_template_type", 0));
|
|
|
return shopDataMap;
|
|
|
}
|
|
|
@Override
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = {"keyword", "is_encode"})
|
|
|
public SearchApiResult searchShopsNew(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
|
|
|
// 1、参数校验
|
|
|
String keyword = SearchKeyWordUtils.getParamKeyword(paramMap, SearchRequestParams.PARAM_SEARCH_SHOPS_KEYWORD);
|
|
|
if (StringUtils.isBlank(keyword)) {
|
|
|
return new SearchApiResult().setCode(400).setMessage("keyword不能为空!");
|
|
|
}
|
|
|
// 2、构造返回对象
|
|
|
SearchApiResult searchApiResult = new SearchApiResult();
|
|
|
JSONObject returnMap = new JSONObject();
|
|
|
returnMap.put("shop", null);
|
|
|
returnMap.put("brand", null);
|
|
|
returnMap.put("tblBrand", null);
|
|
|
|
|
|
private JSONObject getTblBrandFromMap(Map<String, Object> tblBrandInfo) {
|
|
|
JSONObject tblBrand = new JSONObject();
|
|
|
tblBrand.put("brand_id", tblBrandInfo.getOrDefault("id", 0));
|
|
|
tblBrand.put("brand_name", tblBrandInfo.getOrDefault("brand_name", ""));
|
|
|
tblBrand.put("brand_logo", tblBrandInfo.getOrDefault("brand_ico", ""));
|
|
|
return tblBrand;
|
|
|
}
|
|
|
// 3、查询店铺和全球购品牌
|
|
|
SearchApiResult shopListApiResult = shopListService.searchShopList(paramMap);
|
|
|
if (shopListApiResult != null) {
|
|
|
JSONObject jsonObject = (JSONObject) shopListApiResult.getData();
|
|
|
JSONArray shop_list = jsonObject.getJSONArray("shop_list");
|
|
|
if (shop_list != null && !shop_list.isEmpty()) {
|
|
|
for (int i = 0; i < shop_list.size(); i++) {
|
|
|
JSONObject shop_info = shop_list.getJSONObject(0);
|
|
|
if (shop_info.getJSONObject("yoho_shop") != null) {
|
|
|
JSONObject yohoShop = this.getShopDataMapFromMap(shop_info.getJSONObject("yoho_shop"));
|
|
|
returnMap.put("shop", yohoShop);
|
|
|
return searchApiResult.setData(returnMap);
|
|
|
}
|
|
|
if (shop_info.getJSONObject("tbl_brand") != null) {
|
|
|
JSONObject tblBrand = this.getTblBrandFromMap(shop_info.getJSONObject("tbl_brand"));
|
|
|
returnMap.put("tblBrand", tblBrand);
|
|
|
return searchApiResult.setData(returnMap);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 4、否則获取有货品牌信息
|
|
|
returnMap.put("brand", this.getYohoBrand(paramMap));
|
|
|
|
|
|
private JSONObject getYohoBrand(Map<String, String> paramMap) {
|
|
|
SearchApiResult searchApiResult = this.searchYohoBrand(paramMap);
|
|
|
if (searchApiResult == null || searchApiResult.getData() == null) {
|
|
|
return null;
|
|
|
}
|
|
|
JSONObject yohoBrandInfo = (JSONObject) searchApiResult.getData();
|
|
|
return yohoBrandInfo;
|
|
|
}
|
|
|
// 5、返回结果
|
|
|
return searchApiResult.setData(returnMap);
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult("searchShopsNew", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private JSONObject getShopDataMapFromMap(Map<String, Object> shopInfo) {
|
|
|
JSONObject shopDataMap = new JSONObject();
|
|
|
shopDataMap.put("shop_id", shopInfo.getOrDefault("shop_id", 0));
|
|
|
shopDataMap.put("shop_name", shopInfo.getOrDefault("shop_name", ""));
|
|
|
shopDataMap.put("shop_logo", shopInfo.getOrDefault("shop_logo", ""));
|
|
|
shopDataMap.put("shop_domain", shopInfo.getOrDefault("shop_domain", ""));
|
|
|
shopDataMap.put("shop_type", shopInfo.getOrDefault("shop_type", 0));
|
|
|
shopDataMap.put("decorator_template_type", shopInfo.getOrDefault("decorator_template_type", 0));
|
|
|
return shopDataMap;
|
|
|
}
|
|
|
|
|
|
private JSONObject getTblBrandFromMap(Map<String, Object> tblBrandInfo) {
|
|
|
JSONObject tblBrand = new JSONObject();
|
|
|
tblBrand.put("brand_id", tblBrandInfo.getOrDefault("id", 0));
|
|
|
tblBrand.put("brand_name", tblBrandInfo.getOrDefault("brand_name", ""));
|
|
|
tblBrand.put("brand_logo", tblBrandInfo.getOrDefault("brand_ico", ""));
|
|
|
return tblBrand;
|
|
|
}
|
|
|
|
|
|
private JSONObject getYohoBrand(Map<String, String> paramMap) {
|
|
|
SearchApiResult searchApiResult = this.searchYohoBrand(paramMap);
|
|
|
if (searchApiResult == null || searchApiResult.getData() == null) {
|
|
|
return null;
|
|
|
}
|
|
|
JSONObject yohoBrandInfo = (JSONObject) searchApiResult.getData();
|
|
|
return yohoBrandInfo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private String getMaxScoreIdFromPi(List<String> ids, String esFieldName) {
|
|
|
// 查询ProductIndex
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
boolFilter.must(QueryBuilders.termsQuery(esFieldName, ids));
|
|
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
|
|
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, "1"));
|
|
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, "1"));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(1);
|
|
|
// 按shopId打分
|
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
boolQueryBuilder.must(QueryBuilders.matchAllQuery());
|
|
|
double boost = Math.pow(10d, 5d);
|
|
|
for (String id : ids) {
|
|
|
boolQueryBuilder.should(QueryBuilders.termQuery(esFieldName, id).boost((float) boost));
|
|
|
boost = boost / 10;
|
|
|
}
|
|
|
searchParam.setQuery(boolQueryBuilder);
|
|
|
// 按得分排序
|
|
|
List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
|
|
|
sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
|
|
|
searchParam.setSortBuilders(sortBuilders);
|
|
|
// 结果只返回shopId
|
|
|
searchParam.setIncludeFields(Arrays.asList(esFieldName));
|
|
|
// 查询ES
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
|
|
|
return null;
|
|
|
}
|
|
|
return searchResult.getResultList().get(0).get(esFieldName).toString();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 过滤出有库存且有商品上架的店铺id,并且按店铺id排序
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
private String getMaxScoreIdFromPi(List<String> ids, String esFieldName) {
|
|
|
// 查询ProductIndex
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
|
|
|
boolFilter.must(QueryBuilders.termsQuery(esFieldName, ids));
|
|
|
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(1));
|
|
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, "1"));
|
|
|
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, "1"));
|
|
|
searchParam.setFiter(boolFilter);
|
|
|
searchParam.setOffset(0);
|
|
|
searchParam.setSize(1);
|
|
|
// 按shopId打分
|
|
|
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
|
|
|
boolQueryBuilder.must(QueryBuilders.matchAllQuery());
|
|
|
double boost = Math.pow(10d, 5d);
|
|
|
for (String id : ids) {
|
|
|
boolQueryBuilder.should(QueryBuilders.termQuery(esFieldName, id).boost((float) boost));
|
|
|
boost = boost / 10;
|
|
|
}
|
|
|
searchParam.setQuery(boolQueryBuilder);
|
|
|
// 按得分排序
|
|
|
List<SortBuilder<?>> sortBuilders = new ArrayList<SortBuilder<?>>();
|
|
|
sortBuilders.add(SortBuilders.scoreSort().order(SortOrder.DESC));
|
|
|
searchParam.setSortBuilders(sortBuilders);
|
|
|
// 结果只返回shopId
|
|
|
searchParam.setIncludeFields(Arrays.asList(esFieldName));
|
|
|
// 查询ES
|
|
|
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
|
|
|
if (searchResult == null || CollectionUtils.isEmpty(searchResult.getResultList())) {
|
|
|
return null;
|
|
|
}
|
|
|
return searchResult.getResultList().get(0).get(esFieldName).toString();
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|