Skip to content

Commit ec5dddc

Browse files
committed
Merge branch 'master' of https://github.com/redis/go-redis into os-add-geo-tests
2 parents 206719f + 95c5deb commit ec5dddc

File tree

2 files changed

+104
-6
lines changed

2 files changed

+104
-6
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: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,15 +1063,15 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
10631063
Params: map[string]interface{}{"shape": "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))"},
10641064
}).Result()
10651065
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"})
10671067

10681068
disjunction, err := client.FTSearchWithArgs(ctx, "idx1", "@g:[disjoint $shape]",
10691069
&redis.FTSearchOptions{
10701070
DialectVersion: 3,
10711071
Params: map[string]interface{}{"shape": "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))"},
10721072
}).Result()
10731073
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"})
10751075
})
10761076

10771077
It("should test geoshapes query contains and within", func() {
@@ -1093,28 +1093,117 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
10931093
Params: map[string]interface{}{"shape": "POINT(25 25)"},
10941094
}).Result()
10951095
Expect(err).NotTo(HaveOccurred())
1096-
_assert_geosearch_result(client, &containsA, []string{"doc_polygon1"})
1096+
_assert_geosearch_result(&containsA, []string{"doc_polygon1"})
10971097

10981098
containsB, err := client.FTSearchWithArgs(ctx, "idx2", "@g:[contains $shape]",
10991099
&redis.FTSearchOptions{
11001100
DialectVersion: 3,
11011101
Params: map[string]interface{}{"shape": "POLYGON((24 24, 24 26, 25 25, 24 24))"},
11021102
}).Result()
11031103
Expect(err).NotTo(HaveOccurred())
1104-
_assert_geosearch_result(client, &containsB, []string{"doc_polygon1"})
1104+
_assert_geosearch_result(&containsB, []string{"doc_polygon1"})
11051105

11061106
within, err := client.FTSearchWithArgs(ctx, "idx2", "@g:[within $shape]",
11071107
&redis.FTSearchOptions{
11081108
DialectVersion: 3,
11091109
Params: map[string]interface{}{"shape": "POLYGON((15 15, 75 15, 50 70, 20 40, 15 15))"},
11101110
}).Result()
11111111
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"})
11131113
})
11141114

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+
})
11151204
})
11161205

1117-
func _assert_geosearch_result(client *redis.Client, result *redis.FTSearchResult, expectedDocIDs []string) {
1206+
func _assert_geosearch_result(result *redis.FTSearchResult, expectedDocIDs []string) {
11181207
ids := make([]string, len(result.Docs))
11191208
for i, doc := range result.Docs {
11201209
ids[i] = doc.ID

0 commit comments

Comments
 (0)