...
|
...
|
@@ -44,25 +44,16 @@ import java.util.*; |
|
|
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
|
|
|
|
|
@Service
|
|
|
public class BrandListService extends AbstractCacheAbleService implements ApplicationEventPublisherAware {
|
|
|
public class BrandListService implements ApplicationEventPublisherAware {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(BrandListService.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SearchParamHelper searchParamHelper;
|
|
|
@Autowired
|
|
|
private AggregationsService aggregationsService;
|
|
|
@Autowired
|
|
|
private SearchCommonService searchCommonService;
|
|
|
@Autowired
|
|
|
private BrandIndexBaseService brandIndexBaseService;
|
|
|
@Autowired
|
|
|
private AggregationFactory aggregationFactory;
|
|
|
|
|
|
@Override
|
|
|
public SearchCache getSearchCache() {
|
|
|
return searchCacheFactory.getBrandRelatedCache();
|
|
|
}
|
|
|
|
|
|
private ApplicationEventPublisher publisher;
|
|
|
|
...
|
...
|
@@ -71,48 +62,6 @@ public class BrandListService extends AbstractCacheAbleService implements Applic |
|
|
this.publisher = applicationEventPublisher;
|
|
|
}
|
|
|
|
|
|
public SearchApiResult aggAllBrandList(Map<String, String> paramMap) {
|
|
|
try {
|
|
|
logger.info("[func=aggBrand][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis());
|
|
|
return this.aggAllBrandList(paramMap, null);
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult("aggBrand", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public SearchApiResult aggAllBrandList(Map<String, String> paramMap, BoolQueryBuilder mustFilter) {
|
|
|
try {
|
|
|
// 1、构造带filter和query的SearchParam
|
|
|
boolean needPreAggregation = "Y".equals(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_AGG_WITH_PARAM_BRAND, "N")) ? false : true;
|
|
|
SearchParam searchParam = searchParamHelper.buildSearchParam(paramMap, false, mustFilter, needPreAggregation ? "brand" : null);
|
|
|
|
|
|
// 2、构造aggrations
|
|
|
IAggregation brandAggregation = aggregationFactory.getBrandAggregation(paramMap);
|
|
|
searchParam.setAggregationBuilders(Arrays.asList(brandAggregation.getBuilder()));
|
|
|
|
|
|
// 3、从缓存中获取
|
|
|
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
|
|
|
JSONArray cacheJSONArray = searchCacheService.getJSONArrayFromCache(this.searchCache, indexName, searchParam);
|
|
|
if (cacheJSONArray != null) {
|
|
|
SearchCacheMatchLogger.doSearchCacheMatchLog("/productindex/aggBrand.json", paramMap);
|
|
|
return new SearchApiResult().setData(cacheJSONArray);
|
|
|
}
|
|
|
// 4、从ES中获取
|
|
|
JSONObject jsonObject = aggregationsService.getAggNameAndResponse(brandAggregation, searchParam);
|
|
|
if (jsonObject == null) {
|
|
|
return new SearchApiResult().setData(500).setMessage("exception");
|
|
|
}
|
|
|
// 5、生成结果并且加入缓存
|
|
|
JSONArray brandJSONArray = jsonObject.getJSONArray(brandAggregation.aggName());
|
|
|
if (brandJSONArray != null) {
|
|
|
searchCacheService.addJSONArrayToCache(this.searchCache, indexName, searchParam, brandJSONArray);
|
|
|
}
|
|
|
return new SearchApiResult().setData(brandJSONArray);
|
|
|
} catch (Exception e) {
|
|
|
return SearchApiResultUtils.errorSearchApiResult("aggBrand", paramMap, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@SearchCacheAble(cacheInMinute = 30, cacheName = "BRAND_LIST", excludeParams = {"page", "order", "uid", "udid"})
|
|
|
public SearchApiResult brandList(Map<String, String> paramMap) {
|
|
|
try {
|
...
|
...
|
|