fix AggProductListServiceImpl
Showing
1 changed file
with
17 additions
and
13 deletions
@@ -114,8 +114,12 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic | @@ -114,8 +114,12 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic | ||
114 | if (StringUtils.isBlank(order)) { | 114 | if (StringUtils.isBlank(order)) { |
115 | return null; | 115 | return null; |
116 | } | 116 | } |
117 | - String sortField = order.split(":")[0]; | ||
118 | - SortOrder sortOrder = order.split(":")[1].equals("desc") ? SortOrder.DESC : SortOrder.ASC; | 117 | + String[] orderParts = order.split(":"); |
118 | + if (orderParts.length != 2) { | ||
119 | + return null; | ||
120 | + } | ||
121 | + String sortField = orderParts[0]; | ||
122 | + SortOrder sortOrder = "desc".equals(orderParts[1]) ? SortOrder.DESC : SortOrder.ASC; | ||
119 | return new SearchSort(sortField, sortOrder); | 123 | return new SearchSort(sortField, sortOrder); |
120 | } | 124 | } |
121 | 125 | ||
@@ -250,9 +254,9 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic | @@ -250,9 +254,9 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic | ||
250 | searchParam.setAggregationBuilders(list); | 254 | searchParam.setAggregationBuilders(list); |
251 | 255 | ||
252 | // 3、先从缓存中获取,如果能取到,则直接返回 | 256 | // 3、先从缓存中获取,如果能取到,则直接返回 |
253 | - JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(aggProductListSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); | ||
254 | - if (jsonObject != null) { | ||
255 | - return jsonObject; | 257 | + JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(aggProductListSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam); |
258 | + if (cacheObject != null) { | ||
259 | + return cacheObject; | ||
256 | } | 260 | } |
257 | // 4、执行搜索,并构造返回结果 | 261 | // 4、执行搜索,并构造返回结果 |
258 | final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; | 262 | final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX; |
@@ -266,14 +270,14 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic | @@ -266,14 +270,14 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic | ||
266 | } | 270 | } |
267 | // 5、构造返回结果 | 271 | // 5、构造返回结果 |
268 | List<Map<String, Object>> productList = this.getAggProductListResult(((MultiBucketsAggregation) aggMaps.get(firstAggName)), totalViewNum, aggSort, secondSearchSort); | 272 | List<Map<String, Object>> productList = this.getAggProductListResult(((MultiBucketsAggregation) aggMaps.get(firstAggName)), totalViewNum, aggSort, secondSearchSort); |
269 | - jsonObject = new JSONObject(); | ||
270 | - jsonObject.put("total", productList == null ? 0 : productList.size()); | ||
271 | - jsonObject.put("page", 1); | ||
272 | - jsonObject.put("page_size", totalViewNum); | ||
273 | - jsonObject.put("page_total", 1); | ||
274 | - jsonObject.put("product_list", productList); | ||
275 | - searchCacheService.addJSONObjectToCache(aggProductListSearchCache, indexName, searchParam, jsonObject); | ||
276 | - return jsonObject; | 273 | + JSONObject result = new JSONObject(); |
274 | + result.put("total",productList.size()); | ||
275 | + result.put("page", 1); | ||
276 | + result.put("page_size", totalViewNum); | ||
277 | + result.put("page_total", 1); | ||
278 | + result.put("product_list", productList); | ||
279 | + searchCacheService.addJSONObjectToCache(aggProductListSearchCache, indexName, searchParam, result); | ||
280 | + return result; | ||
277 | } catch (Exception e) { | 281 | } catch (Exception e) { |
278 | publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getEventName(), EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST | 282 | publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getEventName(), EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST |
279 | .getFunctionName(), EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null)); | 283 | .getFunctionName(), EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null)); |
-
Please register or login to post a comment