@@ -1683,6 +1683,44 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
1683
1683
Expect (resUint8 .Docs [0 ].ID ).To (BeEquivalentTo ("doc1" ))
1684
1684
})
1685
1685
1686
+ It ("should test ft.search with CountOnly param" , Label ("search" , "ftsearch" ), func () {
1687
+ val , err := client .FTCreate (ctx , "txtIndex" , & redis.FTCreateOptions {},
1688
+ & redis.FieldSchema {FieldName : "txt" , FieldType : redis .SearchFieldTypeText },
1689
+ ).Result ()
1690
+ Expect (err ).NotTo (HaveOccurred ())
1691
+ Expect (val ).To (BeEquivalentTo ("OK" ))
1692
+ WaitForIndexing (client , "txtIndex" )
1693
+
1694
+ _ , err = client .HSet (ctx , "doc1" , "txt" , "hello world" ).Result ()
1695
+ Expect (err ).NotTo (HaveOccurred ())
1696
+ _ , err = client .HSet (ctx , "doc2" , "txt" , "hello go" ).Result ()
1697
+ Expect (err ).NotTo (HaveOccurred ())
1698
+ _ , err = client .HSet (ctx , "doc3" , "txt" , "hello redis" ).Result ()
1699
+ Expect (err ).NotTo (HaveOccurred ())
1700
+
1701
+ optsCountOnly := & redis.FTSearchOptions {
1702
+ CountOnly : true ,
1703
+ LimitOffset : 0 ,
1704
+ Limit : 2 , // even though we limit to 2, with count-only no docs are returned
1705
+ DialectVersion : 2 ,
1706
+ }
1707
+ resCountOnly , err := client .FTSearchWithArgs (ctx , "txtIndex" , "hello" , optsCountOnly ).Result ()
1708
+ Expect (err ).NotTo (HaveOccurred ())
1709
+ Expect (resCountOnly .Total ).To (BeEquivalentTo (3 ))
1710
+ Expect (len (resCountOnly .Docs )).To (BeEquivalentTo (0 ))
1711
+
1712
+ optsLimit := & redis.FTSearchOptions {
1713
+ CountOnly : false ,
1714
+ LimitOffset : 0 ,
1715
+ Limit : 2 , // we expect to get 2 documents even though total count is 3
1716
+ DialectVersion : 2 ,
1717
+ }
1718
+ resLimit , err := client .FTSearchWithArgs (ctx , "txtIndex" , "hello" , optsLimit ).Result ()
1719
+ Expect (err ).NotTo (HaveOccurred ())
1720
+ Expect (resLimit .Total ).To (BeEquivalentTo (3 ))
1721
+ Expect (len (resLimit .Docs )).To (BeEquivalentTo (2 ))
1722
+ })
1723
+
1686
1724
})
1687
1725
1688
1726
func _assert_geosearch_result (result * redis.FTSearchResult , expectedDocIDs []string ) {
0 commit comments