|
| 1 | +package redis_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "reflect" |
| 5 | + |
| 6 | + . "github.com/bsm/ginkgo/v2" |
| 7 | + . "github.com/bsm/gomega" |
| 8 | + "github.com/redis/go-redis/v9" |
| 9 | +) |
| 10 | + |
| 11 | +var _ = Describe("FTAggregateQuery", func() { |
| 12 | + It("returns only the base query when options is nil", func() { |
| 13 | + args := redis.FTAggregateQuery("testQuery", nil) |
| 14 | + Expect(args).To(Equal(redis.AggregateQuery{"testQuery"})) |
| 15 | + }) |
| 16 | + |
| 17 | + It("includes VERBATIM and SCORER when options are set", func() { |
| 18 | + options := &redis.FTAggregateOptions{ |
| 19 | + Verbatim: true, |
| 20 | + Scorer: "BM25", |
| 21 | + } |
| 22 | + args := redis.FTAggregateQuery("testQuery", options) |
| 23 | + Expect(args[0]).To(Equal("testQuery")) |
| 24 | + Expect(args).To(ContainElement("VERBATIM")) |
| 25 | + Expect(args).To(ContainElement("SCORER")) |
| 26 | + Expect(args).To(ContainElement("BM25")) |
| 27 | + }) |
| 28 | + |
| 29 | + It("includes ADDSCORES when AddScores is true", func() { |
| 30 | + options := &redis.FTAggregateOptions{ |
| 31 | + AddScores: true, |
| 32 | + } |
| 33 | + args := redis.FTAggregateQuery("q", options) |
| 34 | + Expect(args).To(ContainElement("ADDSCORES")) |
| 35 | + }) |
| 36 | + |
| 37 | + It("includes LOADALL when LoadAll is true", func() { |
| 38 | + options := &redis.FTAggregateOptions{ |
| 39 | + LoadAll: true, |
| 40 | + } |
| 41 | + args := redis.FTAggregateQuery("q", options) |
| 42 | + Expect(args).To(ContainElement("LOAD")) |
| 43 | + Expect(args).To(ContainElement("*")) |
| 44 | + }) |
| 45 | + |
| 46 | + It("includes LOAD when Load is provided", func() { |
| 47 | + options := &redis.FTAggregateOptions{ |
| 48 | + Load: []redis.FTAggregateLoad{ |
| 49 | + {Field: "field1", As: "alias1"}, |
| 50 | + {Field: "field2"}, |
| 51 | + }, |
| 52 | + } |
| 53 | + args := redis.FTAggregateQuery("q", options) |
| 54 | + // Verify LOAD options related arguments |
| 55 | + Expect(args).To(ContainElement("LOAD")) |
| 56 | + // Check that field names and aliases are present |
| 57 | + Expect(args).To(ContainElement("field1")) |
| 58 | + Expect(args).To(ContainElement("alias1")) |
| 59 | + Expect(args).To(ContainElement("field2")) |
| 60 | + }) |
| 61 | + |
| 62 | + It("includes TIMEOUT when Timeout > 0", func() { |
| 63 | + options := &redis.FTAggregateOptions{ |
| 64 | + Timeout: 500, |
| 65 | + } |
| 66 | + args := redis.FTAggregateQuery("q", options) |
| 67 | + Expect(args).To(ContainElement("TIMEOUT")) |
| 68 | + found := false |
| 69 | + for _, a := range args { |
| 70 | + if reflect.DeepEqual(a, 500) { |
| 71 | + found = true |
| 72 | + break |
| 73 | + } |
| 74 | + } |
| 75 | + Expect(found).To(BeTrue()) |
| 76 | + }) |
| 77 | +}) |
0 commit comments