Authored by zhaojun2

delete

package com.yoho.search.service.scene.activity;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.ISearchConstants;
import com.yoho.search.base.utils.ProductIndexEsField;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.cache.beans.AbstractCacheComponent;
import com.yoho.search.common.SearchCommonService;
import com.yoho.search.core.es.model.SearchParam;
import com.yoho.search.core.es.model.SearchResult;
import com.yoho.search.service.helper.SearchParamHelper;
import com.yoho.search.service.recall.models.common.ParamQueryFilter;
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
import org.elasticsearch.search.aggregations.Aggregation;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class AggBrandService extends AbstractCacheComponent<List<AggBrand>> {
@Autowired
private SearchCommonService searchCommonService;
@Autowired
private SearchParamHelper searchParamHelper;
public List<AggBrand> aggBrands(ParamQueryFilter paramQueryFilter) {
List<AggBrand> value;
try {
value = queryWithCache(paramQueryFilter, null);
} catch (Exception e) {
return Collections.emptyList();
}
return value != null ? value : Collections.emptyList();
}
private List<AggBrand> genAggBrand(Map<String, Aggregation> aggMaps) {
MultiBucketsAggregation aggregation = (MultiBucketsAggregation)aggMaps.get("brandAgg");
Iterator<? extends MultiBucketsAggregation.Bucket> itSizeAgg = aggregation.getBuckets().iterator();
List<AggBrand> aggBrands = new ArrayList<>();
while (itSizeAgg.hasNext()) {
AggBrand aggBrand = new AggBrand();
MultiBucketsAggregation.Bucket ltSize = itSizeAgg.next();
aggBrand.setBrandId(Integer.valueOf(ltSize.getKeyAsString()));
aggBrand.setCount(Long.valueOf(ltSize.getDocCount()).intValue());
aggBrands.add(aggBrand);
}
return aggBrands;
}
@Override
protected List<AggBrand> doRealQuery(ParamQueryFilter paramQueryFilter, Map<String, String> paramMap) {
List<AbstractAggregationBuilder<?>> aggregationBuilders = new ArrayList<>();
TermsAggregationBuilder firstAggregationBuilder = AggregationBuilders.terms("brandAgg").field(ProductIndexEsField.brandId).size(500);
aggregationBuilders.add(firstAggregationBuilder);
SearchParam searchParam = searchParamHelper.buildSearchParam(paramQueryFilter);
searchParam.setAggregationBuilders(aggregationBuilders);
SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
Map<String, Aggregation> aggregationMap = searchResult.getAggMaps();
return this.genAggBrand(aggregationMap);
}
@Override
protected int cacheTimeInMinute() {
return CacheTimeConstants.CACHE_10_MINUTE;
}
@Override
protected String cacheSceneKey() {
return "BRAND_PRODUCT_LIST_NEW";
}
}
package com.yoho.search.service.scene.shopbrand;
import java.util.List;
import java.util.Map;
public class AggProductResponse {
private Integer count;
private Map<String, Object> info;
private List<Map<String, Object>> product_list;
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Map<String, Object> getInfo() {
return info;
}
public void setInfo(Map<String, Object> info) {
this.info = info;
}
public List<Map<String, Object>> getProduct_list() {
return product_list;
}
public void setProduct_list(List<Map<String, Object>> product_list) {
this.product_list = product_list;
}
}