diff --git a/search_commands.go b/search_commands.go index 85e12561..8cdf0570 100644 --- a/search_commands.go +++ b/search_commands.go @@ -320,6 +320,7 @@ type FTSearchOptions struct { SortByWithCount bool LimitOffset int Limit int + CountOnly bool Params map[string]interface{} DialectVersion int } @@ -1954,8 +1955,12 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin args = append(args, "WITHCOUNT") } } - if options.LimitOffset >= 0 && options.Limit > 0 { - args = append(args, "LIMIT", options.LimitOffset, options.Limit) + if options.CountOnly { + args = append(args, "LIMIT", 0, 0) + } else { + if options.LimitOffset >= 0 && options.Limit > 0 || options.LimitOffset > 0 && options.Limit == 0 { + args = append(args, "LIMIT", options.LimitOffset, options.Limit) + } } if options.Params != nil { args = append(args, "PARAMS", len(options.Params)*2)