Skip to content

Commit 95c5deb

Browse files
authored
Support RediSearch empty values (#3053)
* Support RediSearch empty values * Remove from enterprise
1 parent 67824eb commit 95c5deb

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
@@ -1043,6 +1043,96 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
10431043
Expect(err).NotTo(HaveOccurred())
10441044
Expect(res2.Total).To(BeEquivalentTo(int64(2)))
10451045
})
1046+
1047+
It("should search missing fields", Label("search", "ftcreate", "ftsearch", "NonRedisEnterprise"), func() {
1048+
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{Prefix: []interface{}{"property:"}},
1049+
&redis.FieldSchema{FieldName: "title", FieldType: redis.SearchFieldTypeText, Sortable: true},
1050+
&redis.FieldSchema{FieldName: "features", FieldType: redis.SearchFieldTypeTag, IndexMissing: true},
1051+
&redis.FieldSchema{FieldName: "description", FieldType: redis.SearchFieldTypeText, IndexMissing: true}).Result()
1052+
Expect(err).NotTo(HaveOccurred())
1053+
Expect(val).To(BeEquivalentTo("OK"))
1054+
WaitForIndexing(client, "idx1")
1055+
1056+
client.HSet(ctx, "property:1", map[string]interface{}{
1057+
"title": "Luxury Villa in Malibu",
1058+
"features": "pool,sea view,modern",
1059+
"description": "A stunning modern villa overlooking the Pacific Ocean.",
1060+
})
1061+
1062+
client.HSet(ctx, "property:2", map[string]interface{}{
1063+
"title": "Downtown Flat",
1064+
"description": "Modern flat in central Paris with easy access to metro.",
1065+
})
1066+
1067+
client.HSet(ctx, "property:3", map[string]interface{}{
1068+
"title": "Beachfront Bungalow",
1069+
"features": "beachfront,sun deck",
1070+
})
1071+
1072+
res, err := client.FTSearchWithArgs(ctx, "idx1", "ismissing(@features)", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1073+
Expect(err).NotTo(HaveOccurred())
1074+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:2"))
1075+
1076+
res, err = client.FTSearchWithArgs(ctx, "idx1", "-ismissing(@features)", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1077+
Expect(err).NotTo(HaveOccurred())
1078+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:1"))
1079+
Expect(res.Docs[1].ID).To(BeEquivalentTo("property:3"))
1080+
1081+
res, err = client.FTSearchWithArgs(ctx, "idx1", "ismissing(@description)", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1082+
Expect(err).NotTo(HaveOccurred())
1083+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:3"))
1084+
1085+
res, err = client.FTSearchWithArgs(ctx, "idx1", "-ismissing(@description)", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1086+
Expect(err).NotTo(HaveOccurred())
1087+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:1"))
1088+
Expect(res.Docs[1].ID).To(BeEquivalentTo("property:2"))
1089+
})
1090+
1091+
It("should search empty fields", Label("search", "ftcreate", "ftsearch", "NonRedisEnterprise"), func() {
1092+
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{Prefix: []interface{}{"property:"}},
1093+
&redis.FieldSchema{FieldName: "title", FieldType: redis.SearchFieldTypeText, Sortable: true},
1094+
&redis.FieldSchema{FieldName: "features", FieldType: redis.SearchFieldTypeTag, IndexEmpty: true},
1095+
&redis.FieldSchema{FieldName: "description", FieldType: redis.SearchFieldTypeText, IndexEmpty: true}).Result()
1096+
Expect(err).NotTo(HaveOccurred())
1097+
Expect(val).To(BeEquivalentTo("OK"))
1098+
WaitForIndexing(client, "idx1")
1099+
1100+
client.HSet(ctx, "property:1", map[string]interface{}{
1101+
"title": "Luxury Villa in Malibu",
1102+
"features": "pool,sea view,modern",
1103+
"description": "A stunning modern villa overlooking the Pacific Ocean.",
1104+
})
1105+
1106+
client.HSet(ctx, "property:2", map[string]interface{}{
1107+
"title": "Downtown Flat",
1108+
"features": "",
1109+
"description": "Modern flat in central Paris with easy access to metro.",
1110+
})
1111+
1112+
client.HSet(ctx, "property:3", map[string]interface{}{
1113+
"title": "Beachfront Bungalow",
1114+
"features": "beachfront,sun deck",
1115+
"description": "",
1116+
})
1117+
1118+
res, err := client.FTSearchWithArgs(ctx, "idx1", "@features:{\"\"}", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1119+
Expect(err).NotTo(HaveOccurred())
1120+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:2"))
1121+
1122+
res, err = client.FTSearchWithArgs(ctx, "idx1", "-@features:{\"\"}", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1123+
Expect(err).NotTo(HaveOccurred())
1124+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:1"))
1125+
Expect(res.Docs[1].ID).To(BeEquivalentTo("property:3"))
1126+
1127+
res, err = client.FTSearchWithArgs(ctx, "idx1", "@description:''", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1128+
Expect(err).NotTo(HaveOccurred())
1129+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:3"))
1130+
1131+
res, err = client.FTSearchWithArgs(ctx, "idx1", "-@description:''", &redis.FTSearchOptions{DialectVersion: 4, Return: []redis.FTSearchReturn{{FieldName: "id"}}, NoContent: true}).Result()
1132+
Expect(err).NotTo(HaveOccurred())
1133+
Expect(res.Docs[0].ID).To(BeEquivalentTo("property:1"))
1134+
Expect(res.Docs[1].ID).To(BeEquivalentTo("property:2"))
1135+
})
10461136
})
10471137

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

0 commit comments

Comments
 (0)