groupBrands和groupShops去除个性化逻辑
Showing
4 changed files
with
21 additions
and
37 deletions
@@ -85,6 +85,5 @@ public class GroupBrandAggregation extends AbstractAggregation { | @@ -85,6 +85,5 @@ public class GroupBrandAggregation extends AbstractAggregation { | ||
85 | dataMap.put(brandId, tempResult); | 85 | dataMap.put(brandId, tempResult); |
86 | } | 86 | } |
87 | return dataMap; | 87 | return dataMap; |
88 | - | ||
89 | } | 88 | } |
90 | } | 89 | } |
@@ -55,8 +55,6 @@ public class GroupShopAggregation extends AbstractAggregation { | @@ -55,8 +55,6 @@ public class GroupShopAggregation extends AbstractAggregation { | ||
55 | return AggCommonHelper.getTopHitAggregation(Arrays.asList(simpleFieldAgg), this.topHitOrder, this.topHitCount); | 55 | return AggCommonHelper.getTopHitAggregation(Arrays.asList(simpleFieldAgg), this.topHitOrder, this.topHitCount); |
56 | } | 56 | } |
57 | 57 | ||
58 | - | ||
59 | - | ||
60 | @Override | 58 | @Override |
61 | public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) { | 59 | public Object getAggregationResponseMap(Map<String, Aggregation> aggMaps) { |
62 | // 获取每个品牌下对应的数量和列表 | 60 | // 获取每个品牌下对应的数量和列表 |
@@ -85,6 +83,5 @@ public class GroupShopAggregation extends AbstractAggregation { | @@ -85,6 +83,5 @@ public class GroupShopAggregation extends AbstractAggregation { | ||
85 | dataMap.put(shopId, tempResult); | 83 | dataMap.put(shopId, tempResult); |
86 | } | 84 | } |
87 | return dataMap; | 85 | return dataMap; |
88 | - | ||
89 | } | 86 | } |
90 | } | 87 | } |
@@ -12,6 +12,7 @@ import java.util.Map; | @@ -12,6 +12,7 @@ import java.util.Map; | ||
12 | import java.util.Map.Entry; | 12 | import java.util.Map.Entry; |
13 | 13 | ||
14 | import com.yoho.search.base.utils.ConvertUtils; | 14 | import com.yoho.search.base.utils.ConvertUtils; |
15 | +import com.yoho.search.common.cache.aop.SearchCacheAble; | ||
15 | import com.yoho.search.service.helper.ProductListHelper; | 16 | import com.yoho.search.service.helper.ProductListHelper; |
16 | import org.apache.commons.collections.MapUtils; | 17 | import org.apache.commons.collections.MapUtils; |
17 | import org.apache.commons.lang.StringUtils; | 18 | import org.apache.commons.lang.StringUtils; |
@@ -269,45 +270,34 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand | @@ -269,45 +270,34 @@ public class BrandServiceImpl extends AbstractCacheAbleService implements IBrand | ||
269 | } | 270 | } |
270 | 271 | ||
271 | @Override | 272 | @Override |
273 | + @SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_BRANDS", excludeParams = {"page", "order", "uid", "udid"}) | ||
272 | public SearchApiResult groupBrands(Map<String, String> paramMap) { | 274 | public SearchApiResult groupBrands(Map<String, String> paramMap) { |
273 | try { | 275 | try { |
274 | - logger.info("[func=groupBrands][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); | ||
275 | - // 1、参数检验 | ||
276 | - if (!paramMap.containsKey("brand")) { | 276 | + // 0、参数检验 |
277 | + if (!paramMap.containsKey(SearchRequestParams.PARAM_SEARCH_BRAND)) { | ||
277 | return new SearchApiResult().setCode(400).setMessage("没有 brand参数 "); | 278 | return new SearchApiResult().setCode(400).setMessage("没有 brand参数 "); |
278 | } | 279 | } |
279 | - // 2、获取聚合条件 | 280 | + // 1、获取topHitCount |
280 | int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); | 281 | int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); |
281 | - // 3、是否需要个性化 | 282 | + // 2、获取聚合的排序规则 |
282 | String topHitOrder = "heatValue:desc"; | 283 | String topHitOrder = "heatValue:desc"; |
283 | - if (topHitCount > 0 && searchCommonHelper.isNeedPersonalSearch(paramMap)) { | ||
284 | - topHitOrder = "_score:desc"; | ||
285 | - } | ||
286 | 284 | ||
287 | - // 4、构建searchParam | ||
288 | - SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false); | 285 | + // 3、构建searchParam |
286 | + SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, false); | ||
289 | IAggregation groupBrandAgg = aggregationFactoryService.getGroupBrandAggregation(topHitOrder, topHitCount); | 287 | IAggregation groupBrandAgg = aggregationFactoryService.getGroupBrandAggregation(topHitOrder, topHitCount); |
290 | searchParam.setAggregationBuilders(Arrays.asList(groupBrandAgg.getBuilder())); | 288 | searchParam.setAggregationBuilders(Arrays.asList(groupBrandAgg.getBuilder())); |
289 | + searchParam.setOffset(0); | ||
291 | searchParam.setSize(0); | 290 | searchParam.setSize(0); |
292 | - searchParam.setOffset(topHitCount * 2);// justForCache | ||
293 | 291 | ||
294 | - // 5、从缓存中获取 | ||
295 | - final String productIndexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; | ||
296 | - JSONObject groupBrandResult = searchCacheService.getJSONObjectFromCache(this.searchCache, productIndexName, searchParam); | ||
297 | - if (groupBrandResult != null) { | ||
298 | - SearchCacheMatchLogger.doSearchCacheMatchLog("/productindex/groupBrands.json", paramMap); | ||
299 | - return new SearchApiResult().setData(groupBrandResult); | ||
300 | - } | ||
301 | - // 6、从ES中获取 | ||
302 | - groupBrandResult = aggregationService.getAggNameAndResponseWithTotal(groupBrandAgg, searchParam); | 292 | + // 4、从ES中获取 |
293 | + JSONObject groupBrandResult = aggregationService.getAggNameAndResponseWithTotal(groupBrandAgg, searchParam); | ||
303 | if (groupBrandResult == null) { | 294 | if (groupBrandResult == null) { |
304 | return new SearchApiResult().setData(500).setMessage("exception"); | 295 | return new SearchApiResult().setData(500).setMessage("exception"); |
305 | } | 296 | } |
306 | - // 7、生成结果并且加入缓存 | 297 | + // 5、返回生成结果 |
307 | JSONObject realResult = new JSONObject(); | 298 | JSONObject realResult = new JSONObject(); |
308 | realResult.put("total", groupBrandResult.getOrDefault("total", 0)); | 299 | realResult.put("total", groupBrandResult.getOrDefault("total", 0)); |
309 | realResult.put("brands", groupBrandResult.getOrDefault(groupBrandAgg.aggName(), new JSONObject())); | 300 | realResult.put("brands", groupBrandResult.getOrDefault(groupBrandAgg.aggName(), new JSONObject())); |
310 | - searchCacheService.addJSONObjectToCache(this.searchCache, productIndexName, searchParam, realResult); | ||
311 | return new SearchApiResult().setData(realResult).setMessage("groupBrands new List."); | 301 | return new SearchApiResult().setData(realResult).setMessage("groupBrands new List."); |
312 | } catch (Exception e) { | 302 | } catch (Exception e) { |
313 | publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_BRANDS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_BRANDS.getFunctionName(), | 303 | publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_GROUP_BRANDS.getEventName(), EventReportEnum.SEARCHCONTROLLER_GROUP_BRANDS.getFunctionName(), |
@@ -69,29 +69,27 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl | @@ -69,29 +69,27 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl | ||
69 | } | 69 | } |
70 | 70 | ||
71 | @Override | 71 | @Override |
72 | - @SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = { "page", "order" }) | 72 | + @SearchCacheAble(cacheInMinute = 30, cacheName = "GROUP_SHOPS", excludeParams = {"page", "order", "uid", "udid"}) |
73 | public SearchApiResult group_shops(Map<String, String> paramMap) { | 73 | public SearchApiResult group_shops(Map<String, String> paramMap) { |
74 | try { | 74 | try { |
75 | // 1、获取topHitCount | 75 | // 1、获取topHitCount |
76 | int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); | 76 | int topHitCount = StringUtils.isBlank(paramMap.get("viewNum")) ? 10 : Integer.parseInt(paramMap.get("viewNum")); |
77 | // 2、获取聚合的排序规则 | 77 | // 2、获取聚合的排序规则 |
78 | String topHitOrder = "heatValue:desc"; | 78 | String topHitOrder = "heatValue:desc"; |
79 | - if (topHitCount > 0 && searchCommonHelper.isNeedPersonalSearch(paramMap)) { | ||
80 | - topHitOrder = "_score:desc"; | ||
81 | - } | ||
82 | - // 3、获取聚合条件 | ||
83 | - IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount); | ||
84 | - // 4、构建searchParam | 79 | + |
80 | + // 3、构建searchParam | ||
85 | SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false); | 81 | SearchParam searchParam = searchParamHelper.buildWithPersional(paramMap, topHitCount > 0 ? true : false); |
82 | + IAggregation groupShopAgg = aggregationFactoryService.getGroupShopAggregation(topHitOrder, topHitCount); | ||
86 | searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder())); | 83 | searchParam.setAggregationBuilders(Arrays.asList(groupShopAgg.getBuilder())); |
87 | searchParam.setOffset(0); | 84 | searchParam.setOffset(0); |
88 | searchParam.setSize(0); | 85 | searchParam.setSize(0); |
89 | - // 5、从ES中获取 | 86 | + |
87 | + // 4、从ES中获取 | ||
90 | JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam); | 88 | JSONObject aggNameAndResponse = aggregationService.getAggNameAndResponseWithTotal(groupShopAgg, searchParam); |
91 | if (aggNameAndResponse == null) { | 89 | if (aggNameAndResponse == null) { |
92 | return new SearchApiResult().setData(500).setMessage("exception"); | 90 | return new SearchApiResult().setData(500).setMessage("exception"); |
93 | } | 91 | } |
94 | - // 6、返回生成结果 | 92 | + // 5、返回生成结果 |
95 | JSONObject realResult = new JSONObject(); | 93 | JSONObject realResult = new JSONObject(); |
96 | realResult.put("total", aggNameAndResponse.getOrDefault("total", 0)); | 94 | realResult.put("total", aggNameAndResponse.getOrDefault("total", 0)); |
97 | realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject())); | 95 | realResult.put("shops", aggNameAndResponse.getOrDefault(groupShopAgg.aggName(), new JSONObject())); |
@@ -104,7 +102,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl | @@ -104,7 +102,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl | ||
104 | } | 102 | } |
105 | 103 | ||
106 | @Override | 104 | @Override |
107 | - @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = { "keyword", "is_encode"}) | 105 | + @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_YOHO_BRAND", includeParams = {"keyword", "is_encode"}) |
108 | public SearchApiResult searchYohoBrand(Map<String, String> paramMap) { | 106 | public SearchApiResult searchYohoBrand(Map<String, String> paramMap) { |
109 | try { | 107 | try { |
110 | // 1、参数校验 | 108 | // 1、参数校验 |
@@ -158,7 +156,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl | @@ -158,7 +156,7 @@ public class ShopsServiceImpl extends BaseService implements IShopsService, Appl | ||
158 | } | 156 | } |
159 | 157 | ||
160 | @Override | 158 | @Override |
161 | - @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = { "keyword", "is_encode"}) | 159 | + @SearchCacheAble(cacheInMinute = 30, cacheName = "SEARCH_SHOP_NEW", includeParams = {"keyword", "is_encode"}) |
162 | public SearchApiResult searchShopsNew(Map<String, String> paramMap) { | 160 | public SearchApiResult searchShopsNew(Map<String, String> paramMap) { |
163 | try { | 161 | try { |
164 | logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); | 162 | logger.info("[func=searchShops][param={}][begin={}]", paramMap.toString(), System.currentTimeMillis()); |
-
Please register or login to post a comment