...
|
...
|
@@ -82,8 +82,7 @@ public class SearchLikeInShopService { |
|
|
|
|
|
// 4、设置第一步SearchParam
|
|
|
List<SearchParam> searchParams = new ArrayList<SearchParam>();
|
|
|
searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize, true));
|
|
|
searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), 10, false));// 防止数量不够,可以用不同品类的补全
|
|
|
searchParams.add(this.builderSearchParam(productInfoInEs, Arrays.asList(productSkn), pageSize));
|
|
|
|
|
|
// 5、从缓存中获取数据,有则直接返回
|
|
|
String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
...
|
...
|
@@ -114,12 +113,12 @@ public class SearchLikeInShopService { |
|
|
return new SearchApiResult().setData(result);
|
|
|
}
|
|
|
|
|
|
private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize, boolean inSmallSort) {
|
|
|
private SearchParam builderSearchParam(JSONObject productInfoInEs, List<String> productSkns, int pageSize) {
|
|
|
// 1、设置SearchParam
|
|
|
SearchParam searchParam = new SearchParam();
|
|
|
// 2)设置query和filter
|
|
|
searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, inSmallSort ? "30%" : "20%"));
|
|
|
searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns, inSmallSort));
|
|
|
searchParam.setQuery(this.builderQueryBuilder(productInfoInEs, "20%"));
|
|
|
searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns));
|
|
|
// 3、设置排序规则[按打分排序]
|
|
|
List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
|
|
|
sortBuilders.add(SortBuilders.fieldSort("_score").order(SortOrder.DESC));
|
...
|
...
|
@@ -133,7 +132,7 @@ public class SearchLikeInShopService { |
|
|
return searchParam;
|
|
|
}
|
|
|
|
|
|
private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean inSmallSort) {
|
|
|
private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns) {
|
|
|
String isGlobalInEs = productInfoInEs.getString("isGlobal");
|
|
|
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
|
|
|
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal);
|
...
|
...
|
@@ -151,16 +150,6 @@ public class SearchLikeInShopService { |
|
|
} else if (searchLikeHelper.isLegalInteger(brandId)) {
|
|
|
boolFilter.must(QueryBuilders.termQuery("brandId", brandId));
|
|
|
}
|
|
|
// 3)设置品类信息
|
|
|
Integer smallSortId = productInfoInEs.getInteger("smallSortId");
|
|
|
if (!searchLikeHelper.isLegalInteger(smallSortId)) {
|
|
|
return boolFilter;
|
|
|
}
|
|
|
if (inSmallSort) {
|
|
|
boolFilter.must(QueryBuilders.termQuery("smallSortId", smallSortId));
|
|
|
} else {
|
|
|
boolFilter.mustNot(QueryBuilders.termQuery("smallSortId", smallSortId));
|
|
|
}
|
|
|
return boolFilter;
|
|
|
}
|
|
|
|
...
|
...
|
|