Authored by zhaojun2

add querybrandby id

... ... @@ -62,6 +62,18 @@ public class BrandController {
return brandService.searchBrand(paramMap);
}
/**
* id查brand
*/
@RequestMapping(method = RequestMethod.GET, value = "/brand/queryBrandByIds")
@ResponseBody
public SearchApiResult queryBrandByIds(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return brandService.queryBrandsByIds(paramMap);
}
/**
* 批量获取brandIds对应的商品数量和商品列表[我收藏的品牌-支持个性化]
*
... ...
... ... @@ -139,5 +139,7 @@ public class SearchRequestParams {
public static final String PROMOTIONINDEX_COMMONBANNER= "commonBanner";
//brand index field
public static final String BRANDINDEX_ID = "brandIds";
}
... ...
... ... @@ -58,4 +58,6 @@ public interface IBrandService {
SearchApiResult searchBrand(Map<String, String> paramMap);
SearchApiResult queryBrandsByIds(Map<String, String> paramMap);
}
... ...
... ... @@ -16,6 +16,7 @@ import com.yoho.search.service.helper.ProductListHelper;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
... ... @@ -63,6 +64,8 @@ import com.yoho.search.service.scene.common.AbstractCacheAbleService;
import com.yoho.search.service.service.AggregationService;
import com.yoho.search.service.service.IBrandService;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
@Service
public class BrandServiceImpl extends AbstractCacheAbleService implements IBrandService, ApplicationEventPublisherAware {
... ... @@ -387,8 +390,15 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand
}
// 1)构建参数
SearchParam searchParam = new SearchParam();
searchParam.setSize(10);
searchParam.setQuery(QueryBuilders.matchQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY)));
searchParam.setSize(15);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY));
matchQueryBuilder.boost(3);
boolQueryBuilder.should(matchQueryBuilder);
boolQueryBuilder.should(QueryBuilders.matchPhrasePrefixQuery("brandName", paramMap.get(SearchRequestParams.PARAM_SEARCH_QUERY)));
boolQueryBuilder.minimumShouldMatch(1);
searchParam.setQuery(boolQueryBuilder);
// 2、brand数据量比较大,走本地缓存。guavacache缓存中获取result,没有到es中获取
final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
... ... @@ -453,4 +463,31 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand
jsonArray.addAll(productReturnInfoList);
return jsonArray;
}
@Override
public SearchApiResult queryBrandsByIds(Map<String, String> paramMap) {
if (StringUtils.isBlank(paramMap.get(SearchRequestParams.BRANDINDEX_ID))) {
return new SearchApiResult().setCode(400).setMessage("请传brandIds参数");
}
List<Integer> values = ConvertUtils.stringToIntList(paramMap.get(SearchRequestParams.BRANDINDEX_ID), ",");
if(values==null || values.isEmpty()){
return new SearchApiResult().setCode(400).setMessage("empty result");
}
BoolQueryBuilder boolFilter = QueryBuilders.boolQuery();
boolFilter.must(QueryBuilders.termsQuery("id", values));
SearchParam searchParam = new SearchParam();
searchParam.setFiter(boolFilter);
searchParam.setQuery(matchAllQuery());
searchParam.setSize(values.size());
final String brandIndexName = ISearchConstants.INDEX_NAME_BRAND;
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);
}
}
... ...