Showing
5 changed files
with
44 additions
and
189 deletions
@@ -31,6 +31,28 @@ public class AggCommonHelper { | @@ -31,6 +31,28 @@ public class AggCommonHelper { | ||
31 | 31 | ||
32 | private static final Logger logger = LoggerFactory.getLogger(AggCommonHelper.class); | 32 | private static final Logger logger = LoggerFactory.getLogger(AggCommonHelper.class); |
33 | 33 | ||
34 | + /** | ||
35 | + * 从TopHits中获取_source | ||
36 | + * | ||
37 | + * @param topHits | ||
38 | + * @return | ||
39 | + */ | ||
40 | + public static List<Map<String, Object>> getTopHitResultsWithScore(TopHits topHits) { | ||
41 | + List<Map<String, Object>> topHitList = new ArrayList<>(); | ||
42 | + if (topHits == null) { | ||
43 | + return topHitList; | ||
44 | + } | ||
45 | + SearchHits hits = topHits.getHits(); | ||
46 | + for (SearchHit hit : hits.getHits()) { | ||
47 | + Map<String, Object> source = hit.getSource(); | ||
48 | + float _score = hit.getScore(); | ||
49 | + source.put("_score", _score); | ||
50 | + topHitList.add(source); | ||
51 | + } | ||
52 | + return topHitList; | ||
53 | + } | ||
54 | + | ||
55 | + | ||
34 | public static List<Integer> getIdsFromAggMaps(Map<String, Aggregation> aggMaps, String aggName) { | 56 | public static List<Integer> getIdsFromAggMaps(Map<String, Aggregation> aggMaps, String aggName) { |
35 | if (!aggMaps.containsKey(aggName)) { | 57 | if (!aggMaps.containsKey(aggName)) { |
36 | return new ArrayList<>(); | 58 | return new ArrayList<>(); |
@@ -53,7 +75,7 @@ public class AggCommonHelper { | @@ -53,7 +75,7 @@ public class AggCommonHelper { | ||
53 | * | 75 | * |
54 | * @param simpleFieldAggs | 76 | * @param simpleFieldAggs |
55 | * @param topHitOrder | 77 | * @param topHitOrder |
56 | - * @param topHitFieldCount | 78 | + * @param topHitCount |
57 | * @return | 79 | * @return |
58 | */ | 80 | */ |
59 | public static AbstractAggregationBuilder<?> getTopHitAggregation(List<SimpleFieldAgg> simpleFieldAggs, String topHitOrder, int topHitCount) { | 81 | public static AbstractAggregationBuilder<?> getTopHitAggregation(List<SimpleFieldAgg> simpleFieldAggs, String topHitOrder, int topHitCount) { |
@@ -85,12 +107,6 @@ public class AggCommonHelper { | @@ -85,12 +107,6 @@ public class AggCommonHelper { | ||
85 | 107 | ||
86 | /** | 108 | /** |
87 | * 获取聚合出来的商品列表,并按特定顺序截取 | 109 | * 获取聚合出来的商品列表,并按特定顺序截取 |
88 | - * | ||
89 | - * @param aggregation | ||
90 | - * @param viewNum | ||
91 | - * @param sortField | ||
92 | - * @param sortOrder | ||
93 | - * @return | ||
94 | */ | 110 | */ |
95 | public static List<Map<String, Object>> getTopHitList(Map<String, Aggregation> aggMaps, List<SimpleFieldAgg> simpleFieldAggs, String topHitOrder, int totalCount) { | 111 | public static List<Map<String, Object>> getTopHitList(Map<String, Aggregation> aggMaps, List<SimpleFieldAgg> simpleFieldAggs, String topHitOrder, int totalCount) { |
96 | List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); | 112 | List<Map<String, Object>> results = new ArrayList<Map<String, Object>>(); |
@@ -99,6 +115,7 @@ public class AggCommonHelper { | @@ -99,6 +115,7 @@ public class AggCommonHelper { | ||
99 | return results; | 115 | return results; |
100 | } | 116 | } |
101 | 117 | ||
118 | + | ||
102 | private static void getTopHitResults(List<Map<String, Object>> results, Map<String, Aggregation> aggMaps, List<SimpleFieldAgg> simpleFieldAggs, int index) { | 119 | private static void getTopHitResults(List<Map<String, Object>> results, Map<String, Aggregation> aggMaps, List<SimpleFieldAgg> simpleFieldAggs, int index) { |
103 | try { | 120 | try { |
104 | String aggName = simpleFieldAggs.get(index++).getAggName(); | 121 | String aggName = simpleFieldAggs.get(index++).getAggName(); |
@@ -113,15 +130,8 @@ public class AggCommonHelper { | @@ -113,15 +130,8 @@ public class AggCommonHelper { | ||
113 | Map<String, Aggregation> aggMap = bucket.getAggregations().getAsMap(); | 130 | Map<String, Aggregation> aggMap = bucket.getAggregations().getAsMap(); |
114 | if (aggMap.containsKey("topHit")) { | 131 | if (aggMap.containsKey("topHit")) { |
115 | TopHits topHits = bucket.getAggregations().get("topHit"); | 132 | TopHits topHits = bucket.getAggregations().get("topHit"); |
116 | - if (topHits != null) { | ||
117 | - SearchHits hits = topHits.getHits(); | ||
118 | - for (SearchHit hit : hits.getHits()) { | ||
119 | - Map<String, Object> source = hit.getSource(); | ||
120 | - float _score = hit.getScore(); | ||
121 | - source.put("_score", _score); | ||
122 | - results.add(source); | ||
123 | - } | ||
124 | - } | 133 | + List<Map<String, Object>> topHitList = getTopHitResultsWithScore(topHits); |
134 | + results.addAll(topHitList); | ||
125 | } else { | 135 | } else { |
126 | getTopHitResults(results, aggMap, simpleFieldAggs, index); | 136 | getTopHitResults(results, aggMap, simpleFieldAggs, index); |
127 | } | 137 | } |
@@ -133,7 +143,7 @@ public class AggCommonHelper { | @@ -133,7 +143,7 @@ public class AggCommonHelper { | ||
133 | 143 | ||
134 | private static List<Map<String, Object>> sortListBySortField(List<Map<String, Object>> productList, String topHitOrder, int viewNum) { | 144 | private static List<Map<String, Object>> sortListBySortField(List<Map<String, Object>> productList, String topHitOrder, int viewNum) { |
135 | if (productList == null || productList.isEmpty()) { | 145 | if (productList == null || productList.isEmpty()) { |
136 | - return new ArrayList<Map<String, Object>>(); | 146 | + return new ArrayList<>(); |
137 | } | 147 | } |
138 | // 再按照某个字段对商品排序 | 148 | // 再按照某个字段对商品排序 |
139 | FieldSortOrder fieldSortOrder = new FieldSortOrder(topHitOrder); | 149 | FieldSortOrder fieldSortOrder = new FieldSortOrder(topHitOrder); |
@@ -173,38 +183,27 @@ public class AggCommonHelper { | @@ -173,38 +183,27 @@ public class AggCommonHelper { | ||
173 | /** | 183 | /** |
174 | * 按聚合的key获取聚合出来的商品列表[目前只支持一个field,多重field的话,key不好处理] | 184 | * 按聚合的key获取聚合出来的商品列表[目前只支持一个field,多重field的话,key不好处理] |
175 | * | 185 | * |
176 | - * @param aggregation | ||
177 | - * @param viewNum | ||
178 | - * @param sortField | ||
179 | - * @param sortOrder | ||
180 | * @return | 186 | * @return |
181 | */ | 187 | */ |
182 | public static List<KeyTopHitModel> getTopHitListGroupByKey(Map<String, Aggregation> aggMaps, SimpleFieldAgg simpleFieldAgg) { | 188 | public static List<KeyTopHitModel> getTopHitListGroupByKey(Map<String, Aggregation> aggMaps, SimpleFieldAgg simpleFieldAgg) { |
183 | String aggName = simpleFieldAgg.getAggName(); | 189 | String aggName = simpleFieldAgg.getAggName(); |
184 | if (!aggMaps.containsKey(aggName)) { | 190 | if (!aggMaps.containsKey(aggName)) { |
185 | - return new ArrayList<KeyTopHitModel>(); | 191 | + return new ArrayList<>(); |
186 | } | 192 | } |
187 | List<? extends Bucket> bucketList = ((MultiBucketsAggregation) aggMaps.get(aggName)).getBuckets(); | 193 | List<? extends Bucket> bucketList = ((MultiBucketsAggregation) aggMaps.get(aggName)).getBuckets(); |
188 | if (bucketList.isEmpty()) { | 194 | if (bucketList.isEmpty()) { |
189 | - return new ArrayList<KeyTopHitModel>(); | 195 | + return new ArrayList<>(); |
190 | } | 196 | } |
191 | List<KeyTopHitModel> results = new ArrayList<KeyTopHitModel>(); | 197 | List<KeyTopHitModel> results = new ArrayList<KeyTopHitModel>(); |
192 | for (Bucket bucket : bucketList) { | 198 | for (Bucket bucket : bucketList) { |
193 | String key = bucket.getKeyAsString(); | 199 | String key = bucket.getKeyAsString(); |
194 | long count = bucket.getDocCount(); | 200 | long count = bucket.getDocCount(); |
195 | - List<Map<String, Object>> topHitList = new ArrayList<Map<String, Object>>(); | 201 | + List<Map<String, Object>> topHitList = new ArrayList<>(); |
196 | Map<String, Aggregation> aggMap = bucket.getAggregations().getAsMap(); | 202 | Map<String, Aggregation> aggMap = bucket.getAggregations().getAsMap(); |
197 | if (aggMap.containsKey("topHit")) { | 203 | if (aggMap.containsKey("topHit")) { |
198 | TopHits topHits = bucket.getAggregations().get("topHit"); | 204 | TopHits topHits = bucket.getAggregations().get("topHit"); |
199 | - if (topHits != null) { | ||
200 | - SearchHits hits = topHits.getHits(); | ||
201 | - for (SearchHit hit : hits.getHits()) { | ||
202 | - Map<String, Object> source = hit.getSource(); | ||
203 | - float _score = hit.getScore(); | ||
204 | - source.put("_score", _score); | ||
205 | - topHitList.add(source); | ||
206 | - } | ||
207 | - } | 205 | + List<Map<String, Object>> tempTopHitList = getTopHitResultsWithScore(topHits); |
206 | + topHitList.addAll(tempTopHitList); | ||
208 | } | 207 | } |
209 | KeyTopHitModel keyTopHitModel = new KeyTopHitModel(key, count, topHitList); | 208 | KeyTopHitModel keyTopHitModel = new KeyTopHitModel(key, count, topHitList); |
210 | results.add(keyTopHitModel); | 209 | results.add(keyTopHitModel); |
1 | -package com.yoho.search.service.helper; | ||
2 | - | ||
3 | -import java.util.ArrayList; | ||
4 | -import java.util.Collections; | ||
5 | -import java.util.Comparator; | ||
6 | -import java.util.Iterator; | ||
7 | -import java.util.List; | ||
8 | -import java.util.Map; | ||
9 | - | ||
10 | -import org.elasticsearch.search.SearchHit; | ||
11 | -import org.elasticsearch.search.SearchHits; | ||
12 | -import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; | ||
13 | -import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket; | ||
14 | -import org.elasticsearch.search.aggregations.metrics.tophits.TopHits; | ||
15 | -import org.elasticsearch.search.sort.SortOrder; | ||
16 | -import org.springframework.beans.factory.annotation.Autowired; | ||
17 | -import org.springframework.stereotype.Component; | ||
18 | - | ||
19 | -import com.yoho.search.base.utils.CollectionUtils; | ||
20 | -import com.yoho.search.service.base.index.ProductIndexBaseService; | ||
21 | - | ||
22 | -@Component | ||
23 | -public class AggProductListHelper { | ||
24 | - | ||
25 | - @Autowired | ||
26 | - private ProductIndexBaseService productIndexBaseService; | ||
27 | - | ||
28 | - /** | ||
29 | - * 获取聚合出来的商品列表 | ||
30 | - * | ||
31 | - * @param aggregation | ||
32 | - * @return | ||
33 | - */ | ||
34 | - public List<Map<String, Object>> getProductListFromAggregation(final MultiBucketsAggregation aggregation) { | ||
35 | - Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator(); | ||
36 | - List<Map<String, Object>> productEsSourceList = new ArrayList<Map<String, Object>>(); | ||
37 | - while (itAgg.hasNext()) { | ||
38 | - Bucket lt = itAgg.next(); | ||
39 | - if (lt.getAggregations().getAsMap().containsKey("product")) { | ||
40 | - TopHits topHits = lt.getAggregations().get("product"); | ||
41 | - if (topHits != null) { | ||
42 | - SearchHits hits = topHits.getHits(); | ||
43 | - for (SearchHit hit : hits.getHits()) { | ||
44 | - productEsSourceList.add(hit.getSource()); | ||
45 | - } | ||
46 | - } | ||
47 | - } | ||
48 | - } | ||
49 | - if (productEsSourceList == null || productEsSourceList.isEmpty()) { | ||
50 | - return new ArrayList<Map<String, Object>>(); | ||
51 | - } | ||
52 | - return productIndexBaseService.getProductListWithPricePlan(productEsSourceList); | ||
53 | - } | ||
54 | - | ||
55 | - /** | ||
56 | - * 获取聚合出来的商品列表,并按特定顺序截取 | ||
57 | - * | ||
58 | - * @param aggregation | ||
59 | - * @param viewNum | ||
60 | - * @param sortField | ||
61 | - * @param sortOrder | ||
62 | - * @return | ||
63 | - */ | ||
64 | - public List<Map<String, Object>> getProductListFromAggregation(final MultiBucketsAggregation aggregation, int viewNum, String sortField, SortOrder sortOrder) { | ||
65 | - Iterator<? extends Bucket> itAgg = aggregation.getBuckets().iterator(); | ||
66 | - // 获取品牌聚合出来的商品 | ||
67 | - List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>(); | ||
68 | - while (itAgg.hasNext()) { | ||
69 | - Bucket lt = itAgg.next(); | ||
70 | - if (lt.getAggregations().getAsMap().containsKey("product")) { | ||
71 | - TopHits topHits = lt.getAggregations().get("product"); | ||
72 | - if (topHits == null) { | ||
73 | - continue; | ||
74 | - } | ||
75 | - SearchHits hits = topHits.getHits(); | ||
76 | - for (SearchHit hit : hits.getHits()) { | ||
77 | - Map<String, Object> source = hit.getSource(); | ||
78 | - float _score = hit.getScore(); | ||
79 | - source.put("_score", _score); | ||
80 | - dataList.add(source); | ||
81 | - } | ||
82 | - } | ||
83 | - } | ||
84 | - dataList = this.sortListBySortField(dataList, viewNum, sortField, sortOrder); | ||
85 | - return productIndexBaseService.getProductListWithPricePlan(dataList); | ||
86 | - } | ||
87 | - | ||
88 | - private List<Map<String, Object>> sortListBySortField(List<Map<String, Object>> productList, int viewNum, String orderField, SortOrder sortOrder) { | ||
89 | - if (productList == null || productList.isEmpty()) { | ||
90 | - return new ArrayList<Map<String, Object>>(); | ||
91 | - } | ||
92 | - // 再按照某个字段对商品排序 | ||
93 | - boolean isDesc = sortOrder == SortOrder.DESC ? true : false; | ||
94 | - Collections.sort(productList, new Comparator<Map<String, Object>>() { | ||
95 | - public int compare(Map<String, Object> o1, Map<String, Object> o2) { | ||
96 | - double value1 = getDouble(o1.get(orderField)); | ||
97 | - double value2 = getDouble(o2.get(orderField)); | ||
98 | - if (isDesc) { | ||
99 | - return value1 > value2 ? -1 : value1 < value2 ? 1 : 0; | ||
100 | - } else { | ||
101 | - return value1 > value2 ? 1 : value1 < value2 ? -1 : 0; | ||
102 | - } | ||
103 | - } | ||
104 | - }); | ||
105 | - if (productList.size() > viewNum) { | ||
106 | - productList = CollectionUtils.safeSubList(productList, 0, viewNum); | ||
107 | - } | ||
108 | - return productList; | ||
109 | - } | ||
110 | - | ||
111 | - private double getDouble(Object value) { | ||
112 | - try { | ||
113 | - return Double.parseDouble(value.toString()); | ||
114 | - } catch (Exception e) { | ||
115 | - return 0; | ||
116 | - } | ||
117 | - } | ||
118 | -} |
@@ -14,6 +14,7 @@ import com.yoho.search.models.SearchApiResult; | @@ -14,6 +14,7 @@ import com.yoho.search.models.SearchApiResult; | ||
14 | import com.yoho.search.models.SearchSort; | 14 | import com.yoho.search.models.SearchSort; |
15 | import com.yoho.search.service.base.SearchCommonService; | 15 | import com.yoho.search.service.base.SearchCommonService; |
16 | import com.yoho.search.service.base.index.ProductIndexBaseService; | 16 | import com.yoho.search.service.base.index.ProductIndexBaseService; |
17 | +import com.yoho.search.service.helper.AggCommonHelper; | ||
17 | import com.yoho.search.service.helper.SearchCommonHelper; | 18 | import com.yoho.search.service.helper.SearchCommonHelper; |
18 | import com.yoho.search.service.helper.SearchParamHelper; | 19 | import com.yoho.search.service.helper.SearchParamHelper; |
19 | import com.yoho.search.service.helper.SearchSortHelper; | 20 | import com.yoho.search.service.helper.SearchSortHelper; |
@@ -207,7 +208,7 @@ public class AggProductListService implements ApplicationEventPublisherAware { | @@ -207,7 +208,7 @@ public class AggProductListService implements ApplicationEventPublisherAware { | ||
207 | * 【父聚合的字段名称】 | 208 | * 【父聚合的字段名称】 |
208 | * @param firstAggBucketCount | 209 | * @param firstAggBucketCount |
209 | * 【父聚合的桶大小】 | 210 | * 【父聚合的桶大小】 |
210 | - * @param aggOrderSearchSort | 211 | + * @param aggSort |
211 | * 【聚合排序规则,即按什么排序推荐】 | 212 | * 【聚合排序规则,即按什么排序推荐】 |
212 | * @param secondSearchSort | 213 | * @param secondSearchSort |
213 | * 【次要排序条件,即最终商品按什么排序】 | 214 | * 【次要排序条件,即最终商品按什么排序】 |
@@ -291,15 +292,7 @@ public class AggProductListService implements ApplicationEventPublisherAware { | @@ -291,15 +292,7 @@ public class AggProductListService implements ApplicationEventPublisherAware { | ||
291 | Bucket lt = itAgg.next(); | 292 | Bucket lt = itAgg.next(); |
292 | if (lt.getAggregations().getAsMap().containsKey("product")) { | 293 | if (lt.getAggregations().getAsMap().containsKey("product")) { |
293 | TopHits topHits = lt.getAggregations().get("product"); | 294 | TopHits topHits = lt.getAggregations().get("product"); |
294 | - if (topHits != null) { | ||
295 | - SearchHits hits = topHits.getHits(); | ||
296 | - for (SearchHit hit : hits.getHits()) { | ||
297 | - Map<String, Object> source = hit.getSource(); | ||
298 | - float _score = hit.getScore(); | ||
299 | - source.put("_score", _score); | ||
300 | - productList.add(source); | ||
301 | - } | ||
302 | - } | 295 | + productList.addAll(AggCommonHelper.getTopHitResultsWithScore(topHits)); |
303 | } | 296 | } |
304 | } | 297 | } |
305 | return productList; | 298 | return productList; |
@@ -15,6 +15,7 @@ import com.yoho.search.service.base.SearchCommonService; | @@ -15,6 +15,7 @@ import com.yoho.search.service.base.SearchCommonService; | ||
15 | import com.yoho.search.service.base.SearchRequestParams; | 15 | import com.yoho.search.service.base.SearchRequestParams; |
16 | import com.yoho.search.service.base.index.BrandIndexBaseService; | 16 | import com.yoho.search.service.base.index.BrandIndexBaseService; |
17 | import com.yoho.search.service.base.index.ShopsIndexBaseService; | 17 | import com.yoho.search.service.base.index.ShopsIndexBaseService; |
18 | +import com.yoho.search.service.helper.AggCommonHelper; | ||
18 | import com.yoho.search.service.helper.SearchCommonHelper; | 19 | import com.yoho.search.service.helper.SearchCommonHelper; |
19 | import com.yoho.search.service.service.IShopListService; | 20 | import com.yoho.search.service.service.IShopListService; |
20 | import org.apache.commons.lang.StringUtils; | 21 | import org.apache.commons.lang.StringUtils; |
@@ -151,20 +152,13 @@ public class ShopListServiceImpl implements IShopListService { | @@ -151,20 +152,13 @@ public class ShopListServiceImpl implements IShopListService { | ||
151 | Bucket lt = itAgg.next(); | 152 | Bucket lt = itAgg.next(); |
152 | if (lt.getAggregations().getAsMap().containsKey("product")) { | 153 | if (lt.getAggregations().getAsMap().containsKey("product")) { |
153 | TopHits topHits = lt.getAggregations().get("product"); | 154 | TopHits topHits = lt.getAggregations().get("product"); |
154 | - if (topHits != null) { | ||
155 | - SearchHits hits = topHits.getHits(); | ||
156 | - for (SearchHit hit : hits.getHits()) { | ||
157 | - Map<String, Object> source = hit.getSource(); | ||
158 | - float _score = hit.getScore(); | ||
159 | - source.put("_score", _score); | ||
160 | - productSourceList.add(source); | ||
161 | - } | ||
162 | - } | 155 | + productSourceList.addAll(AggCommonHelper.getTopHitResultsWithScore(topHits)); |
163 | } | 156 | } |
164 | } | 157 | } |
165 | if (productSourceList == null || productSourceList.isEmpty()) { | 158 | if (productSourceList == null || productSourceList.isEmpty()) { |
166 | return new ArrayList<Map<String, Object>>(); | 159 | return new ArrayList<Map<String, Object>>(); |
167 | } | 160 | } |
161 | + | ||
168 | List<Integer> yohoShopIds = new ArrayList<Integer>(); | 162 | List<Integer> yohoShopIds = new ArrayList<Integer>(); |
169 | List<Integer> globalBrandIds = new ArrayList<Integer>(); | 163 | List<Integer> globalBrandIds = new ArrayList<Integer>(); |
170 | 164 |
@@ -6,8 +6,10 @@ import com.yoho.search.base.utils.CollectionUtils; | @@ -6,8 +6,10 @@ import com.yoho.search.base.utils.CollectionUtils; | ||
6 | import com.yoho.search.base.utils.EventReportEnum; | 6 | import com.yoho.search.base.utils.EventReportEnum; |
7 | import com.yoho.search.base.utils.ISearchConstants; | 7 | import com.yoho.search.base.utils.ISearchConstants; |
8 | import com.yoho.search.base.utils.ProductIndexEsField; | 8 | import com.yoho.search.base.utils.ProductIndexEsField; |
9 | +import com.yoho.search.common.cache.CacheType; | ||
9 | import com.yoho.search.common.cache.SearchCacheFactory; | 10 | import com.yoho.search.common.cache.SearchCacheFactory; |
10 | import com.yoho.search.common.cache.SearchCacheMatchLogger; | 11 | import com.yoho.search.common.cache.SearchCacheMatchLogger; |
12 | +import com.yoho.search.common.cache.aop.SearchCacheAble; | ||
11 | import com.yoho.search.common.cache.model.SearchCache; | 13 | import com.yoho.search.common.cache.model.SearchCache; |
12 | import com.yoho.search.common.utils.SearchApiResultUtils; | 14 | import com.yoho.search.common.utils.SearchApiResultUtils; |
13 | import com.yoho.search.core.es.model.SearchParam; | 15 | import com.yoho.search.core.es.model.SearchParam; |
@@ -62,17 +64,12 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | @@ -62,17 +64,12 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | ||
62 | @Autowired | 64 | @Autowired |
63 | private SearchServiceHelper searchServiceHelper; | 65 | private SearchServiceHelper searchServiceHelper; |
64 | @Autowired | 66 | @Autowired |
65 | - private SearchCacheService searchCacheService; | ||
66 | - @Autowired | ||
67 | - private SearchCacheFactory searchCacheFactory; | ||
68 | - @Autowired | ||
69 | private SearchCommonService searchCommonService; | 67 | private SearchCommonService searchCommonService; |
70 | @Autowired | 68 | @Autowired |
71 | private WebProductIndexBaseService webProductIndexBaseService; | 69 | private WebProductIndexBaseService webProductIndexBaseService; |
72 | @Autowired | 70 | @Autowired |
73 | private ProductListSortService productListSortService; | 71 | private ProductListSortService productListSortService; |
74 | 72 | ||
75 | - private SearchCache searchCache; | ||
76 | private ApplicationEventPublisher publisher; | 73 | private ApplicationEventPublisher publisher; |
77 | 74 | ||
78 | @Override | 75 | @Override |
@@ -80,12 +77,8 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | @@ -80,12 +77,8 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | ||
80 | this.publisher = applicationEventPublisher; | 77 | this.publisher = applicationEventPublisher; |
81 | } | 78 | } |
82 | 79 | ||
83 | - @PostConstruct | ||
84 | - void init() { | ||
85 | - searchCache = searchCacheFactory.getBrandRelatedCache(); | ||
86 | - } | ||
87 | - | ||
88 | @Override | 80 | @Override |
81 | + @SearchCacheAble(cacheName = "WEB_NEW_SHELVE",cacheInMinute = 30,cacheType = CacheType.SEARCH_REDIS,excludeParams={ "uid","udid"}) | ||
89 | public SearchApiResult webNewShelveProductList(Map<String, String> paramMap) { | 82 | public SearchApiResult webNewShelveProductList(Map<String, String> paramMap) { |
90 | try { | 83 | try { |
91 | logger.info("[func=aggProductsByBrandId][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); | 84 | logger.info("[func=aggProductsByBrandId][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); |
@@ -130,14 +123,7 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | @@ -130,14 +123,7 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | ||
130 | // 5、构造返回结果 | 123 | // 5、构造返回结果 |
131 | SearchApiResult searchApiResult = new SearchApiResult().setMessage("new-shelve list"); | 124 | SearchApiResult searchApiResult = new SearchApiResult().setMessage("new-shelve list"); |
132 | 125 | ||
133 | - // 6、先从缓存中获取,如果能取到,则直接返回 | ||
134 | - JSONArray jsonArray = searchCacheService.getJSONArrayFromCache(this.searchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); | ||
135 | - if (jsonArray != null) { | ||
136 | - SearchCacheMatchLogger.doSearchCacheMatchLog("/new-shelve.json", paramMap); | ||
137 | - return searchApiResult.setData(jsonArray); | ||
138 | - } | ||
139 | - | ||
140 | - // 7、执行搜索,并构造返回结果 | 126 | + // 6、执行搜索,并构造返回结果 |
141 | final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; | 127 | final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; |
142 | SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam); | 128 | SearchResult searchResult = searchCommonService.doSearch(indexName, searchParam); |
143 | if (searchResult == null || searchResult.getAggMaps() == null) { | 129 | if (searchResult == null || searchResult.getAggMaps() == null) { |
@@ -148,7 +134,6 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | @@ -148,7 +134,6 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | ||
148 | return searchApiResult.setData(""); | 134 | return searchApiResult.setData(""); |
149 | } | 135 | } |
150 | JSONArray productList = this.getNewShelveResponseMap(((MultiBucketsAggregation) aggMaps.get("brandAgg"))); | 136 | JSONArray productList = this.getNewShelveResponseMap(((MultiBucketsAggregation) aggMaps.get("brandAgg"))); |
151 | - searchCacheService.addJSONArrayToCache(this.searchCache, indexName, searchParam, productList); | ||
152 | return searchApiResult.setData(productList); | 137 | return searchApiResult.setData(productList); |
153 | } catch (Exception e) { | 138 | } catch (Exception e) { |
154 | publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_NEW_SHELVE.getEventName(), EventReportEnum.SEARCHCONTROLLER_NEW_SHELVE.getFunctionName(), | 139 | publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_NEW_SHELVE.getEventName(), EventReportEnum.SEARCHCONTROLLER_NEW_SHELVE.getFunctionName(), |
@@ -177,6 +162,7 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | @@ -177,6 +162,7 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | ||
177 | return this.transforToJSONArray(productListWithPricePlan); | 162 | return this.transforToJSONArray(productListWithPricePlan); |
178 | } | 163 | } |
179 | 164 | ||
165 | + | ||
180 | private JSONArray transforToJSONArray(List<Map<String, Object>> productListWithPricePlan) { | 166 | private JSONArray transforToJSONArray(List<Map<String, Object>> productListWithPricePlan) { |
181 | JSONArray results = new JSONArray(); | 167 | JSONArray results = new JSONArray(); |
182 | for (Map<String, Object> productWithPricePlan : productListWithPricePlan) { | 168 | for (Map<String, Object> productWithPricePlan : productListWithPricePlan) { |
@@ -186,6 +172,7 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | @@ -186,6 +172,7 @@ public class WebNewShelveServiceImpl implements IWebNewShelveService, Applicatio | ||
186 | } | 172 | } |
187 | 173 | ||
188 | @Override | 174 | @Override |
175 | + @SearchCacheAble(cacheName = "WEB_BATCH_NEW_SHELVE",cacheInMinute = 30,cacheType = CacheType.SEARCH_REDIS,excludeParams={ "uid","udid"}) | ||
189 | public SearchApiResult webNewShelveBatchProductList(Map<String, String> paramMap) { | 176 | public SearchApiResult webNewShelveBatchProductList(Map<String, String> paramMap) { |
190 | try { | 177 | try { |
191 | logger.info("[func=webNewShelvesProductList][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); | 178 | logger.info("[func=webNewShelvesProductList][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); |
-
Please register or login to post a comment