Skip to content

Commit d5ecd54

Browse files
authored
Merge branch 'master' into os-test-dialect-4
2 parents f3770ac + 95c5deb commit d5ecd54

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

search_commands.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ type FieldSchema struct {
7575
WithSuffixtrie bool
7676
VectorArgs *FTVectorArgs
7777
GeoShapeFieldType string
78+
IndexEmpty bool
79+
IndexMissing bool
7880
}
7981

8082
type FTVectorArgs struct {
@@ -1002,6 +1004,13 @@ func (c cmdable) FTCreate(ctx context.Context, index string, options *FTCreateOp
10021004
if schema.WithSuffixtrie {
10031005
args = append(args, "WITHSUFFIXTRIE")
10041006
}
1007+
if schema.IndexEmpty {
1008+
args = append(args, "INDEXEMPTY")
1009+
}
1010+
if schema.IndexMissing {
1011+
args = append(args, "INDEXMISSING")
1012+
1013+
}
10051014
}
10061015
cmd := NewStatusCmd(ctx, args...)
10071016
_ = c(ctx, cmd)

search_test.go

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,96 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
11471147
Expect(err).NotTo(HaveOccurred())
11481148
Expect(res2.Total).To(BeEquivalentTo(int64(2)))
11491149
})
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+
})
11501240
})
11511241

11521242
// It("should FTProfile Search and Aggregate", Label("search", "ftprofile"), func() {

0 commit comments

Comments
 (0)