Authored by zhaojun2

search brand

... ... @@ -49,6 +49,19 @@ public class BrandController {
return brandService.brands(paramMap);
}
/**
* 关键字查询品牌id
* @param request
* @return
*/
@RequestMapping(method = RequestMethod.GET, value = "/brand/searchBrand")
@ResponseBody
public SearchApiResult searchBrand(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return brandService.searchBrand(paramMap);
}
/**
* 批量获取brandIds对应的商品数量和商品列表[我收藏的品牌-支持个性化]
*
... ...
... ... @@ -55,4 +55,7 @@ public interface IBrandService {
* @return
*/
public SearchApiResult aggProductsByBrandIdInParam(Map<String, String> paramMap);
SearchApiResult searchBrand(Map<String, String> paramMap);
}
... ...
... ... @@ -9,7 +9,6 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.yoho.search.base.utils.ConvertUtils;
import com.yoho.search.service.helper.ProductListHelper;
... ... @@ -56,7 +55,6 @@ import com.yoho.search.service.aggregations.impls.AggregationFactoryService;
import com.yoho.search.service.base.SearchCommonService;
import com.yoho.search.service.base.SearchRequestParams;
import com.yoho.search.service.base.index.BrandIndexBaseService;
import com.yoho.search.service.base.index.ProductIndexBaseService;
import com.yoho.search.service.helper.SearchCommonHelper;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.helper.SearchSortHelper;
... ... @@ -390,6 +388,31 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand
}
}
@Override
public SearchApiResult searchBrand(Map<String, String> paramMap) {
// 1、参数校验
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY))) {
return new SearchApiResult().setCode(400).setMessage("请传query参数");
}
// 1)构建参数
SearchParam searchParam = new SearchParam();
searchParam.setSize(10);
searchParam.setQuery(QueryBuilders.matchQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY)));
// 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取
final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
// 3、执行搜索
SearchResult searchResult = searchCommonService.doSearch(brandIndexName, searchParam);
if (searchResult == null || searchResult.getResultList().isEmpty()) {
return new SearchApiResult().setCode(400).setMessage("empty result");
}
Map<String, List> data = new HashMap<>();
data.put("brands", searchResult.getResultList());
return new SearchApiResult().setCode(200).setData(data);
}
private JSONArray getNewBrandResponseMap(MultiBucketsAggregation aggregation, int size, List<Integer> brandIds, final String realSortField, final SortOrder realSortOrder) {
// 1、首先获取全部品牌的商品列表
Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator();
... ...