mirror of
https://github.com/redis/go-redis.git
synced 2025-07-28 06:42:00 +03:00
Fix FT.Search Limit argument and add CountOnly argument for limit 0 0 (#3338)
* Fix Limit argument and add CountOnly argument * Add test and Documentation * Update search_commands.go --------- Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com>
This commit is contained in:
@ -320,8 +320,11 @@ type FTSearchOptions struct {
|
||||
SortByWithCount bool
|
||||
LimitOffset int
|
||||
Limit int
|
||||
Params map[string]interface{}
|
||||
DialectVersion int
|
||||
// CountOnly sets LIMIT 0 0 to get the count - number of documents in the result set without actually returning the result set.
|
||||
// When using this option, the Limit and LimitOffset options are ignored.
|
||||
CountOnly bool
|
||||
Params map[string]interface{}
|
||||
DialectVersion int
|
||||
}
|
||||
|
||||
type FTSynDumpResult struct {
|
||||
@ -1954,8 +1957,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)
|
||||
|
Reference in New Issue
Block a user