Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dialect 2 on default #3213

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions search_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
}
if options.DialectVersion > 0 {
queryArgs = append(queryArgs, "DIALECT", options.DialectVersion)
} else {
queryArgs = append(queryArgs, "DIALECT", 2)
}
}
return queryArgs
Expand Down Expand Up @@ -767,6 +769,8 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
}
if options.DialectVersion > 0 {
args = append(args, "DIALECT", options.DialectVersion)
} else {
args = append(args, "DIALECT", 2)
}
}

Expand Down Expand Up @@ -1128,6 +1132,8 @@ func (c cmdable) FTExplainWithArgs(ctx context.Context, index string, query stri
args := []interface{}{"FT.EXPLAIN", index, query}
if options.Dialect != "" {
args = append(args, "DIALECT", options.Dialect)
} else {
args = append(args, "DIALECT", 2)
}
cmd := NewStringCmd(ctx, args...)
_ = c(ctx, cmd)
Expand Down Expand Up @@ -1425,6 +1431,8 @@ func (c cmdable) FTSpellCheckWithArgs(ctx context.Context, index string, query s
}
if options.Dialect > 0 {
args = append(args, "DIALECT", options.Dialect)
} else {
args = append(args, "DIALECT", 2)
}
}
cmd := newFTSpellCheckCmd(ctx, args...)
Expand Down Expand Up @@ -1789,6 +1797,8 @@ func FTSearchQuery(query string, options *FTSearchOptions) SearchQuery {
}
if options.DialectVersion > 0 {
queryArgs = append(queryArgs, "DIALECT", options.DialectVersion)
} else {
queryArgs = append(queryArgs, "DIALECT", 2)
}
}
return queryArgs
Expand Down Expand Up @@ -1903,6 +1913,8 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
}
if options.DialectVersion > 0 {
args = append(args, "DIALECT", options.DialectVersion)
} else {
args = append(args, "DIALECT", 2)
}
}
cmd := newFTSearchCmd(ctx, options, args...)
Expand Down
24 changes: 24 additions & 0 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,30 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
Expect(res.Docs[0].Fields["__v_score"]).To(BeEquivalentTo("0"))
})

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() {
val, err := client.FTCreate(ctx, "idx1", &redis.FTCreateOptions{}, &redis.FieldSchema{FieldName: "name", FieldType: redis.SearchFieldTypeText}).Result()
Expect(err).NotTo(HaveOccurred())
Expand Down
Loading