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

fix(search&aggregate):fix error overwrite and typo #3220 #3224

Open
wants to merge 2 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
18 changes: 4 additions & 14 deletions search_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ type FTAggregateApply struct {

type FTAggregateLoad struct {
Field string
As string
}

type FTAggregateWithCursor struct {
Expand Down Expand Up @@ -493,9 +492,6 @@ func FTAggregateQuery(query string, options *FTAggregateOptions) AggregateQuery
queryArgs = append(queryArgs, "LOAD", len(options.Load))
for _, load := range options.Load {
queryArgs = append(queryArgs, load.Field)
if load.As != "" {
queryArgs = append(queryArgs, "AS", load.As)
}
}
}
if options.Timeout > 0 {
Expand Down Expand Up @@ -653,8 +649,7 @@ func (cmd *AggregateCmd) String() string {
func (cmd *AggregateCmd) readReply(rd *proto.Reader) (err error) {
data, err := rd.ReadSlice()
if err != nil {
cmd.err = err
return nil
return err
}
cmd.val, err = ProcessAggregateResult(data)
if err != nil {
Expand Down Expand Up @@ -684,9 +679,6 @@ func (c cmdable) FTAggregateWithArgs(ctx context.Context, index string, query st
args = append(args, "LOAD", len(options.Load))
for _, load := range options.Load {
args = append(args, load.Field)
if load.As != "" {
args = append(args, "AS", load.As)
}
}
}
if options.Timeout > 0 {
Expand Down Expand Up @@ -1473,8 +1465,7 @@ func (cmd *FTSpellCheckCmd) RawResult() (interface{}, error) {
func (cmd *FTSpellCheckCmd) readReply(rd *proto.Reader) (err error) {
data, err := rd.ReadSlice()
if err != nil {
cmd.err = err
return nil
return err
}
cmd.val, err = parseFTSpellCheck(data)
if err != nil {
Expand Down Expand Up @@ -1662,8 +1653,7 @@ func (cmd *FTSearchCmd) RawResult() (interface{}, error) {
func (cmd *FTSearchCmd) readReply(rd *proto.Reader) (err error) {
data, err := rd.ReadSlice()
if err != nil {
cmd.err = err
return nil
return err
}
cmd.val, err = parseFTSearch(data, cmd.options.NoContent, cmd.options.WithScores, cmd.options.WithPayloads, cmd.options.WithSortKeys)
if err != nil {
Expand Down Expand Up @@ -1889,7 +1879,7 @@ func (c cmdable) FTSearchWithArgs(ctx context.Context, index string, query strin
}
}
if options.SortByWithCount {
args = append(args, "WITHCOUT")
args = append(args, "WITHCOUNT")
}
}
if options.LimitOffset >= 0 && options.Limit > 0 {
Expand Down
12 changes: 10 additions & 2 deletions search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {

res3, err := client.FTSearchWithArgs(ctx, "num", "foo", &redis.FTSearchOptions{NoContent: true, SortBy: []redis.FTSearchSortBy{sortBy2}, SortByWithCount: true}).Result()
Expect(err).NotTo(HaveOccurred())
Expect(res3.Total).To(BeEquivalentTo(int64(0)))

Expect(res3.Total).To(BeEquivalentTo(int64(3)))
Expect(res2.Docs[2].ID).To(BeEquivalentTo("doc1"))
Expect(res2.Docs[1].ID).To(BeEquivalentTo("doc2"))
Expect(res2.Docs[0].ID).To(BeEquivalentTo("doc3"))
})

It("should FTCreate and FTSearch example", Label("search", "ftcreate", "ftsearch"), func() {
Expand Down Expand Up @@ -264,6 +266,8 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
Expect(err).NotTo(HaveOccurred())
Expect(res1.Total).To(BeEquivalentTo(int64(1)))

_, err = client.FTSearch(ctx, "idx_not_exist", "only in the body").Result()
Expect(err).To(HaveOccurred())
})

It("should FTSpellCheck", Label("search", "ftcreate", "ftsearch", "ftspellcheck"), func() {
Expand Down Expand Up @@ -592,6 +596,9 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
Expect(err).NotTo(HaveOccurred())
Expect(res.Rows[0].Fields["t1"]).To(BeEquivalentTo("hello"))
Expect(res.Rows[0].Fields["t2"]).To(BeEquivalentTo("world"))

_, err = client.FTAggregateWithArgs(ctx, "idx_not_exist", "*", &redis.FTAggregateOptions{}).Result()
Expect(err).To(HaveOccurred())
})

It("should FTAggregate apply", Label("search", "ftaggregate"), func() {
Expand Down Expand Up @@ -1101,6 +1108,7 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
val, err = client.FTCreate(ctx, "idx_hash", ftCreateOptions, schema...).Result()
Expect(err).NotTo(HaveOccurred())
Expect(val).To(Equal("OK"))
WaitForIndexing(client, "idx_hash")

ftSearchOptions := &redis.FTSearchOptions{
DialectVersion: 4,
Expand Down
Loading