@@ -1017,6 +1017,110 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
1017
1017
Expect (res .Attributes [0 ].WithSuffixtrie ).To (BeTrue ())
1018
1018
})
1019
1019
1020
+ It ("should test dialect 4" , Label ("search" , "ftcreate" , "ftsearch" , "NonRedisEnterprise" ), func () {
1021
+ val , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {
1022
+ Prefix : []interface {}{"resource:" },
1023
+ }, & redis.FieldSchema {
1024
+ FieldName : "uuid" ,
1025
+ FieldType : redis .SearchFieldTypeTag ,
1026
+ }, & redis.FieldSchema {
1027
+ FieldName : "tags" ,
1028
+ FieldType : redis .SearchFieldTypeTag ,
1029
+ }, & redis.FieldSchema {
1030
+ FieldName : "description" ,
1031
+ FieldType : redis .SearchFieldTypeText ,
1032
+ }, & redis.FieldSchema {
1033
+ FieldName : "rating" ,
1034
+ FieldType : redis .SearchFieldTypeNumeric ,
1035
+ }).Result ()
1036
+ Expect (err ).NotTo (HaveOccurred ())
1037
+ Expect (val ).To (BeEquivalentTo ("OK" ))
1038
+
1039
+ client .HSet (ctx , "resource:1" , map [string ]interface {}{
1040
+ "uuid" : "123e4567-e89b-12d3-a456-426614174000" ,
1041
+ "tags" : "finance|crypto|$btc|blockchain" ,
1042
+ "description" : "Analysis of blockchain technologies & Bitcoin's potential." ,
1043
+ "rating" : 5 ,
1044
+ })
1045
+ client .HSet (ctx , "resource:2" , map [string ]interface {}{
1046
+ "uuid" : "987e6543-e21c-12d3-a456-426614174999" ,
1047
+ "tags" : "health|well-being|fitness|new-year's-resolutions" ,
1048
+ "description" : "Health trends for the new year, including fitness regimes." ,
1049
+ "rating" : 4 ,
1050
+ })
1051
+
1052
+ res , err := client .FTSearchWithArgs (ctx , "idx1" , "@uuid:{$uuid}" ,
1053
+ & redis.FTSearchOptions {
1054
+ DialectVersion : 2 ,
1055
+ Params : map [string ]interface {}{"uuid" : "123e4567-e89b-12d3-a456-426614174000" },
1056
+ }).Result ()
1057
+ Expect (err ).NotTo (HaveOccurred ())
1058
+ Expect (res .Total ).To (BeEquivalentTo (int64 (1 )))
1059
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("resource:1" ))
1060
+
1061
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "@uuid:{$uuid}" ,
1062
+ & redis.FTSearchOptions {
1063
+ DialectVersion : 4 ,
1064
+ Params : map [string ]interface {}{"uuid" : "123e4567-e89b-12d3-a456-426614174000" },
1065
+ }).Result ()
1066
+ Expect (err ).NotTo (HaveOccurred ())
1067
+ Expect (res .Total ).To (BeEquivalentTo (int64 (1 )))
1068
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("resource:1" ))
1069
+
1070
+ client .HSet (ctx , "test:1" , map [string ]interface {}{
1071
+ "uuid" : "3d3586fe-0416-4572-8ce" ,
1072
+
1073
+ "num" : 5 ,
1074
+ })
1075
+
1076
+ // Create the index
1077
+ ftCreateOptions := & redis.FTCreateOptions {
1078
+ Prefix : []interface {}{"test:" },
1079
+ }
1080
+ schema := []* redis.FieldSchema {
1081
+ {
1082
+ FieldName : "uuid" ,
1083
+ FieldType : redis .SearchFieldTypeTag ,
1084
+ },
1085
+ {
1086
+ FieldName : "email" ,
1087
+ FieldType : redis .SearchFieldTypeTag ,
1088
+ },
1089
+ {
1090
+ FieldName : "num" ,
1091
+ FieldType : redis .SearchFieldTypeNumeric ,
1092
+ },
1093
+ }
1094
+
1095
+ val , err = client .FTCreate (ctx , "idx_hash" , ftCreateOptions , schema ... ).Result ()
1096
+ Expect (err ).NotTo (HaveOccurred ())
1097
+ Expect (val ).To (Equal ("OK" ))
1098
+
1099
+ ftSearchOptions := & redis.FTSearchOptions {
1100
+ DialectVersion : 4 ,
1101
+ Params : map [string ]interface {}{
1102
+ "uuid" : "3d3586fe-0416-4572-8ce" ,
1103
+
1104
+ },
1105
+ }
1106
+
1107
+ res , err = client .FTSearchWithArgs (ctx , "idx_hash" , "@uuid:{$uuid}" , ftSearchOptions ).Result ()
1108
+ Expect (err ).NotTo (HaveOccurred ())
1109
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("test:1" ))
1110
+ Expect (res .Docs [0 ].Fields ["uuid" ]).To (BeEquivalentTo ("3d3586fe-0416-4572-8ce" ))
1111
+
1112
+ res , err = client .FTSearchWithArgs (ctx , "idx_hash" , "@email:{$email}" , ftSearchOptions ).Result ()
1113
+ Expect (err ).NotTo (HaveOccurred ())
1114
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("test:1" ))
1115
+ Expect (
res .
Docs [
0 ].
Fields [
"email" ]).
To (
BeEquivalentTo (
"[email protected] " ))
1116
+
1117
+ ftSearchOptions .Params = map [string ]interface {}{"num" : 5 }
1118
+ res , err = client .FTSearchWithArgs (ctx , "idx_hash" , "@num:[5]" , ftSearchOptions ).Result ()
1119
+ Expect (err ).NotTo (HaveOccurred ())
1120
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("test:1" ))
1121
+ Expect (res .Docs [0 ].Fields ["num" ]).To (BeEquivalentTo ("5" ))
1122
+ })
1123
+
1020
1124
It ("should FTCreate GeoShape" , Label ("search" , "ftcreate" , "ftsearch" ), func () {
1021
1125
val , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {}, & redis.FieldSchema {FieldName : "geom" , FieldType : redis .SearchFieldTypeGeoShape , GeoShapeFieldType : "FLAT" }).Result ()
1022
1126
Expect (err ).NotTo (HaveOccurred ())
0 commit comments