Authored by wangnan

fixbug

package com.yoho.search.service.helper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.yoho.search.base.utils.CharUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.base.SearchRequestParams;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MultiMatchQueryBuilder;
... ... @@ -11,11 +13,9 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.yoho.search.base.utils.CharUtils;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.SearchPageIdDefine;
import com.yoho.search.service.base.SearchDynamicConfigService;
import com.yoho.search.service.base.SearchRequestParams;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Component
public class SearchCommonHelper {
... ... @@ -368,4 +368,19 @@ public class SearchCommonHelper {
return null;
}
/**
* 自定义标签过滤
* @param paramMap
* @return
*/
public BoolQueryBuilder getCustomizeTagBuilder(Map<String, String> paramMap) {
if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
nestedBoolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.customizeTagsId, paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)));
return nestedBoolFilter;
}
return null;
}
}
... ...
... ... @@ -214,11 +214,7 @@ public class SearchServiceHelper {
int[] storeShowStatuss = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STORESHOWSTATUS), ",");
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, storeShowStatuss));
}
//自定义标签
if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ",");
boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids));
}
// //////////////////////////////////////////不支持多个参数///////////////////////////////////////////////////////////
// 是否特价
if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)) {
... ... @@ -452,6 +448,12 @@ public class SearchServiceHelper {
boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder,ScoreMode.None));
}
//自定义标签
BoolQueryBuilder customizeTagsTermsBuilder = searchCommonHelper.getCustomizeTagBuilder(paramMap);
if (customizeTagsTermsBuilder != null) {
boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.customizeTags, customizeTagsTermsBuilder,ScoreMode.None));
}
// 如果contain_seckill!=Y,则过滤掉秒杀商品
if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL) || !"Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL))) {
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
... ... @@ -481,7 +483,9 @@ public class SearchServiceHelper {
if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID)) {
boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.shopId, paramMap.get(SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID).split(",")));
}
// // 通用的过滤请求
// for (String key : paramMap.keySet()) {
// if (key.startsWith("not_")) {
... ...