@@ -1063,15 +1063,15 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
1063
1063
Params : map [string ]interface {}{"shape" : "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))" },
1064
1064
}).Result ()
1065
1065
Expect (err ).NotTo (HaveOccurred ())
1066
- _assert_geosearch_result (client , & intersection , []string {"doc_point2" , "doc_polygon1" })
1066
+ _assert_geosearch_result (& intersection , []string {"doc_point2" , "doc_polygon1" })
1067
1067
1068
1068
disjunction , err := client .FTSearchWithArgs (ctx , "idx1" , "@g:[disjoint $shape]" ,
1069
1069
& redis.FTSearchOptions {
1070
1070
DialectVersion : 3 ,
1071
1071
Params : map [string ]interface {}{"shape" : "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))" },
1072
1072
}).Result ()
1073
1073
Expect (err ).NotTo (HaveOccurred ())
1074
- _assert_geosearch_result (client , & disjunction , []string {"doc_point1" , "doc_polygon2" })
1074
+ _assert_geosearch_result (& disjunction , []string {"doc_point1" , "doc_polygon2" })
1075
1075
})
1076
1076
1077
1077
It ("should test geoshapes query contains and within" , func () {
@@ -1093,28 +1093,117 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
1093
1093
Params : map [string ]interface {}{"shape" : "POINT(25 25)" },
1094
1094
}).Result ()
1095
1095
Expect (err ).NotTo (HaveOccurred ())
1096
- _assert_geosearch_result (client , & containsA , []string {"doc_polygon1" })
1096
+ _assert_geosearch_result (& containsA , []string {"doc_polygon1" })
1097
1097
1098
1098
containsB , err := client .FTSearchWithArgs (ctx , "idx2" , "@g:[contains $shape]" ,
1099
1099
& redis.FTSearchOptions {
1100
1100
DialectVersion : 3 ,
1101
1101
Params : map [string ]interface {}{"shape" : "POLYGON((24 24, 24 26, 25 25, 24 24))" },
1102
1102
}).Result ()
1103
1103
Expect (err ).NotTo (HaveOccurred ())
1104
- _assert_geosearch_result (client , & containsB , []string {"doc_polygon1" })
1104
+ _assert_geosearch_result (& containsB , []string {"doc_polygon1" })
1105
1105
1106
1106
within , err := client .FTSearchWithArgs (ctx , "idx2" , "@g:[within $shape]" ,
1107
1107
& redis.FTSearchOptions {
1108
1108
DialectVersion : 3 ,
1109
1109
Params : map [string ]interface {}{"shape" : "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))" },
1110
1110
}).Result ()
1111
1111
Expect (err ).NotTo (HaveOccurred ())
1112
- _assert_geosearch_result (client , & within , []string {"doc_point2" , "doc_polygon1" })
1112
+ _assert_geosearch_result (& within , []string {"doc_point2" , "doc_polygon1" })
1113
1113
})
1114
1114
1115
+ It ("should search missing fields" , Label ("search" , "ftcreate" , "ftsearch" , "NonRedisEnterprise" ), func () {
1116
+ val , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {Prefix : []interface {}{"property:" }},
1117
+ & redis.FieldSchema {FieldName : "title" , FieldType : redis .SearchFieldTypeText , Sortable : true },
1118
+ & redis.FieldSchema {FieldName : "features" , FieldType : redis .SearchFieldTypeTag , IndexMissing : true },
1119
+ & redis.FieldSchema {FieldName : "description" , FieldType : redis .SearchFieldTypeText , IndexMissing : true }).Result ()
1120
+ Expect (err ).NotTo (HaveOccurred ())
1121
+ Expect (val ).To (BeEquivalentTo ("OK" ))
1122
+ WaitForIndexing (client , "idx1" )
1123
+
1124
+ client .HSet (ctx , "property:1" , map [string ]interface {}{
1125
+ "title" : "Luxury Villa in Malibu" ,
1126
+ "features" : "pool,sea view,modern" ,
1127
+ "description" : "A stunning modern villa overlooking the Pacific Ocean." ,
1128
+ })
1129
+
1130
+ client .HSet (ctx , "property:2" , map [string ]interface {}{
1131
+ "title" : "Downtown Flat" ,
1132
+ "description" : "Modern flat in central Paris with easy access to metro." ,
1133
+ })
1134
+
1135
+ client .HSet (ctx , "property:3" , map [string ]interface {}{
1136
+ "title" : "Beachfront Bungalow" ,
1137
+ "features" : "beachfront,sun deck" ,
1138
+ })
1139
+
1140
+ res , err := client .FTSearchWithArgs (ctx , "idx1" , "ismissing(@features)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1141
+ Expect (err ).NotTo (HaveOccurred ())
1142
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:2" ))
1143
+
1144
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-ismissing(@features)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1145
+ Expect (err ).NotTo (HaveOccurred ())
1146
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1147
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:3" ))
1148
+
1149
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "ismissing(@description)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1150
+ Expect (err ).NotTo (HaveOccurred ())
1151
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:3" ))
1152
+
1153
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-ismissing(@description)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1154
+ Expect (err ).NotTo (HaveOccurred ())
1155
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1156
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:2" ))
1157
+ })
1158
+
1159
+ It ("should search empty fields" , Label ("search" , "ftcreate" , "ftsearch" , "NonRedisEnterprise" ), func () {
1160
+ val , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {Prefix : []interface {}{"property:" }},
1161
+ & redis.FieldSchema {FieldName : "title" , FieldType : redis .SearchFieldTypeText , Sortable : true },
1162
+ & redis.FieldSchema {FieldName : "features" , FieldType : redis .SearchFieldTypeTag , IndexEmpty : true },
1163
+ & redis.FieldSchema {FieldName : "description" , FieldType : redis .SearchFieldTypeText , IndexEmpty : true }).Result ()
1164
+ Expect (err ).NotTo (HaveOccurred ())
1165
+ Expect (val ).To (BeEquivalentTo ("OK" ))
1166
+ WaitForIndexing (client , "idx1" )
1167
+
1168
+ client .HSet (ctx , "property:1" , map [string ]interface {}{
1169
+ "title" : "Luxury Villa in Malibu" ,
1170
+ "features" : "pool,sea view,modern" ,
1171
+ "description" : "A stunning modern villa overlooking the Pacific Ocean." ,
1172
+ })
1173
+
1174
+ client .HSet (ctx , "property:2" , map [string ]interface {}{
1175
+ "title" : "Downtown Flat" ,
1176
+ "features" : "" ,
1177
+ "description" : "Modern flat in central Paris with easy access to metro." ,
1178
+ })
1179
+
1180
+ client .HSet (ctx , "property:3" , map [string ]interface {}{
1181
+ "title" : "Beachfront Bungalow" ,
1182
+ "features" : "beachfront,sun deck" ,
1183
+ "description" : "" ,
1184
+ })
1185
+
1186
+ res , err := client .FTSearchWithArgs (ctx , "idx1" , "@features:{\" \" }" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1187
+ Expect (err ).NotTo (HaveOccurred ())
1188
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:2" ))
1189
+
1190
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-@features:{\" \" }" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1191
+ Expect (err ).NotTo (HaveOccurred ())
1192
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1193
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:3" ))
1194
+
1195
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "@description:''" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1196
+ Expect (err ).NotTo (HaveOccurred ())
1197
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:3" ))
1198
+
1199
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-@description:''" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1200
+ Expect (err ).NotTo (HaveOccurred ())
1201
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1202
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:2" ))
1203
+ })
1115
1204
})
1116
1205
1117
- func _assert_geosearch_result (client * redis. Client , result * redis.FTSearchResult , expectedDocIDs []string ) {
1206
+ func _assert_geosearch_result (result * redis.FTSearchResult , expectedDocIDs []string ) {
1118
1207
ids := make ([]string , len (result .Docs ))
1119
1208
for i , doc := range result .Docs {
1120
1209
ids [i ] = doc .ID
0 commit comments