mirror of
https://github.com/redis/go-redis.git
synced 2025-04-17 20:17:02 +03:00
Enable dialect 2 on default (#3213)
* Enable dialect 2 on deafult * add vector test for default dialect * Add dialect 1 test * Add dialect 1 test & fix ft.search * Add default dialect to Readme
This commit is contained in:
parent
310ce55c59
commit
555a41ecc7
@ -209,6 +209,10 @@ res1, err := client.FTSearchWithArgs(ctx, "txt", "foo bar", &redis.FTSearchOptio
|
|||||||
val1 := client.FTSearchWithArgs(ctx, "txt", "foo bar", &redis.FTSearchOptions{}).RawVal()
|
val1 := client.FTSearchWithArgs(ctx, "txt", "foo bar", &redis.FTSearchOptions{}).RawVal()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Redis-Search Default Dialect
|
||||||
|
|
||||||
|
In the Redis-Search module, **the default dialect is 2**. If needed, you can explicitly specify a different dialect using the appropriate configuration in your queries.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!
|
Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!
|
||||||
|
@ -604,6 +604,8 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
|
|||||||
|
|
||||||
if options.DialectVersion > 0 {
|
if options.DialectVersion > 0 {
|
||||||
queryArgs = append(queryArgs, "DIALECT", options.DialectVersion)
|
queryArgs = append(queryArgs, "DIALECT", options.DialectVersion)
|
||||||
|
} else {
|
||||||
|
queryArgs = append(queryArgs, "DIALECT", 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return queryArgs
|
return queryArgs
|
||||||
@ -801,6 +803,8 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
|
|||||||
}
|
}
|
||||||
if options.DialectVersion > 0 {
|
if options.DialectVersion > 0 {
|
||||||
args = append(args, "DIALECT", options.DialectVersion)
|
args = append(args, "DIALECT", options.DialectVersion)
|
||||||
|
} else {
|
||||||
|
args = append(args, "DIALECT", 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1174,6 +1178,8 @@ func (c cmdable) FTExplainWithArgs(ctx context.Context, index string, query stri
|
|||||||
args := []interface{}{"FT.EXPLAIN", index, query}
|
args := []interface{}{"FT.EXPLAIN", index, query}
|
||||||
if options.Dialect != "" {
|
if options.Dialect != "" {
|
||||||
args = append(args, "DIALECT", options.Dialect)
|
args = append(args, "DIALECT", options.Dialect)
|
||||||
|
} else {
|
||||||
|
args = append(args, "DIALECT", 2)
|
||||||
}
|
}
|
||||||
cmd := NewStringCmd(ctx, args...)
|
cmd := NewStringCmd(ctx, args...)
|
||||||
_ = c(ctx, cmd)
|
_ = c(ctx, cmd)
|
||||||
@ -1471,6 +1477,8 @@ func (c cmdable) FTSpellCheckWithArgs(ctx context.Context, index string, query s
|
|||||||
}
|
}
|
||||||
if options.Dialect > 0 {
|
if options.Dialect > 0 {
|
||||||
args = append(args, "DIALECT", options.Dialect)
|
args = append(args, "DIALECT", options.Dialect)
|
||||||
|
} else {
|
||||||
|
args = append(args, "DIALECT", 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd := newFTSpellCheckCmd(ctx, args...)
|
cmd := newFTSpellCheckCmd(ctx, args...)
|
||||||
@ -1840,6 +1848,8 @@ func FTSearchQuery(query string, options *FTSearchOptions) SearchQuery {
|
|||||||
}
|
}
|
||||||
if options.DialectVersion > 0 {
|
if options.DialectVersion > 0 {
|
||||||
queryArgs = append(queryArgs, "DIALECT", options.DialectVersion)
|
queryArgs = append(queryArgs, "DIALECT", options.DialectVersion)
|
||||||
|
} else {
|
||||||
|
queryArgs = append(queryArgs, "DIALECT", 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return queryArgs
|
return queryArgs
|
||||||
@ -1955,6 +1965,8 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
|
|||||||
}
|
}
|
||||||
if options.DialectVersion > 0 {
|
if options.DialectVersion > 0 {
|
||||||
args = append(args, "DIALECT", options.DialectVersion)
|
args = append(args, "DIALECT", options.DialectVersion)
|
||||||
|
} else {
|
||||||
|
args = append(args, "DIALECT", 2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cmd := newFTSearchCmd(ctx, options, args...)
|
cmd := newFTSearchCmd(ctx, options, args...)
|
||||||
|
@ -1143,6 +1143,55 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
|
|||||||
Expect(res.Docs[0].Fields["__v_score"]).To(BeEquivalentTo("0"))
|
Expect(res.Docs[0].Fields["__v_score"]).To(BeEquivalentTo("0"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("should FTCreate VECTOR with dialect 1 ", Label("search", "ftcreate"), func() {
|
||||||
|
hnswOptions := &redis.FTHNSWOptions{Type: "FLOAT32", Dim: 2, DistanceMetric: "L2"}
|
||||||
|
val, err := client.FTCreate(ctx, "idx1",
|
||||||
|
&redis.FTCreateOptions{},
|
||||||
|
&redis.FieldSchema{FieldName: "v", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptions}}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(val).To(BeEquivalentTo("OK"))
|
||||||
|
WaitForIndexing(client, "idx1")
|
||||||
|
|
||||||
|
client.HSet(ctx, "a", "v", "aaaaaaaa")
|
||||||
|
client.HSet(ctx, "b", "v", "aaaabaaa")
|
||||||
|
client.HSet(ctx, "c", "v", "aaaaabaa")
|
||||||
|
|
||||||
|
searchOptions := &redis.FTSearchOptions{
|
||||||
|
Return: []redis.FTSearchReturn{{FieldName: "v"}},
|
||||||
|
SortBy: []redis.FTSearchSortBy{{FieldName: "v", Asc: true}},
|
||||||
|
Limit: 10,
|
||||||
|
DialectVersion: 1,
|
||||||
|
}
|
||||||
|
res, err := client.FTSearchWithArgs(ctx, "idx1", "*", searchOptions).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res.Docs[0].ID).To(BeEquivalentTo("a"))
|
||||||
|
Expect(res.Docs[0].Fields["v"]).To(BeEquivalentTo("aaaaaaaa"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should FTCreate VECTOR with default dialect", Label("search", "ftcreate"), func() {
|
||||||
|
hnswOptions := &redis.FTHNSWOptions{Type: "FLOAT32", Dim: 2, DistanceMetric: "L2"}
|
||||||
|
val, err := client.FTCreate(ctx, "idx1",
|
||||||
|
&redis.FTCreateOptions{},
|
||||||
|
&redis.FieldSchema{FieldName: "v", FieldType: redis.SearchFieldTypeVector, VectorArgs: &redis.FTVectorArgs{HNSWOptions: hnswOptions}}).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(val).To(BeEquivalentTo("OK"))
|
||||||
|
WaitForIndexing(client, "idx1")
|
||||||
|
|
||||||
|
client.HSet(ctx, "a", "v", "aaaaaaaa")
|
||||||
|
client.HSet(ctx, "b", "v", "aaaabaaa")
|
||||||
|
client.HSet(ctx, "c", "v", "aaaaabaa")
|
||||||
|
|
||||||
|
searchOptions := &redis.FTSearchOptions{
|
||||||
|
Return: []redis.FTSearchReturn{{FieldName: "__v_score"}},
|
||||||
|
SortBy: []redis.FTSearchSortBy{{FieldName: "__v_score", Asc: true}},
|
||||||
|
Params: map[string]interface{}{"vec": "aaaaaaaa"},
|
||||||
|
}
|
||||||
|
res, err := client.FTSearchWithArgs(ctx, "idx1", "*=>[KNN 2 @v $vec]", searchOptions).Result()
|
||||||
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Expect(res.Docs[0].ID).To(BeEquivalentTo("a"))
|
||||||
|
Expect(res.Docs[0].Fields["__v_score"]).To(BeEquivalentTo("0"))
|
||||||
|
})
|
||||||
|
|
||||||
It("should FTCreate and FTSearch text params", Label("search", "ftcreate", "ftsearch"), func() {
|
It("should FTCreate and FTSearch text params", Label("search", "ftcreate", "ftsearch"), func() {
|
||||||
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "name", FieldType: redis.SearchFieldTypeText}).Result()
|
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "name", FieldType: redis.SearchFieldTypeText}).Result()
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user