@@ -3,6 +3,7 @@ package redis_test
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "reflect"
6
7
"strconv"
7
8
"time"
8
9
@@ -806,6 +807,72 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
806
807
}
807
808
})
808
809
810
+ It ("should return only the base query when options is nil" , Label ("search" , "ftaggregate" ), func () {
811
+ args := redis .FTAggregateQuery ("testQuery" , nil )
812
+ Expect (args ).To (Equal (redis.AggregateQuery {"testQuery" }))
813
+ })
814
+
815
+ It ("should include VERBATIM and SCORER when options are set" , Label ("search" , "ftaggregate" ), func () {
816
+ options := & redis.FTAggregateOptions {
817
+ Verbatim : true ,
818
+ Scorer : "BM25" ,
819
+ }
820
+ args := redis .FTAggregateQuery ("testQuery" , options )
821
+ Expect (args [0 ]).To (Equal ("testQuery" ))
822
+ Expect (args ).To (ContainElement ("VERBATIM" ))
823
+ Expect (args ).To (ContainElement ("SCORER" ))
824
+ Expect (args ).To (ContainElement ("BM25" ))
825
+ })
826
+
827
+ It ("should include ADDSCORES when AddScores is true" , Label ("search" , "ftaggregate" ), func () {
828
+ options := & redis.FTAggregateOptions {
829
+ AddScores : true ,
830
+ }
831
+ args := redis .FTAggregateQuery ("q" , options )
832
+ Expect (args ).To (ContainElement ("ADDSCORES" ))
833
+ })
834
+
835
+ It ("should include LOADALL when LoadAll is true" , Label ("search" , "ftaggregate" ), func () {
836
+ options := & redis.FTAggregateOptions {
837
+ LoadAll : true ,
838
+ }
839
+ args := redis .FTAggregateQuery ("q" , options )
840
+ Expect (args ).To (ContainElement ("LOAD" ))
841
+ Expect (args ).To (ContainElement ("*" ))
842
+ })
843
+
844
+ It ("should include LOAD when Load is provided" , Label ("search" , "ftaggregate" ), func () {
845
+ options := & redis.FTAggregateOptions {
846
+ Load : []redis.FTAggregateLoad {
847
+ {Field : "field1" , As : "alias1" },
848
+ {Field : "field2" },
849
+ },
850
+ }
851
+ args := redis .FTAggregateQuery ("q" , options )
852
+ // Verify LOAD options related arguments
853
+ Expect (args ).To (ContainElement ("LOAD" ))
854
+ // Check that field names and aliases are present
855
+ Expect (args ).To (ContainElement ("field1" ))
856
+ Expect (args ).To (ContainElement ("alias1" ))
857
+ Expect (args ).To (ContainElement ("field2" ))
858
+ })
859
+
860
+ It ("should include TIMEOUT when Timeout > 0" , Label ("search" , "ftaggregate" ), func () {
861
+ options := & redis.FTAggregateOptions {
862
+ Timeout : 500 ,
863
+ }
864
+ args := redis .FTAggregateQuery ("q" , options )
865
+ Expect (args ).To (ContainElement ("TIMEOUT" ))
866
+ found := false
867
+ for _ , a := range args {
868
+ if reflect .DeepEqual (a , 500 ) {
869
+ found = true
870
+ break
871
+ }
872
+ }
873
+ Expect (found ).To (BeTrue ())
874
+ })
875
+
809
876
It ("should FTSearch SkipInitialScan" , Label ("search" , "ftsearch" ), func () {
810
877
client .HSet (ctx , "doc1" , "foo" , "bar" )
811
878
0 commit comments