diff --git a/src/main/java/redis/clients/jedis/search/aggr/AggregationBuilder.java b/src/main/java/redis/clients/jedis/search/aggr/AggregationBuilder.java index 4dcd8fdee4..13d6f9a270 100644 --- a/src/main/java/redis/clients/jedis/search/aggr/AggregationBuilder.java +++ b/src/main/java/redis/clients/jedis/search/aggr/AggregationBuilder.java @@ -69,16 +69,6 @@ public AggregationBuilder sortBy(SortedField... fields) { args.add(field.getField()); args.add(field.getOrder()); } - - return this; - } - - public AggregationBuilder sortBy(int max, SortedField... fields) { - sortBy(fields); - if (max > 0) { - args.add(SearchKeyword.MAX); - args.add(max); - } return this; } @@ -90,6 +80,33 @@ public AggregationBuilder sortByDesc(String field) { return sortBy(SortedField.desc(field)); } + /** + * {@link AggregationBuilder#sortBy(redis.clients.jedis.search.aggr.SortedField...)} + * (or {@link AggregationBuilder#sortByAsc(java.lang.String)} + * or {@link AggregationBuilder#sortByDesc(java.lang.String)}) + * MUST BE called JUST BEFORE this. + * @param max limit + * @return this + */ + public AggregationBuilder sortByMax(int max) { + args.add(SearchKeyword.MAX); + args.add(max); + return this; + } + + /** + * Shortcut to {@link AggregationBuilder#sortBy(redis.clients.jedis.search.aggr.SortedField...)} + * and {@link AggregationBuilder#sortByMax(int)}. + * @param max limit + * @param fields sorted fields + * @return this + */ + public AggregationBuilder sortBy(int max, SortedField... fields) { + sortBy(fields); + sortByMax(max); + return this; + } + public AggregationBuilder apply(String projection, String alias) { args.add(SearchKeyword.APPLY); args.add(projection);