@@ -6,7 +6,9 @@ namespace NRedisStack.Search;
66public sealed class AggregationResult
77{
88 public long TotalResults { get ; }
9- private readonly Dictionary < string , RedisValue > [ ] _results ;
9+ private readonly Dictionary < string , object > [ ] _results ;
10+ private Dictionary < string , RedisValue > [ ] _resultsAsRedisValues ;
11+
1012 public long CursorId { get ; }
1113
1214
@@ -18,18 +20,23 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
1820 // // the first element is always the number of results
1921 // TotalResults = (long)arr[0];
2022
21- _results = new Dictionary < string , RedisValue > [ arr . Length - 1 ] ;
23+ _results = new Dictionary < string , object > [ arr . Length - 1 ] ;
2224 for ( int i = 1 ; i < arr . Length ; i ++ )
2325 {
2426 var raw = ( RedisResult [ ] ) arr [ i ] ! ;
25- var cur = new Dictionary < string , RedisValue > ( ) ;
27+ var cur = new Dictionary < string , object > ( ) ;
2628 for ( int j = 0 ; j < raw . Length ; )
2729 {
2830 var key = ( string ) raw [ j ++ ] ! ;
2931 var val = raw [ j ++ ] ;
3032 if ( val . Type == ResultType . MultiBulk )
31- continue ; // TODO: handle multi-bulk (maybe change to object?)
32- cur . Add ( key , ( RedisValue ) val ) ;
33+ {
34+ cur . Add ( key , ConvertMultiBulkToObject ( ( RedisResult [ ] ) val ! ) ) ;
35+ }
36+ else
37+ {
38+ cur . Add ( key , ( RedisValue ) val ) ;
39+ }
3340 }
3441
3542 _results [ i - 1 ] = cur ;
@@ -52,17 +59,47 @@ private object ConvertMultiBulkToObject(IEnumerable<RedisResult> multiBulkArray)
5259 {
5360 return multiBulkArray . Select ( item => item . Type == ResultType . MultiBulk
5461 ? ConvertMultiBulkToObject ( ( RedisResult [ ] ) item ! )
55- : item )
62+ : ( RedisValue ) item )
5663 . ToList ( ) ;
5764 }
5865
59- public IReadOnlyList < Dictionary < string , RedisValue > > GetResults ( ) => _results ;
66+ /// <summary>
67+ /// Gets the results as a read-only list of dictionaries with string keys and RedisValue values.
68+ /// </summary>
69+ /// <remarks>
70+ /// This method is deprecated and will be removed in future versions.
71+ /// Please use <see cref="GetRow"/> instead.
72+ /// </remarks>
73+ [ Obsolete ( "This method is deprecated and will be removed in future versions. Please use 'GetRow' instead." ) ]
74+ public IReadOnlyList < Dictionary < string , RedisValue > > GetResults ( )
75+ {
76+ return getResultsAsRedisValues ( ) ;
77+ }
6078
79+ /// <summary>
80+ /// Gets the aggregation result at the specified index.
81+ /// </summary>
82+ /// <param name="index">The zero-based index of the aggregation result to retrieve.</param>
83+ /// <returns>
84+ /// A dictionary containing the aggregation result as Redis values if the index is within bounds;
85+ /// otherwise, <c>null</c>.
86+ /// </returns>
87+ [ Obsolete ( "This method is deprecated and will be removed in future versions. Please use 'GetRow' instead." ) ]
6188 public Dictionary < string , RedisValue > ? this [ int index ]
62- => index >= _results . Length ? null : _results [ index ] ;
89+ => index >= getResultsAsRedisValues ( ) . Length ? null : getResultsAsRedisValues ( ) [ index ] ;
6390
6491 public Row GetRow ( int index )
6592 {
6693 return index >= _results . Length ? default : new Row ( _results [ index ] ) ;
6794 }
95+
96+ private Dictionary < string , RedisValue > [ ] getResultsAsRedisValues ( )
97+ {
98+ if ( _resultsAsRedisValues == null )
99+ _resultsAsRedisValues = _results . Select ( dict => dict . ToDictionary (
100+ kvp => kvp . Key ,
101+ kvp => kvp . Value is RedisValue value ? value : RedisValue . Null
102+ ) ) . ToArray ( ) ;
103+ return _resultsAsRedisValues ;
104+ }
68105}
0 commit comments