Authored by 胡古飞

fix AggProductListServiceImpl

... ... @@ -114,8 +114,12 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic
if (StringUtils.isBlank(order)) {
return null;
}
String sortField = order.split(":")[0];
SortOrder sortOrder = order.split(":")[1].equals("desc") ? SortOrder.DESC : SortOrder.ASC;
String[] orderParts = order.split(":");
if (orderParts.length != 2) {
return null;
}
String sortField = orderParts[0];
SortOrder sortOrder = "desc".equals(orderParts[1]) ? SortOrder.DESC : SortOrder.ASC;
return new SearchSort(sortField, sortOrder);
}
... ... @@ -250,9 +254,9 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic
searchParam.setAggregationBuilders(list);
// 3、先从缓存中获取,如果能取到,则直接返回
JSONObject jsonObject = searchCacheService.getJSONObjectFromCache(aggProductListSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (jsonObject != null) {
return jsonObject;
JSONObject cacheObject = searchCacheService.getJSONObjectFromCache(aggProductListSearchCache, ISearchConstants.INDEX_NAME_PRODUCT_INDEX, searchParam);
if (cacheObject != null) {
return cacheObject;
}
// 4、执行搜索,并构造返回结果
final String indexName = ISearchConstants.INDEX_NAME_PRODUCT_INDEX;
... ... @@ -266,14 +270,14 @@ public class AggProductListServiceImpl implements IAggProductListService, Applic
}
// 5、构造返回结果
List<Map<String, Object>> productList = this.getAggProductListResult(((MultiBucketsAggregation) aggMaps.get(firstAggName)), totalViewNum, aggSort, secondSearchSort);
jsonObject = new JSONObject();
jsonObject.put("total", productList == null ? 0 : productList.size());
jsonObject.put("page", 1);
jsonObject.put("page_size", totalViewNum);
jsonObject.put("page_total", 1);
jsonObject.put("product_list", productList);
searchCacheService.addJSONObjectToCache(aggProductListSearchCache, indexName, searchParam, jsonObject);
return jsonObject;
JSONObject result = new JSONObject();
result.put("total",productList.size());
result.put("page", 1);
result.put("page_size", totalViewNum);
result.put("page_total", 1);
result.put("product_list", productList);
searchCacheService.addJSONObjectToCache(aggProductListSearchCache, indexName, searchParam, result);
return result;
} catch (Exception e) {
publisher.publishEvent(new SearchEvent(EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getEventName(), EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST
.getFunctionName(), EventReportEnum.SEARCHCONTROLLER_AGG_PRODUCTLIST.getMoudleName(), "exception", IgnoreSomeException.filterSomeException(e), null));
... ...