Skip to content

Commit 196fc9b

Browse files
authored
use limit when limitoffset is zero (#3275)
1 parent 9db1286 commit 196fc9b

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

search_commands.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -574,11 +574,8 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
574574
if options.SortByMax > 0 {
575575
queryArgs = append(queryArgs, "MAX", options.SortByMax)
576576
}
577-
if options.LimitOffset > 0 {
578-
queryArgs = append(queryArgs, "LIMIT", options.LimitOffset)
579-
}
580-
if options.Limit > 0 {
581-
queryArgs = append(queryArgs, options.Limit)
577+
if options.LimitOffset >= 0 && options.Limit > 0 {
578+
queryArgs = append(queryArgs, "LIMIT", options.LimitOffset, options.Limit)
582579
}
583580
if options.Filter != "" {
584581
queryArgs = append(queryArgs, "FILTER", options.Filter)
@@ -773,11 +770,8 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
773770
if options.SortByMax > 0 {
774771
args = append(args, "MAX", options.SortByMax)
775772
}
776-
if options.LimitOffset > 0 {
777-
args = append(args, "LIMIT", options.LimitOffset)
778-
}
779-
if options.Limit > 0 {
780-
args = append(args, options.Limit)
773+
if options.LimitOffset >= 0 && options.Limit > 0 {
774+
args = append(args, "LIMIT", options.LimitOffset, options.Limit)
781775
}
782776
if options.Filter != "" {
783777
args = append(args, "FILTER", options.Filter)

search_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,11 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
616616
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
617617
Expect(err).NotTo(HaveOccurred())
618618
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("b"))
619+
620+
options = &redis.FTAggregateOptions{SortBy: []redis.FTAggregateSortBy{{FieldName: "@t1"}}, Limit: 1, LimitOffset: 0}
621+
res, err = client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
622+
Expect(err).NotTo(HaveOccurred())
623+
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("a"))
619624
})
620625

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

0 commit comments

Comments
 (0)