mirror of https://github.com/go-redis/redis.git
Test RediSearch dialect 4 (#3052)
* Test dialect 4 * Add support for num and email * remove tests from RE
This commit is contained in:
parent
89f4dfa309
commit
46d2452fbb
104
search_test.go
104
search_test.go
|
@ -1017,6 +1017,110 @@ var _ = Describe("RediSearch commands", Label("search"), func() {
|
||||||
Expect(res.Attributes[0].WithSuffixtrie).To(BeTrue())
|
Expect(res.Attributes[0].WithSuffixtrie).To(BeTrue())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should test dialect 4", Label("search", "ftcreate", "ftsearch", "NonRedisEnterprise"), func() {
|
||||||
|
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{
|
||||||
|
Prefix: []interface{}{"resource:"},
|
||||||
|
}, &redis.FieldSchema{
|
||||||
|
FieldName: "uuid",
|
||||||
|
FieldType: redis.SearchFieldTypeTag,
|
||||||
|
}, &redis.FieldSchema{
|
||||||
|
FieldName: "tags",
|
||||||
|
FieldType: redis.SearchFieldTypeTag,
|
||||||
|
}, &redis.FieldSchema{
|
||||||
|
FieldName: "description",
|
||||||
|
FieldType: redis.SearchFieldTypeText,
|
||||||
|
}, &redis.FieldSchema{
|
||||||
|
FieldName: "rating",
|
||||||
|
FieldType: redis.SearchFieldTypeNumeric,
|
||||||
|
}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(val).To(BeEquivalentTo("OK"))
|
||||||
|
|
||||||
|
client.HSet(ctx, "resource:1", map[string]interface{}{
|
||||||
|
"uuid": "123e4567-e89b-12d3-a456-426614174000",
|
||||||
|
"tags": "finance|crypto|$btc|blockchain",
|
||||||
|
"description": "Analysis of blockchain technologies & Bitcoin's potential.",
|
||||||
|
"rating": 5,
|
||||||
|
})
|
||||||
|
client.HSet(ctx, "resource:2", map[string]interface{}{
|
||||||
|
"uuid": "987e6543-e21c-12d3-a456-426614174999",
|
||||||
|
"tags": "health|well-being|fitness|new-year's-resolutions",
|
||||||
|
"description": "Health trends for the new year, including fitness regimes.",
|
||||||
|
"rating": 4,
|
||||||
|
})
|
||||||
|
|
||||||
|
res, err := client.FTSearchWithArgs(ctx, "idx1", "@uuid:{$uuid}",
|
||||||
|
&redis.FTSearchOptions{
|
||||||
|
DialectVersion: 2,
|
||||||
|
Params: map[string]interface{}{"uuid": "123e4567-e89b-12d3-a456-426614174000"},
|
||||||
|
}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res.Total).To(BeEquivalentTo(int64(1)))
|
||||||
|
Expect(res.Docs[0].ID).To(BeEquivalentTo("resource:1"))
|
||||||
|
|
||||||
|
res, err = client.FTSearchWithArgs(ctx, "idx1", "@uuid:{$uuid}",
|
||||||
|
&redis.FTSearchOptions{
|
||||||
|
DialectVersion: 4,
|
||||||
|
Params: map[string]interface{}{"uuid": "123e4567-e89b-12d3-a456-426614174000"},
|
||||||
|
}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res.Total).To(BeEquivalentTo(int64(1)))
|
||||||
|
Expect(res.Docs[0].ID).To(BeEquivalentTo("resource:1"))
|
||||||
|
|
||||||
|
client.HSet(ctx, "test:1", map[string]interface{}{
|
||||||
|
"uuid": "3d3586fe-0416-4572-8ce",
|
||||||
|
"email": "adriano@acme.com.ie",
|
||||||
|
"num": 5,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Create the index
|
||||||
|
ftCreateOptions := &redis.FTCreateOptions{
|
||||||
|
Prefix: []interface{}{"test:"},
|
||||||
|
}
|
||||||
|
schema := []*redis.FieldSchema{
|
||||||
|
{
|
||||||
|
FieldName: "uuid",
|
||||||
|
FieldType: redis.SearchFieldTypeTag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
FieldName: "email",
|
||||||
|
FieldType: redis.SearchFieldTypeTag,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
FieldName: "num",
|
||||||
|
FieldType: redis.SearchFieldTypeNumeric,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
val, err = client.FTCreate(ctx, "idx_hash", ftCreateOptions, schema...).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(val).To(Equal("OK"))
|
||||||
|
|
||||||
|
ftSearchOptions := &redis.FTSearchOptions{
|
||||||
|
DialectVersion: 4,
|
||||||
|
Params: map[string]interface{}{
|
||||||
|
"uuid": "3d3586fe-0416-4572-8ce",
|
||||||
|
"email": "adriano@acme.com.ie",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err = client.FTSearchWithArgs(ctx, "idx_hash", "@uuid:{$uuid}", ftSearchOptions).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res.Docs[0].ID).To(BeEquivalentTo("test:1"))
|
||||||
|
Expect(res.Docs[0].Fields["uuid"]).To(BeEquivalentTo("3d3586fe-0416-4572-8ce"))
|
||||||
|
|
||||||
|
res, err = client.FTSearchWithArgs(ctx, "idx_hash", "@email:{$email}", ftSearchOptions).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res.Docs[0].ID).To(BeEquivalentTo("test:1"))
|
||||||
|
Expect(res.Docs[0].Fields["email"]).To(BeEquivalentTo("adriano@acme.com.ie"))
|
||||||
|
|
||||||
|
ftSearchOptions.Params = map[string]interface{}{"num": 5}
|
||||||
|
res, err = client.FTSearchWithArgs(ctx, "idx_hash", "@num:[5]", ftSearchOptions).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res.Docs[0].ID).To(BeEquivalentTo("test:1"))
|
||||||
|
Expect(res.Docs[0].Fields["num"]).To(BeEquivalentTo("5"))
|
||||||
|
})
|
||||||
|
|
||||||
It("should FTCreate GeoShape", Label("search", "ftcreate", "ftsearch"), func() {
|
It("should FTCreate GeoShape", Label("search", "ftcreate", "ftsearch"), func() {
|
||||||
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "geom", FieldType: redis.SearchFieldTypeGeoShape, GeoShapeFieldType: "FLAT"}).Result()
|
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "geom", FieldType: redis.SearchFieldTypeGeoShape, GeoShapeFieldType: "FLAT"}).Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
Loading…
Reference in New Issue