Authored by unknown

店铺外推荐排除至中分类

... ... @@ -115,12 +115,12 @@ public class SearchLikeNotInShopService {
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, boolean inSameSort) {
// 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, inSameSort ? "30%" : "20%"));
searchParam.setFiter(this.builderFilterBuilder(productInfoInEs, productSkns, inSameSort));
// 3、设置排序规则[按打分排序]
List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
sortBuilders.add(SortBuilders.fieldSort("_score").order(SortOrder.DESC));
... ... @@ -134,7 +134,7 @@ public class SearchLikeNotInShopService {
return searchParam;
}
private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean inSmallSort) {
private QueryBuilder builderFilterBuilder(JSONObject productInfoInEs, List<String> notProductSkns, boolean inSameSort) {
String isGlobalInEs = productInfoInEs.getString("isGlobal");
boolean isGlobal = "Y".equalsIgnoreCase(isGlobalInEs);
BoolQueryBuilder boolFilter = searchLikeHelper.genDefaultSearchLikeFilter(notProductSkns, isGlobal);
... ... @@ -153,11 +153,11 @@ public class SearchLikeNotInShopService {
boolFilter.mustNot(QueryBuilders.termQuery("brandId", brandId));
}
// 3)设置品类信息
Integer smallSortId = productInfoInEs.getInteger("smallSortId");
if (inSmallSort) {
boolFilter.must(QueryBuilders.termQuery("smallSortId", smallSortId));
Integer middleSortId = productInfoInEs.getInteger("middleSortId");
if (inSameSort) {
boolFilter.must(QueryBuilders.termQuery("middleSortId", middleSortId));
} else {
boolFilter.mustNot(QueryBuilders.termQuery("smallSortId", smallSortId));
boolFilter.mustNot(QueryBuilders.termQuery("middleSortId", middleSortId));
boolFilter.mustNot(QueryBuilders.termQuery("smallSort.smallSort_keyword", productInfoInEs.getString("smallSort")));// 有些小分类同名,要排除这种情况。
}
return boolFilter;
... ...