Authored by wangnan

fixbug

1 package com.yoho.search.service.helper; 1 package com.yoho.search.service.helper;
2 2
3 -import java.util.ArrayList;  
4 -import java.util.List;  
5 -import java.util.Map;  
6 - 3 +import com.yoho.search.base.utils.CharUtils;
  4 +import com.yoho.search.base.utils.ISearchConstants;
  5 +import com.yoho.search.base.utils.ProductIndexEsField;
  6 +import com.yoho.search.base.utils.SearchPageIdDefine;
  7 +import com.yoho.search.service.base.SearchDynamicConfigService;
  8 +import com.yoho.search.service.base.SearchRequestParams;
7 import org.apache.commons.lang.StringUtils; 9 import org.apache.commons.lang.StringUtils;
8 import org.elasticsearch.index.query.BoolQueryBuilder; 10 import org.elasticsearch.index.query.BoolQueryBuilder;
9 import org.elasticsearch.index.query.MultiMatchQueryBuilder; 11 import org.elasticsearch.index.query.MultiMatchQueryBuilder;
@@ -11,11 +13,9 @@ import org.elasticsearch.index.query.QueryBuilders; @@ -11,11 +13,9 @@ import org.elasticsearch.index.query.QueryBuilders;
11 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.stereotype.Component; 14 import org.springframework.stereotype.Component;
13 15
14 -import com.yoho.search.base.utils.CharUtils;  
15 -import com.yoho.search.base.utils.ISearchConstants;  
16 -import com.yoho.search.base.utils.SearchPageIdDefine;  
17 -import com.yoho.search.service.base.SearchDynamicConfigService;  
18 -import com.yoho.search.service.base.SearchRequestParams; 16 +import java.util.ArrayList;
  17 +import java.util.List;
  18 +import java.util.Map;
19 19
20 @Component 20 @Component
21 public class SearchCommonHelper { 21 public class SearchCommonHelper {
@@ -368,4 +368,19 @@ public class SearchCommonHelper { @@ -368,4 +368,19 @@ public class SearchCommonHelper {
368 return null; 368 return null;
369 } 369 }
370 370
  371 +
  372 + /**
  373 + * 自定义标签过滤
  374 + * @param paramMap
  375 + * @return
  376 + */
  377 + public BoolQueryBuilder getCustomizeTagBuilder(Map<String, String> paramMap) {
  378 + if (paramMap.containsKey(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG) && StringUtils.isNotBlank(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {
  379 + BoolQueryBuilder nestedBoolFilter = QueryBuilders.boolQuery();
  380 + nestedBoolFilter.must(QueryBuilders.termQuery(ProductIndexEsField.customizeTagsId, paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)));
  381 + return nestedBoolFilter;
  382 + }
  383 + return null;
  384 + }
  385 +
371 } 386 }
@@ -214,11 +214,7 @@ public class SearchServiceHelper { @@ -214,11 +214,7 @@ public class SearchServiceHelper {
214 int[] storeShowStatuss = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STORESHOWSTATUS), ","); 214 int[] storeShowStatuss = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.PARAM_SEARCH_STORESHOWSTATUS), ",");
215 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, storeShowStatuss)); 215 boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.storeShowStatus, storeShowStatuss));
216 } 216 }
217 - //自定义标签  
218 - if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG)) {  
219 - int[] ids = ConvertUtils.stringToIntArray(paramMap.get(SearchRequestParams.SHOPS_PARAM_CUSTOMIZE_TAG), ",");  
220 - boolFilter.must(QueryBuilders.termsQuery(ProductIndexEsField.customizeTagsId, ids));  
221 - } 217 +
222 // //////////////////////////////////////////不支持多个参数/////////////////////////////////////////////////////////// 218 // //////////////////////////////////////////不支持多个参数///////////////////////////////////////////////////////////
223 // 是否特价 219 // 是否特价
224 if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)) { 220 if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_SPECIALOFFER)) {
@@ -452,6 +448,12 @@ public class SearchServiceHelper { @@ -452,6 +448,12 @@ public class SearchServiceHelper {
452 boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder,ScoreMode.None)); 448 boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.activities, activitiesTermsBuilder,ScoreMode.None));
453 } 449 }
454 450
  451 + //自定义标签
  452 + BoolQueryBuilder customizeTagsTermsBuilder = searchCommonHelper.getCustomizeTagBuilder(paramMap);
  453 + if (customizeTagsTermsBuilder != null) {
  454 + boolFilter.must(QueryBuilders.nestedQuery(ProductIndexEsField.customizeTags, customizeTagsTermsBuilder,ScoreMode.None));
  455 + }
  456 +
455 // 如果contain_seckill!=Y,则过滤掉秒杀商品 457 // 如果contain_seckill!=Y,则过滤掉秒杀商品
456 if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL) || !"Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL))) { 458 if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL) || !"Y".equals(paramMap.get(SearchRequestParams.PARAM_SEARCH_CONTAIN_SECKILL))) {
457 boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y")); 459 boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.isSeckill, "Y"));
@@ -481,7 +483,9 @@ public class SearchServiceHelper { @@ -481,7 +483,9 @@ public class SearchServiceHelper {
481 if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID)) { 483 if (this.checkParamNotFiltered(paramMap, filterParamName, SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID)) {
482 boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.shopId, paramMap.get(SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID).split(","))); 484 boolFilter.mustNot(QueryBuilders.termsQuery(ProductIndexEsField.shopId, paramMap.get(SearchRequestParams.PARAM_SEARCH_NOT_SHOP_ID).split(",")));
483 } 485 }
484 - 486 +
  487 +
  488 +
485 // // 通用的过滤请求 489 // // 通用的过滤请求
486 // for (String key : paramMap.keySet()) { 490 // for (String key : paramMap.keySet()) {
487 // if (key.startsWith("not_")) { 491 // if (key.startsWith("not_")) {