mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
Merge remote-tracking branch 'origin/master' into ndyakov/update-readme-discord
This commit is contained in:
commit
27cfce4485
@ -320,8 +320,11 @@ type FTSearchOptions struct {
|
|||||||
SortByWithCount bool
|
SortByWithCount bool
|
||||||
LimitOffset int
|
LimitOffset int
|
||||||
Limit int
|
Limit int
|
||||||
Params map[string]interface{}
|
// CountOnly sets LIMIT 0 0 to get the count - number of documents in the result set without actually returning the result set.
|
||||||
DialectVersion int
|
// When using this option, the Limit and LimitOffset options are ignored.
|
||||||
|
CountOnly bool
|
||||||
|
Params map[string]interface{}
|
||||||
|
DialectVersion int
|
||||||
}
|
}
|
||||||
|
|
||||||
type FTSynDumpResult struct {
|
type FTSynDumpResult struct {
|
||||||
@ -1954,8 +1957,12 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
|
|||||||
args = append(args, "WITHCOUNT")
|
args = append(args, "WITHCOUNT")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if options.LimitOffset >= 0 && options.Limit > 0 {
|
if options.CountOnly {
|
||||||
args = append(args, "LIMIT", options.LimitOffset, options.Limit)
|
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 {
|
if options.Params != nil {
|
||||||
args = append(args, "PARAMS", len(options.Params)*2)
|
args = append(args, "PARAMS", len(options.Params)*2)
|
||||||
|
@ -1683,6 +1683,44 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
|
|||||||
Expect(resUint8.Docs[0].ID).To(BeEquivalentTo("doc1"))
|
Expect(resUint8.Docs[0].ID).To(BeEquivalentTo("doc1"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should test ft.search with CountOnly param", Label("search", "ftsearch"), func() {
|
||||||
|
val, err := client.FTCreate(ctx, "txtIndex", &redis.FTCreateOptions{},
|
||||||
|
&redis.FieldSchema{FieldName: "txt", FieldType: redis.SearchFieldTypeText},
|
||||||
|
).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(val).To(BeEquivalentTo("OK"))
|
||||||
|
WaitForIndexing(client, "txtIndex")
|
||||||
|
|
||||||
|
_, err = client.HSet(ctx, "doc1", "txt", "hello world").Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
_, err = client.HSet(ctx, "doc2", "txt", "hello go").Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
_, err = client.HSet(ctx, "doc3", "txt", "hello redis").Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
|
optsCountOnly := &redis.FTSearchOptions{
|
||||||
|
CountOnly: true,
|
||||||
|
LimitOffset: 0,
|
||||||
|
Limit: 2, // even though we limit to 2, with count-only no docs are returned
|
||||||
|
DialectVersion: 2,
|
||||||
|
}
|
||||||
|
resCountOnly, err := client.FTSearchWithArgs(ctx, "txtIndex", "hello", optsCountOnly).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(resCountOnly.Total).To(BeEquivalentTo(3))
|
||||||
|
Expect(len(resCountOnly.Docs)).To(BeEquivalentTo(0))
|
||||||
|
|
||||||
|
optsLimit := &redis.FTSearchOptions{
|
||||||
|
CountOnly: false,
|
||||||
|
LimitOffset: 0,
|
||||||
|
Limit: 2, // we expect to get 2 documents even though total count is 3
|
||||||
|
DialectVersion: 2,
|
||||||
|
}
|
||||||
|
resLimit, err := client.FTSearchWithArgs(ctx, "txtIndex", "hello", optsLimit).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(resLimit.Total).To(BeEquivalentTo(3))
|
||||||
|
Expect(len(resLimit.Docs)).To(BeEquivalentTo(2))
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []string) {
|
func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []string) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user