From 196fc9b21ac460f0d5251d349e4249e2ffedb9ff Mon Sep 17 00:00:00 2001 From: Nedyalko Dyakov Date: Fri, 14 Feb 2025 13:07:39 +0200 Subject: [PATCH] use limit when limitoffset is zero (#3275) --- search_commands.go | 14 ++++---------- search_test.go | 5 +++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/search_commands.go b/search_commands.go index df12bb3f..878f874e 100644 --- a/search_commands.go +++ b/search_commands.go @@ -574,11 +574,8 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery if options.SortByMax > 0 { queryArgs = append(queryArgs, "MAX", options.SortByMax) } - if options.LimitOffset > 0 { - queryArgs = append(queryArgs, "LIMIT", options.LimitOffset) - } - if options.Limit > 0 { - queryArgs = append(queryArgs, options.Limit) + if options.LimitOffset >= 0 && options.Limit > 0 { + queryArgs = append(queryArgs, "LIMIT", options.LimitOffset, options.Limit) } if options.Filter != "" { queryArgs = append(queryArgs, "FILTER", options.Filter) @@ -773,11 +770,8 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st if options.SortByMax > 0 { args = append(args, "MAX", options.SortByMax) } - if options.LimitOffset > 0 { - args = append(args, "LIMIT", options.LimitOffset) - } - if options.Limit > 0 { - args = append(args, options.Limit) + if options.LimitOffset >= 0 && options.Limit > 0 { + args = append(args, "LIMIT", options.LimitOffset, options.Limit) } if options.Filter != "" { args = append(args, "FILTER", options.Filter) diff --git a/search_test.go b/search_test.go index e4e55215..993116da 100644 --- a/search_test.go +++ b/search_test.go @@ -616,6 +616,11 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() { res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result() Expect(err).NotTo(HaveOccurred()) Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("b")) + + options = &redis.FTAggregateOptions{SortBy: []redis.FTAggregateSortBy{{FieldName: "@t1"}}, Limit: 1, LimitOffset: 0} + res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result() + Expect(err).NotTo(HaveOccurred()) + Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("a")) }) It("should FTAggregate load ", Label("search", "ftaggregate"), func() {