...
|
...
|
@@ -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);
|
|
|
}
|
|
|
} |
...
|
...
|
|