private static async Task <List <T> > ToListWithMultipleSortAsync <T>(this Client client, string whereQuery, int skip, int take, List <RedisearchSortDescriptor> sorts) where T : class, new() { PropertyInfo[] props = Helpers.GetModelProperties <T>().Where(x => x.GetSetMethod() != null).ToArray(); SortedField[] sort = sorts.Select(x => new SortedField($"@{x.PropertyName}", x.Ascending ? Order.Ascending : Order.Descending)) .ToArray(); string[] returnFields = props.Select(x => x.Name).ToArray(); AggregationBuilder aggregation = new AggregationBuilder(whereQuery).Load(returnFields) .SortBy(sort) .Limit(skip, take); AggregationResult aggreagate = await client.AggregateAsync(aggregation); IReadOnlyList <Dictionary <string, RedisValue> > aggregationResult = aggreagate.GetResults(); return(aggregationResult.Select(x => SerializeProperties <T>(props, x.ToList())) .ToList()); }
public void TestGetTagFieldUnf() { // Add version check Client cl = GetClient(); // Check that UNF can't be given to non-sortable filed try { var temp = new Schema().AddField(new TextField("non-sortable-unf", 1.0, sortable: false, unNormalizedForm: true)); Assert.True(false); } catch (ArgumentException) { Assert.True(true); } Schema sc = new Schema().AddSortableTextField("txt").AddSortableTextField("txt_unf", unf: true). AddSortableTagField("tag").AddSortableTagField("tag_unf", unNormalizedForm: true); Assert.True(cl.CreateIndex(sc, new ConfiguredIndexOptions())); Db.Execute("HSET", "doc1", "txt", "FOO", "txt_unf", "FOO", "tag", "FOO", "tag_unf", "FOO"); AggregationBuilder r = new AggregationBuilder() .GroupBy(new List <string> { "@txt", "@txt_unf", "@tag", "@tag_unf" }, new List <Aggregation.Reducers.Reducer> { }); AggregationResult res = cl.Aggregate(r); var results = res.GetResults()[0]; Assert.NotNull(results); Assert.Equal(4, results.Count); Assert.Equal("foo", results["txt"]); Assert.Equal("FOO", results["txt_unf"]); Assert.Equal("foo", results["tag"]); Assert.Equal("FOO", results["tag_unf"]); }