Skip to content

Commit 4d09be3

Browse files
committed
use limit when limitoffset is zero (#3275)
1 parent 08e13a5 commit 4d09be3

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

search_commands.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -567,11 +567,8 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
567567
if options.SortByMax > 0 {
568568
queryArgs = append(queryArgs, "MAX", options.SortByMax)
569569
}
570-
if options.LimitOffset > 0 {
571-
queryArgs = append(queryArgs, "LIMIT", options.LimitOffset)
572-
}
573-
if options.Limit > 0 {
574-
queryArgs = append(queryArgs, options.Limit)
570+
if options.LimitOffset >= 0 && options.Limit > 0 {
571+
queryArgs = append(queryArgs, "LIMIT", options.LimitOffset, options.Limit)
575572
}
576573
if options.Filter != "" {
577574
queryArgs = append(queryArgs, "FILTER", options.Filter)
@@ -766,11 +763,8 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
766763
if options.SortByMax > 0 {
767764
args = append(args, "MAX", options.SortByMax)
768765
}
769-
if options.LimitOffset > 0 {
770-
args = append(args, "LIMIT", options.LimitOffset)
771-
}
772-
if options.Limit > 0 {
773-
args = append(args, options.Limit)
766+
if options.LimitOffset >= 0 && options.Limit > 0 {
767+
args = append(args, "LIMIT", options.LimitOffset, options.Limit)
774768
}
775769
if options.Filter != "" {
776770
args = append(args, "FILTER", options.Filter)

search_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,11 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
570570
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
571571
Expect(err).NotTo(HaveOccurred())
572572
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("b"))
573+
574+
options = &redis.FTAggregateOptions{SortBy: []redis.FTAggregateSortBy{{FieldName: "@t1"}}, Limit: 1, LimitOffset: 0}
575+
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
576+
Expect(err).NotTo(HaveOccurred())
577+
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("a"))
573578
})
574579

575580
It("should FTAggregate load ", Label("search", "ftaggregate"), func() {

0 commit comments

Comments
 (0)