@@ -6,7 +6,9 @@ namespace NRedisStack.Search;
6
6
public sealed class AggregationResult
7
7
{
8
8
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
+
10
12
public long CursorId { get ; }
11
13
12
14
@@ -18,18 +20,23 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
18
20
// // the first element is always the number of results
19
21
// TotalResults = (long)arr[0];
20
22
21
- _results = new Dictionary < string , RedisValue > [ arr . Length - 1 ] ;
23
+ _results = new Dictionary < string , object > [ arr . Length - 1 ] ;
22
24
for ( int i = 1 ; i < arr . Length ; i ++ )
23
25
{
24
26
var raw = ( RedisResult [ ] ) arr [ i ] ! ;
25
- var cur = new Dictionary < string , RedisValue > ( ) ;
27
+ var cur = new Dictionary < string , object > ( ) ;
26
28
for ( int j = 0 ; j < raw . Length ; )
27
29
{
28
30
var key = ( string ) raw [ j ++ ] ! ;
29
31
var val = raw [ j ++ ] ;
30
32
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
+ }
33
40
}
34
41
35
42
_results [ i - 1 ] = cur ;
@@ -52,17 +59,47 @@ private object ConvertMultiBulkToObject(IEnumerable<RedisResult> multiBulkArray)
52
59
{
53
60
return multiBulkArray . Select ( item => item . Type == ResultType . MultiBulk
54
61
? ConvertMultiBulkToObject ( ( RedisResult [ ] ) item ! )
55
- : item )
62
+ : ( RedisValue ) item )
56
63
. ToList ( ) ;
57
64
}
58
65
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
+ }
60
78
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." ) ]
61
88
public Dictionary < string , RedisValue > ? this [ int index ]
62
- => index >= _results . Length ? null : _results [ index ] ;
89
+ => index >= getResultsAsRedisValues ( ) . Length ? null : getResultsAsRedisValues ( ) [ index ] ;
63
90
64
91
public Row GetRow ( int index )
65
92
{
66
93
return index >= _results . Length ? default : new Row ( _results [ index ] ) ;
67
94
}
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
+ }
68
105
}
0 commit comments