Authored by 胡古飞

使用ProductIndexEsField重构constructFilterBuilder

... ... @@ -3,12 +3,14 @@ package com.yoho.search.service.service.helper;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.base.utils.DateUtil;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.service.SearchCommonService;
import com.yoho.search.service.service.SearchDynamicConfigService;
import com.yoho.search.service.service.SearchKeyWordService;
import com.yoho.search.service.utils.SearchRequestParams;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.*;
import org.slf4j.Logger;
... ... @@ -27,7 +29,6 @@ public class SearchServiceHelper {
@Autowired
private SearchCommonHelper searchCommonHelper;
@Autowired
private SearchKeyWordService searchKeyWordService;
@Autowired
... ... @@ -61,7 +62,7 @@ public class SearchServiceHelper {
// 3.如果查询的是skn,则直接走productSkn_ansj这个字段
if (searchCommonHelper.isQuerySkn(keyword)) {
queryBuilder.field("productSkn.productSkn_ansj");
queryBuilder.field(ProductIndexEsField.productSkn_productSkn_ansj);
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
return queryBuilder;
}
... ... @@ -108,7 +109,7 @@ public class SearchServiceHelper {
// 3.如果查询的是skn,则直接走productSkn_ansj这个字段
if (searchCommonHelper.isQuerySkn(keyword)) {
queryBuilder.field("productSkn.productSkn_ansj");
queryBuilder.field(ProductIndexEsField.productSkn_productSkn_ansj);
queryBuilder.operator(MatchQueryBuilder.Operator.OR);
return queryBuilder;
}
... ... @@ -196,63 +197,56 @@ public class SearchServiceHelper {
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_BRAND) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_BRAND))
&& !SearchRequestParams.PARAM_SEARCH_BRAND.equals(filterParamName)) {
int[] brandids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_BRAND), ",");
boolFilter.must(QueryBuilders.termsQuery("brandId", brandids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.brandId, brandids));
}
// 全局降分品牌过滤
// if
// ("Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND)))
// {
// boolFilter.mustNot(QueryBuilders.termQuery("isForbiddenSortBrand",
// 1));
// }
if ("Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_GLOBAL_FILTER_BRAND)) && StringUtils.isNotBlank(paramMap.get("pageId"))) {
boolFilter.mustNot(QueryBuilders.termQuery("forbiddenPageIds", paramMap.get("pageId")));
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.forbiddenPageIds, paramMap.get("pageId")));
}
// 店铺
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SHOP) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP))
&& !SearchRequestParams.PARAM_SEARCH_SHOP.equals(filterParamName)) {
int[] shopids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SHOP), ",");
boolFilter.must(QueryBuilders.termsQuery("shopId", shopids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.shopId, shopids));
}
// 大分类
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_MAXSORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT))
&& !SearchRequestParams.PARAM_SEARCH_MAXSORT.equals(filterParamName)) {
int[] maxsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MAXSORT), ",");
boolFilter.must(QueryBuilders.termsQuery("maxSortId", maxsortids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.maxSortId, maxsortids));
}
// 中类
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_MIDDLESORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT))
&& !SearchRequestParams.PARAM_SEARCH_MAXSORT.equals(filterParamName)) {
int[] middlesortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_MIDDLESORT), ",");
boolFilter.must(QueryBuilders.termsQuery("middleSortId", middlesortids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.middleSortId, middlesortids));
}
// 小类
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SMALLSORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT))) {
int[] smallsortids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SMALLSORT), ",");
boolFilter.must(QueryBuilders.termsQuery("smallSortId", smallsortids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.smallSortId, smallsortids));
}
// 大中小分类
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_COMMONSORT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_COMMONSORT))) {
int[] commonSortIds = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_COMMONSORT), ",");
BoolQueryBuilder commonSortIdFilter = QueryBuilders.boolQuery();
commonSortIdFilter.should(QueryBuilders.termsQuery("maxSortId", commonSortIds));
commonSortIdFilter.should(QueryBuilders.termsQuery("middleSortId", commonSortIds));
commonSortIdFilter.should(QueryBuilders.termsQuery("smallSortId", commonSortIds));
commonSortIdFilter.should(QueryBuilders.termsQuery(ProductIndexEsField.maxSortId, commonSortIds));
commonSortIdFilter.should(QueryBuilders.termsQuery(ProductIndexEsField.middleSortId, commonSortIds));
commonSortIdFilter.should(QueryBuilders.termsQuery(ProductIndexEsField.smallSortId, commonSortIds));
boolFilter.must(commonSortIdFilter);
}
// 颜色
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_COLOR) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_COLOR))
&& !SearchRequestParams.PARAM_SEARCH_COLOR.equals(filterParamName)) {
int[] colorids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_COLOR), ",");
boolFilter.must(QueryBuilders.termsQuery("colorIds", colorids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.colorIds, colorids));
}
// 尺码
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SIZE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SIZE))
&& !SearchRequestParams.PARAM_SEARCH_SIZE.equals(filterParamName)) {
int[] sizeids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_SIZE), ",");
boolFilter.must(QueryBuilders.termsQuery("sizeIds", sizeids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.sizeIds, sizeids));
}
// 销售价格
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_PRICE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_PRICE))
... ... @@ -263,34 +257,33 @@ public class SearchServiceHelper {
}
double begin = Double.parseDouble(prices[0]);
double end = Double.parseDouble(prices[1]);
boolFilter.must(QueryBuilders.rangeQuery("salesPrice").gte(begin).lte(end));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.salesPrice).gte(begin).lte(end));
}
// 性别
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_GENDER) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER))
&& !SearchRequestParams.PARAM_SEARCH_GENDER.equals(filterParamName)) {
int[] genders = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_GENDER), ",");
// boolFilter.must(FilterBuilders.termsFilter("gender", genders));
boolFilter.must(QueryBuilders.termsQuery("gender", genders));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.gender, genders));
}
// 是否特价
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER))) {
boolFilter.must(QueryBuilders.termQuery(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER, paramMap.get(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.specialoffer, paramMap.get(SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)));
}
// 是否打折
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT))) {
boolFilter.must(QueryBuilders.termQuery("isDiscount", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isDiscount, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDISCOUNT)));
}
// 是否为学生价
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE))) {
boolFilter.must(QueryBuilders.termQuery(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE, paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isStudentPrice, paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTPRICE)));
}
// 是否学生返币
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE))) {
boolFilter.must(QueryBuilders.termQuery("isstudentrebate", paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isstudentrebate, paramMap.get(SearchRequestParams.PARAM_SEARCH_STUDENTREBATE)));
}
// 是否支持分期
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT))) {
boolFilter.must(QueryBuilders.termQuery(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isInstalment, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISINSTALMENT)));
}
// 属性(待研究)
if (!"parameter".equals(filterParamName)) {
... ... @@ -309,22 +302,22 @@ public class SearchServiceHelper {
for (long standard : standards) {
// boolFilter.must(FilterBuilders.termFilter("standardIds",
// standard));
boolFilter.must(QueryBuilders.termQuery("standardIds", standard));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.standardIds, standard));
}
}
}
// 是否在售
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISSALES) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISSALES))) {
boolFilter.must(QueryBuilders.termQuery("isSales", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISSALES)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isSales, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISSALES)));
}
// 促销标记
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISPROMOTION) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISPROMOTION))) {
int[] ispromotions = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISPROMOTION), ",");
boolFilter.must(QueryBuilders.termsQuery("ispromotion", ispromotions));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.ispromotion, ispromotions));
}
// vip折扣类型
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE))) {
boolFilter.must(QueryBuilders.termQuery("vipDiscountType", paramMap.get(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.vipDiscountType, paramMap.get(SearchRequestParams.PARAM_SEARCH_VIPDISCOUNTTYPE)));
}
// 促销折扣
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_PD) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_PD))) {
... ... @@ -334,15 +327,15 @@ public class SearchServiceHelper {
}
double begin = Double.parseDouble(discounts[0]);
double end = Double.parseDouble(discounts[1]);
boolFilter.must(QueryBuilders.rangeQuery("promotionDiscount").gte(begin).lte(end));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.promotionDiscount).gte(begin).lte(end));
}
// 商品属性 1正常商品 2赠品
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE))) {
boolFilter.must(QueryBuilders.termQuery("attribute", paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.attribute, paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE)));
}
// 商品属性 1赠品 2正常商品
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT))) {
boolFilter.mustNot(QueryBuilders.termQuery("attribute", paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT)));
boolFilter.mustNot(QueryBuilders.termQuery(ProductIndexEsField.attribute, paramMap.get(SearchRequestParams.PARAM_SEARCH_ATTRIBUTE_NOT)));
}
// 库存
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STOCKNUM) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STOCKNUM))) {
... ... @@ -350,64 +343,65 @@ public class SearchServiceHelper {
long now = DateUtil.getTimeSecondByDate(new Date());
int begin = Integer.parseInt(paramMap.get(SearchRequestParams.PARAM_SEARCH_STOCKNUM));
if (begin == 0) {
boolFilter.must(QueryBuilders.termQuery("storageNum", begin));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.storageNum, begin));
} else {
if (StringUtils.isNotBlank(paramMap.get("showSoldOut")) && paramMap.get("showSoldOut").equals("1")) {
boolFilter.should(QueryBuilders.rangeQuery("storageNum").gte(begin)).should(
QueryBuilders.boolQuery().must(QueryBuilders.termQuery("storageNum", 0)).must(QueryBuilders.rangeQuery("storageUpdateTime").gte(now)));
boolFilter.should(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(begin)).should(
QueryBuilders.boolQuery().must(QueryBuilders.termQuery(ProductIndexEsField.storageNum, 0))
.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageUpdateTime).gte(now)));
} else {
boolFilter.must(QueryBuilders.rangeQuery("storageNum").gte(begin));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.storageNum).gte(begin));
}
}
}
// 是否限量
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISLIMITED) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITED))) {
boolFilter.must(QueryBuilders.termQuery("islimited", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITED)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.islimited, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITED)));
}
// 是否限购
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY))) {
boolFilter.must(QueryBuilders.termQuery("isLimitbuy", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isLimitbuy, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISLIMITEDBUY)));
}
// 是否预售
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISADVANCE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISADVANCE))) {
boolFilter.must(QueryBuilders.termQuery("isAdvance", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISADVANCE)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isAdvance, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISADVANCE)));
}// 是否定金预售
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE))) {
boolFilter.must(QueryBuilders.termQuery("isDepositAdvance", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isDepositAdvance, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISDESPOSITADVANCE)));
}
// 是否新品
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISNEW) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISNEW))) {
boolFilter.must(QueryBuilders.termQuery("isnew", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISNEW)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isnew, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISNEW)));
}
// 是否奥莱
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_ISOUTLETS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_ISOUTLETS))) {
boolFilter.must(QueryBuilders.termQuery("isOutlets", paramMap.get(SearchRequestParams.PARAM_SEARCH_ISOUTLETS)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.isOutlets, paramMap.get(SearchRequestParams.PARAM_SEARCH_ISOUTLETS)));
}
// 状态是否上架
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STATUS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STATUS))) {
boolFilter.must(QueryBuilders.termQuery(SearchRequestParams.PARAM_SEARCH_STATUS, paramMap.get(SearchRequestParams.PARAM_SEARCH_STATUS)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.status, paramMap.get(SearchRequestParams.PARAM_SEARCH_STATUS)));
}
// APP类型
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_APPTYPE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_APPTYPE))
&& !SearchRequestParams.PARAM_SEARCH_APPTYPE.equals(filterParamName)) {
int[] appTypes = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_APPTYPE), ",");
boolFilter.must(QueryBuilders.termsQuery("appType", appTypes));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.appType, appTypes));
}
// 风格
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_STYLE) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_STYLE))
&& !SearchRequestParams.PARAM_SEARCH_STYLE.equals(filterParamName)) {
int[] styleids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STYLE), ",");
boolFilter.must(QueryBuilders.termsQuery("styleIds", styleids));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.styleIds, styleids));
}
// 销售平台 (网站、APP、现场)
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS))) {
boolFilter.must(QueryBuilders.termQuery("sellChannels", paramMap.get(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS)));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.sellChannels, paramMap.get(SearchRequestParams.PARAM_SEARCH_SELLCHANNELS)));
}
if (paramMap.containsKey("folder_id") && StringUtils.isNotBlank(paramMap.get("folder_id"))) {
boolFilter.must(QueryBuilders.termQuery("folderId", paramMap.get("folder_id")));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.folderId, paramMap.get("folder_id")));
}
if (paramMap.containsKey("series_id") && StringUtils.isNotBlank(paramMap.get("series_id"))) {
boolFilter.must(QueryBuilders.termQuery("seriesId", paramMap.get("series_id")));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.seriesId, paramMap.get("series_id")));
}
// 促销折扣
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_PDINT) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_PDINT))) {
... ... @@ -417,7 +411,7 @@ public class SearchServiceHelper {
}
double begin = Double.parseDouble(discounts[0]);
double end = Double.parseDouble(discounts[1]);
boolFilter.must(QueryBuilders.rangeQuery("promotionDiscountInt").gte(begin).lte(end));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.promotionDiscountInt).gte(begin).lte(end));
}
// 首次上架时间间隔
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_FIRST_SHELVE_TIME))
... ... @@ -428,7 +422,7 @@ public class SearchServiceHelper {
}
double begin = Double.parseDouble(times[0]);
double end = Double.parseDouble(times[1]);
boolFilter.must(QueryBuilders.rangeQuery("firstShelveTime").from(begin).to(end));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.firstShelveTime).from(begin).to(end));
}
// 上架日期间隔
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_SHELVETIME) && !SearchRequestParams.PARAM_SEARCH_SHELVETIME.equals(filterParamName)) {
... ... @@ -438,7 +432,7 @@ public class SearchServiceHelper {
}
double begin = Double.parseDouble(times[0]);
double end = Double.parseDouble(times[1]);
boolFilter.must(QueryBuilders.rangeQuery("shelveTime").from(begin).to(end));
boolFilter.must(QueryBuilders.rangeQuery(ProductIndexEsField.shelveTime).from(begin).to(end));
}
// 上架日期
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_DAY) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_DAY))) {
... ... @@ -446,49 +440,50 @@ public class SearchServiceHelper {
if (!DateUtil.isDate(recentDay)) {
throw new IllegalArgumentException("wrong date format");
}
boolFilter.must(QueryBuilders.termQuery("shelveDay", recentDay));
boolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.shelveDay, recentDay));
}
// 增加活动模板相关的过滤条件
BoolQueryBuilder activitiesTermsBuilder = searchCommonHelper.getActivitiesTermsBuilder(paramMap);
if (activitiesTermsBuilder != null) {
boolFilter.must(QueryBuilders.nestedQuery("activities", activitiesTermsBuilder));
boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder));
}
// 断码(breakingRate>=50 || basePinRatio>=3.5)
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_BREAKING) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_BREAKING))) {
String breaking = paramMap.get(SearchRequestParams.PARAM_SEARCH_BREAKING);
if ("1".equals(breaking)) {
boolFilter.must(QueryBuilders.boolQuery().should(QueryBuilders.rangeQuery("breakingRate").from(50)).should(QueryBuilders.rangeQuery("basePinRatio").from(3.5)));
boolFilter.must(QueryBuilders.boolQuery().should(QueryBuilders.rangeQuery(ProductIndexEsField.breakingRate).from(50))
.should(QueryBuilders.rangeQuery(ProductIndexEsField.basePinRatio).from(3.5)));
}
}
// SKN
if (paramMap.containsKey(SearchRequestParams.PARAM_SYNC_SKN) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SYNC_SKN))) {
String sknString = paramMap.get(SearchRequestParams.PARAM_SYNC_SKN);
boolFilter.must(QueryBuilders.termsQuery("productSkn", sknString.split(",")));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.productSkn, sknString.split(",")));
}
// 年龄层
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_AGELEVEL) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_AGELEVEL))
&& !SearchRequestParams.PARAM_SEARCH_AGELEVEL.equals(filterParamName)) {
int[] ageLevels = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_AGELEVEL), ",");
boolFilter.must(QueryBuilders.termsQuery("ageLevel", ageLevels));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.ageLevel, ageLevels));
}
// 判断是否需要包含全球购[全球购的开关]
if (!searchCommonHelper.containGlobal(paramMap)) {
boolFilter.mustNot(QueryBuilders.termsQuery("isGlobal", "Y"));
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, "Y"));
}
// 判断是否需要是筛选全球购[全球购的筛选项]
if (paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL) && StringUtils.isNotBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL))) {
boolFilter.must(QueryBuilders.termsQuery("isGlobal", paramMap.get(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL)));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.isGlobal, paramMap.get(SearchRequestParams.PARAM_SEARCH_IS_GLOBAL)));
}
// 如果contain_seckill!=Y,则过滤掉秒杀商品
if (!paramMap.containsKey("contain_seckill") || !"Y".equals(paramMap.get("contain_seckill"))) {
boolFilter.mustNot(QueryBuilders.termsQuery("isSeckill", "Y"));
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
}
// 用户VIP级别过滤
String userVipLevel = (paramMap.get(SearchRequestParams.USER_VIP_LEVEL));
if (StringUtils.isNotBlank(userVipLevel)) {
List<String> userVipLevels = this.getUserVipLevels(userVipLevel);
if (userVipLevels != null) {
boolFilter.must(QueryBuilders.termsQuery("vipLevels", userVipLevels));
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.vipLevels, userVipLevels));
}
}
// 通用的过滤请求
... ...