Authored by zhaojun2

no message

@@ -62,6 +62,18 @@ public class BrandController { @@ -62,6 +62,18 @@ public class BrandController {
62 return brandService.searchBrand(paramMap); 62 return brandService.searchBrand(paramMap);
63 } 63 }
64 64
  65 +
  66 + /**
  67 + * id查brand
  68 + */
  69 + @RequestMapping(method = RequestMethod.GET, value = "/brand/queryBrandByIds")
  70 + @ResponseBody
  71 + public SearchApiResult queryBrandByIds(HttpServletRequest request) {
  72 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  73 + return brandService.queryBrandsByIds(paramMap);
  74 + }
  75 +
  76 +
65 /** 77 /**
66 * 批量获取brandIds对应的商品数量和商品列表[我收藏的品牌-支持个性化] 78 * 批量获取brandIds对应的商品数量和商品列表[我收藏的品牌-支持个性化]
67 * 79 *
@@ -139,5 +139,7 @@ public class SearchRequestParams { @@ -139,5 +139,7 @@ public class SearchRequestParams {
139 public static final String PROMOTIONINDEX_COMMONBANNER= "commonBanner"; 139 public static final String PROMOTIONINDEX_COMMONBANNER= "commonBanner";
140 140
141 141
  142 + //brand index field
  143 + public static final String BRANDINDEX_ID = "brandIds";
142 144
143 } 145 }
@@ -58,4 +58,6 @@ public interface IBrandService { @@ -58,4 +58,6 @@ public interface IBrandService {
58 58
59 SearchApiResult searchBrand(Map<String, String> paramMap); 59 SearchApiResult searchBrand(Map<String, String> paramMap);
60 60
  61 + SearchApiResult queryBrandsByIds(Map<String, String> paramMap);
  62 +
61 } 63 }
@@ -16,6 +16,7 @@ import com.yoho.search.service.helper.ProductListHelper; @@ -16,6 +16,7 @@ import com.yoho.search.service.helper.ProductListHelper;
16 import org.apache.commons.collections.MapUtils; 16 import org.apache.commons.collections.MapUtils;
17 import org.apache.commons.lang.StringUtils; 17 import org.apache.commons.lang.StringUtils;
18 import org.elasticsearch.index.query.BoolQueryBuilder; 18 import org.elasticsearch.index.query.BoolQueryBuilder;
  19 +import org.elasticsearch.index.query.MatchQueryBuilder;
19 import org.elasticsearch.index.query.QueryBuilders; 20 import org.elasticsearch.index.query.QueryBuilders;
20 import org.elasticsearch.search.SearchHit; 21 import org.elasticsearch.search.SearchHit;
21 import org.elasticsearch.search.SearchHits; 22 import org.elasticsearch.search.SearchHits;
@@ -63,6 +64,8 @@ import com.yoho.search.service.scene.common.AbstractCacheAbleService; @@ -63,6 +64,8 @@ import com.yoho.search.service.scene.common.AbstractCacheAbleService;
63 import com.yoho.search.service.service.AggregationService; 64 import com.yoho.search.service.service.AggregationService;
64 import com.yoho.search.service.service.IBrandService; 65 import com.yoho.search.service.service.IBrandService;
65 66
  67 +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
  68 +
66 @Service 69 @Service
67 public class BrandServiceImpl extends AbstractCacheAbleService implements IBrandService, ApplicationEventPublisherAware { 70 public class BrandServiceImpl extends AbstractCacheAbleService implements IBrandService, ApplicationEventPublisherAware {
68 71
@@ -387,8 +390,15 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand @@ -387,8 +390,15 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand
387 } 390 }
388 // 1)构建参数 391 // 1)构建参数
389 SearchParam searchParam = new SearchParam(); 392 SearchParam searchParam = new SearchParam();
390 - searchParam.setSize(10);  
391 - searchParam.setQuery(QueryBuilders.matchQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))); 393 + searchParam.setSize(15);
  394 +
  395 + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
  396 + MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY));
  397 + matchQueryBuilder.boost(3);
  398 + boolQueryBuilder.should(matchQueryBuilder);
  399 + boolQueryBuilder.should(QueryBuilders.matchPhrasePrefixQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY)));
  400 + boolQueryBuilder.minimumShouldMatch(1);
  401 + searchParam.setQuery(boolQueryBuilder);
392 402
393 // 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取 403 // 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取
394 final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND; 404 final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
@@ -453,4 +463,31 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand @@ -453,4 +463,31 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand
453 jsonArray.addAll(productReturnInfoList); 463 jsonArray.addAll(productReturnInfoList);
454 return jsonArray; 464 return jsonArray;
455 } 465 }
  466 +
  467 + @Override
  468 + public SearchApiResult queryBrandsByIds(Map<String, String> paramMap) {
  469 + if (StringUtils.isBlank(paramMap.get(SearchRequestParams.BRANDINDEX_ID))) {
  470 + return new SearchApiResult().setCode(400).setMessage("请传brandIds参数");
  471 + }
  472 +
  473 + List<Integer> values = ConvertUtils.stringToIntList(paramMap.get(SearchRequestParams.BRANDINDEX_ID), ",");
  474 + if(values==null || values.isEmpty()){
  475 + return new SearchApiResult().setCode(400).setMessage("empty result");
  476 + }
  477 + BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
  478 + boolFilter.must(QueryBuilders.termsQuery("id", values));
  479 +
  480 + SearchParam searchParam = new SearchParam();
  481 + searchParam.setFiter(boolFilter);
  482 + searchParam.setQuery(matchAllQuery());
  483 + searchParam.setSize(values.size());
  484 + final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
  485 + SearchResult searchResult = searchCommonService.doSearch(brandIndexName, searchParam);
  486 + if (searchResult == null || searchResult.getResultList().isEmpty()) {
  487 + return new SearchApiResult().setCode(400).setMessage("empty result");
  488 + }
  489 + Map<String, List> data = new HashMap<>();
  490 + data.put("brands", searchResult.getResultList());
  491 + return new SearchApiResult().setCode(200).setData(data);
  492 + }
456 } 493 }