Authored by hugufei

Merge branch 'recall_searchbrand' into recall_config

@@ -49,6 +49,19 @@ public class BrandController { @@ -49,6 +49,19 @@ public class BrandController {
49 return brandService.brands(paramMap); 49 return brandService.brands(paramMap);
50 } 50 }
51 51
  52 +
  53 + /**
  54 + * 关键字查询品牌id
  55 + * @param request
  56 + * @return
  57 + */
  58 + @RequestMapping(method = RequestMethod.GET, value = "/brand/searchBrand")
  59 + @ResponseBody
  60 + public SearchApiResult searchBrand(HttpServletRequest request) {
  61 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  62 + return brandService.searchBrand(paramMap);
  63 + }
  64 +
52 /** 65 /**
53 * 批量获取brandIds对应的商品数量和商品列表[我收藏的品牌-支持个性化] 66 * 批量获取brandIds对应的商品数量和商品列表[我收藏的品牌-支持个性化]
54 * 67 *
@@ -55,4 +55,7 @@ public interface IBrandService { @@ -55,4 +55,7 @@ public interface IBrandService {
55 * @return 55 * @return
56 */ 56 */
57 public SearchApiResult aggProductsByBrandIdInParam(Map<String, String> paramMap); 57 public SearchApiResult aggProductsByBrandIdInParam(Map<String, String> paramMap);
  58 +
  59 + SearchApiResult searchBrand(Map<String, String> paramMap);
  60 +
58 } 61 }
@@ -9,7 +9,6 @@ import java.util.Iterator; @@ -9,7 +9,6 @@ import java.util.Iterator;
9 import java.util.LinkedHashMap; 9 import java.util.LinkedHashMap;
10 import java.util.List; 10 import java.util.List;
11 import java.util.Map; 11 import java.util.Map;
12 -import java.util.Map.Entry;  
13 12
14 import com.yoho.search.base.utils.ConvertUtils; 13 import com.yoho.search.base.utils.ConvertUtils;
15 import com.yoho.search.common.cache.aop.SearchCacheAble; 14 import com.yoho.search.common.cache.aop.SearchCacheAble;
@@ -57,7 +56,6 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService; @@ -57,7 +56,6 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
57 import com.yoho.search.service.base.SearchCommonService; 56 import com.yoho.search.service.base.SearchCommonService;
58 import com.yoho.search.service.base.SearchRequestParams; 57 import com.yoho.search.service.base.SearchRequestParams;
59 import com.yoho.search.service.base.index.BrandIndexBaseService; 58 import com.yoho.search.service.base.index.BrandIndexBaseService;
60 -import com.yoho.search.service.base.index.ProductIndexBaseService;  
61 import com.yoho.search.service.helper.SearchCommonHelper; 59 import com.yoho.search.service.helper.SearchCommonHelper;
62 import com.yoho.search.service.helper.SearchParamHelper; 60 import com.yoho.search.service.helper.SearchParamHelper;
63 import com.yoho.search.service.helper.SearchSortHelper; 61 import com.yoho.search.service.helper.SearchSortHelper;
@@ -380,6 +378,31 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand @@ -380,6 +378,31 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand
380 } 378 }
381 } 379 }
382 380
  381 +
  382 + @Override
  383 + public SearchApiResult searchBrand(Map<String, String> paramMap) {
  384 + // 1、参数校验
  385 + if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
  386 + return new SearchApiResult().setCode(400).setMessage("请传query参数");
  387 + }
  388 + // 1)构建参数
  389 + SearchParam searchParam = new SearchParam();
  390 + searchParam.setSize(10);
  391 + searchParam.setQuery(QueryBuilders.matchQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY)));
  392 +
  393 + // 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取
  394 + final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
  395 + // 3、执行搜索
  396 + SearchResult searchResult = searchCommonService.doSearch(brandIndexName, searchParam);
  397 + if (searchResult == null || searchResult.getResultList().isEmpty()) {
  398 + return new SearchApiResult().setCode(400).setMessage("empty result");
  399 + }
  400 + Map<String, List> data = new HashMap<>();
  401 + data.put("brands", searchResult.getResultList());
  402 + return new SearchApiResult().setCode(200).setData(data);
  403 + }
  404 +
  405 +
383 private JSONArray getNewBrandResponseMap(MultiBucketsAggregation aggregation, int size, List<Integer> brandIds, final String realSortField, final SortOrder realSortOrder) { 406 private JSONArray getNewBrandResponseMap(MultiBucketsAggregation aggregation, int size, List<Integer> brandIds, final String realSortField, final SortOrder realSortOrder) {
384 // 1、首先获取全部品牌的商品列表 407 // 1、首先获取全部品牌的商品列表
385 Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator(); 408 Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();