Showing
2 changed files
with
0 additions
and
113 deletions
service/src/main/java/com/yoho/search/service/scene/activity/AggBrandService.java
deleted
100644 → 0
1 | -package com.yoho.search.service.scene.activity; | ||
2 | - | ||
3 | -import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder; | ||
4 | -import com.yoho.search.base.utils.ISearchConstants; | ||
5 | -import com.yoho.search.base.utils.ProductIndexEsField; | ||
6 | -import com.yoho.search.cache.CacheTimeConstants; | ||
7 | -import com.yoho.search.cache.beans.AbstractCacheComponent; | ||
8 | -import com.yoho.search.common.SearchCommonService; | ||
9 | -import com.yoho.search.core.es.model.SearchParam; | ||
10 | -import com.yoho.search.core.es.model.SearchResult; | ||
11 | -import com.yoho.search.service.helper.SearchParamHelper; | ||
12 | -import com.yoho.search.service.recall.models.common.ParamQueryFilter; | ||
13 | -import org.elasticsearch.search.aggregations.AbstractAggregationBuilder; | ||
14 | -import org.elasticsearch.search.aggregations.Aggregation; | ||
15 | -import org.elasticsearch.search.aggregations.AggregationBuilders; | ||
16 | -import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; | ||
17 | -import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; | ||
18 | -import org.springframework.beans.factory.annotation.Autowired; | ||
19 | -import org.springframework.stereotype.Component; | ||
20 | - | ||
21 | -import java.util.*; | ||
22 | - | ||
23 | -@Component | ||
24 | -public class AggBrandService extends AbstractCacheComponent<List<AggBrand>> { | ||
25 | - | ||
26 | - @Autowired | ||
27 | - private SearchCommonService searchCommonService; | ||
28 | - @Autowired | ||
29 | - private SearchParamHelper searchParamHelper; | ||
30 | - | ||
31 | - public List<AggBrand> aggBrands(ParamQueryFilter paramQueryFilter) { | ||
32 | - List<AggBrand> value; | ||
33 | - try { | ||
34 | - value = queryWithCache(paramQueryFilter, null); | ||
35 | - } catch (Exception e) { | ||
36 | - return Collections.emptyList(); | ||
37 | - } | ||
38 | - return value != null ? value : Collections.emptyList(); | ||
39 | - } | ||
40 | - | ||
41 | - private List<AggBrand> genAggBrand(Map<String, Aggregation> aggMaps) { | ||
42 | - MultiBucketsAggregation aggregation = (MultiBucketsAggregation)aggMaps.get("brandAgg"); | ||
43 | - Iterator<? extends MultiBucketsAggregation.Bucket> itSizeAgg = aggregation.getBuckets().iterator(); | ||
44 | - List<AggBrand> aggBrands = new ArrayList<>(); | ||
45 | - while (itSizeAgg.hasNext()) { | ||
46 | - AggBrand aggBrand = new AggBrand(); | ||
47 | - MultiBucketsAggregation.Bucket ltSize = itSizeAgg.next(); | ||
48 | - aggBrand.setBrandId(Integer.valueOf(ltSize.getKeyAsString())); | ||
49 | - aggBrand.setCount(Long.valueOf(ltSize.getDocCount()).intValue()); | ||
50 | - aggBrands.add(aggBrand); | ||
51 | - } | ||
52 | - return aggBrands; | ||
53 | - } | ||
54 | - | ||
55 | - @Override | ||
56 | - protected List<AggBrand> doRealQuery(ParamQueryFilter paramQueryFilter, Map<String, String> paramMap) { | ||
57 | - List<AbstractAggregationBuilder<?>> aggregationBuilders = new ArrayList<>(); | ||
58 | - TermsAggregationBuilder firstAggregationBuilder = AggregationBuilders.terms("brandAgg").field(ProductIndexEsField.brandId).size(500); | ||
59 | - aggregationBuilders.add(firstAggregationBuilder); | ||
60 | - | ||
61 | - SearchParam searchParam = searchParamHelper.buildSearchParam(paramQueryFilter); | ||
62 | - searchParam.setAggregationBuilders(aggregationBuilders); | ||
63 | - SearchResult searchResult = searchCommonService.doSearch(ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); | ||
64 | - Map<String, Aggregation> aggregationMap = searchResult.getAggMaps(); | ||
65 | - return this.genAggBrand(aggregationMap); | ||
66 | - } | ||
67 | - | ||
68 | - @Override | ||
69 | - protected int cacheTimeInMinute() { | ||
70 | - return CacheTimeConstants.CACHE_10_MINUTE; | ||
71 | - } | ||
72 | - | ||
73 | - @Override | ||
74 | - protected String cacheSceneKey() { | ||
75 | - return "BRAND_PRODUCT_LIST_NEW"; | ||
76 | - } | ||
77 | - | ||
78 | -} |
service/src/main/java/com/yoho/search/service/scene/shopbrand/AggProductResponse.java
deleted
100644 → 0
1 | -package com.yoho.search.service.scene.shopbrand; | ||
2 | - | ||
3 | -import java.util.List; | ||
4 | -import java.util.Map; | ||
5 | - | ||
6 | -public class AggProductResponse { | ||
7 | - | ||
8 | - private Integer count; | ||
9 | - private Map<String, Object> info; | ||
10 | - private List<Map<String, Object>> product_list; | ||
11 | - | ||
12 | - public Integer getCount() { | ||
13 | - return count; | ||
14 | - } | ||
15 | - | ||
16 | - public void setCount(Integer count) { | ||
17 | - this.count = count; | ||
18 | - } | ||
19 | - | ||
20 | - public Map<String, Object> getInfo() { | ||
21 | - return info; | ||
22 | - } | ||
23 | - | ||
24 | - public void setInfo(Map<String, Object> info) { | ||
25 | - this.info = info; | ||
26 | - } | ||
27 | - | ||
28 | - public List<Map<String, Object>> getProduct_list() { | ||
29 | - return product_list; | ||
30 | - } | ||
31 | - | ||
32 | - public void setProduct_list(List<Map<String, Object>> product_list) { | ||
33 | - this.product_list = product_list; | ||
34 | - } | ||
35 | -} |
-
Please register or login to post a comment