Skip to content

Commit 064c83f

Browse files
committed
improve test
1 parent 28e79aa commit 064c83f

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

search_test.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -655,14 +655,26 @@ var _ = Describe("RediSearch commands Resp 2", Label("search"), func() {
655655
client.HSet(ctx, "doc2", "PrimaryKey", "9::362329", "CreatedDateTimeUTC", "1739342399")
656656
client.HSet(ctx, "doc3", "PrimaryKey", "9::362329", "CreatedDateTimeUTC", "1739353199")
657657

658-
reducer := redis.FTAggregateReducer{Reducer: redis.SearchCount}
658+
reducer := redis.FTAggregateReducer{Reducer: redis.SearchCount, As: "perDay"}
659659

660660
options := &redis.FTAggregateOptions{
661-
Apply: []redis.FTAggregateApply{{Field: "@CreatedDateTimeUTC /(60*60*24)", As: "TimestampAsDay"}},
662-
GroupBy: []redis.FTAggregateGroupBy{{Fields: []interface{}{"@TimestampAsDay"}, Reduce: []redis.FTAggregateReducer{reducer}}},
661+
Apply: []redis.FTAggregateApply{{Field: "floor(@CreatedDateTimeUTC /(60*60*24))", As: "TimestampAsDay"}},
662+
GroupBy: []redis.FTAggregateGroupBy{{
663+
Fields: []interface{}{"@TimestampAsDay"},
664+
Reduce: []redis.FTAggregateReducer{reducer},
665+
}},
666+
SortBy: []redis.FTAggregateSortBy{{
667+
FieldName: "@perDay",
668+
Desc: true,
669+
}},
663670
}
671+
664672
res, err := client.FTAggregateWithArgs(ctx, "idx1", "*", options).Result()
665673
Expect(err).NotTo(HaveOccurred())
674+
Expect(res).ToNot(BeNil())
675+
Expect(len(res.Rows)).To(BeEquivalentTo(2))
676+
Expect(res.Rows[0].Fields["perDay"]).To(BeEquivalentTo("2"))
677+
Expect(res.Rows[1].Fields["perDay"]).To(BeEquivalentTo("1"))
666678
})
667679

668680
It("should FTAggregate apply", Label("search", "ftaggregate"), func() {

0 commit comments

Comments
 (0)