@@ -1147,6 +1147,96 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
1147
1147
Expect (err ).NotTo (HaveOccurred ())
1148
1148
Expect (res2 .Total ).To (BeEquivalentTo (int64 (2 )))
1149
1149
})
1150
+
1151
+ It ("should search missing fields" , Label ("search" , "ftcreate" , "ftsearch" , "NonRedisEnterprise" ), func () {
1152
+ val , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {Prefix : []interface {}{"property:" }},
1153
+ & redis.FieldSchema {FieldName : "title" , FieldType : redis .SearchFieldTypeText , Sortable : true },
1154
+ & redis.FieldSchema {FieldName : "features" , FieldType : redis .SearchFieldTypeTag , IndexMissing : true },
1155
+ & redis.FieldSchema {FieldName : "description" , FieldType : redis .SearchFieldTypeText , IndexMissing : true }).Result ()
1156
+ Expect (err ).NotTo (HaveOccurred ())
1157
+ Expect (val ).To (BeEquivalentTo ("OK" ))
1158
+ WaitForIndexing (client , "idx1" )
1159
+
1160
+ client .HSet (ctx , "property:1" , map [string ]interface {}{
1161
+ "title" : "Luxury Villa in Malibu" ,
1162
+ "features" : "pool,sea view,modern" ,
1163
+ "description" : "A stunning modern villa overlooking the Pacific Ocean." ,
1164
+ })
1165
+
1166
+ client .HSet (ctx , "property:2" , map [string ]interface {}{
1167
+ "title" : "Downtown Flat" ,
1168
+ "description" : "Modern flat in central Paris with easy access to metro." ,
1169
+ })
1170
+
1171
+ client .HSet (ctx , "property:3" , map [string ]interface {}{
1172
+ "title" : "Beachfront Bungalow" ,
1173
+ "features" : "beachfront,sun deck" ,
1174
+ })
1175
+
1176
+ res , err := client .FTSearchWithArgs (ctx , "idx1" , "ismissing(@features)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1177
+ Expect (err ).NotTo (HaveOccurred ())
1178
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:2" ))
1179
+
1180
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-ismissing(@features)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1181
+ Expect (err ).NotTo (HaveOccurred ())
1182
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1183
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:3" ))
1184
+
1185
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "ismissing(@description)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1186
+ Expect (err ).NotTo (HaveOccurred ())
1187
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:3" ))
1188
+
1189
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-ismissing(@description)" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1190
+ Expect (err ).NotTo (HaveOccurred ())
1191
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1192
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:2" ))
1193
+ })
1194
+
1195
+ It ("should search empty fields" , Label ("search" , "ftcreate" , "ftsearch" , "NonRedisEnterprise" ), func () {
1196
+ val , err := client .FTCreate (ctx , "idx1" , & redis.FTCreateOptions {Prefix : []interface {}{"property:" }},
1197
+ & redis.FieldSchema {FieldName : "title" , FieldType : redis .SearchFieldTypeText , Sortable : true },
1198
+ & redis.FieldSchema {FieldName : "features" , FieldType : redis .SearchFieldTypeTag , IndexEmpty : true },
1199
+ & redis.FieldSchema {FieldName : "description" , FieldType : redis .SearchFieldTypeText , IndexEmpty : true }).Result ()
1200
+ Expect (err ).NotTo (HaveOccurred ())
1201
+ Expect (val ).To (BeEquivalentTo ("OK" ))
1202
+ WaitForIndexing (client , "idx1" )
1203
+
1204
+ client .HSet (ctx , "property:1" , map [string ]interface {}{
1205
+ "title" : "Luxury Villa in Malibu" ,
1206
+ "features" : "pool,sea view,modern" ,
1207
+ "description" : "A stunning modern villa overlooking the Pacific Ocean." ,
1208
+ })
1209
+
1210
+ client .HSet (ctx , "property:2" , map [string ]interface {}{
1211
+ "title" : "Downtown Flat" ,
1212
+ "features" : "" ,
1213
+ "description" : "Modern flat in central Paris with easy access to metro." ,
1214
+ })
1215
+
1216
+ client .HSet (ctx , "property:3" , map [string ]interface {}{
1217
+ "title" : "Beachfront Bungalow" ,
1218
+ "features" : "beachfront,sun deck" ,
1219
+ "description" : "" ,
1220
+ })
1221
+
1222
+ res , err := client .FTSearchWithArgs (ctx , "idx1" , "@features:{\" \" }" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1223
+ Expect (err ).NotTo (HaveOccurred ())
1224
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:2" ))
1225
+
1226
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-@features:{\" \" }" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1227
+ Expect (err ).NotTo (HaveOccurred ())
1228
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1229
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:3" ))
1230
+
1231
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "@description:''" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1232
+ Expect (err ).NotTo (HaveOccurred ())
1233
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:3" ))
1234
+
1235
+ res , err = client .FTSearchWithArgs (ctx , "idx1" , "-@description:''" , & redis.FTSearchOptions {DialectVersion : 4 , Return : []redis.FTSearchReturn {{FieldName : "id" }}, NoContent : true }).Result ()
1236
+ Expect (err ).NotTo (HaveOccurred ())
1237
+ Expect (res .Docs [0 ].ID ).To (BeEquivalentTo ("property:1" ))
1238
+ Expect (res .Docs [1 ].ID ).To (BeEquivalentTo ("property:2" ))
1239
+ })
1150
1240
})
1151
1241
1152
1242
// It("should FTProfile Search and Aggregate", Label("search", "ftprofile"), func() {
0 commit comments