Skip to content

Commit d325e32

Browse files
committed
handle ft.profile response processing with "ProfilingInformation"
1 parent f63bf4a commit d325e32

File tree

8 files changed

+192
-50
lines changed

8 files changed

+192
-50
lines changed

src/NRedisStack/ResponseParser.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,26 +685,26 @@ public static Dictionary<string, RedisResult> ToStringRedisResultDictionary(this
685685
return dict;
686686
}
687687

688-
public static Tuple<SearchResult, Dictionary<string, RedisResult>> ToProfileSearchResult(this RedisResult result, Query q)
688+
public static Tuple<SearchResult, ProfilingInformation> ToProfileSearchResult(this RedisResult result, Query q)
689689
{
690690
var results = (RedisResult[])result!;
691691

692692
var searchResult = results[0].ToSearchResult(q);
693-
var profile = results[1].ToStringRedisResultDictionary();
694-
return new Tuple<SearchResult, Dictionary<string, RedisResult>>(searchResult, profile);
693+
var profile = new ProfilingInformation(results[1]);
694+
return new Tuple<SearchResult, ProfilingInformation>(searchResult, profile);
695695
}
696696

697697
public static SearchResult ToSearchResult(this RedisResult result, Query q)
698698
{
699699
return new SearchResult((RedisResult[])result!, !q.NoContent, q.WithScores, q.WithPayloads/*, q.ExplainScore*/);
700700
}
701701

702-
public static Tuple<AggregationResult, Dictionary<string, RedisResult>> ToProfileAggregateResult(this RedisResult result, AggregationRequest q)
702+
public static Tuple<AggregationResult, ProfilingInformation> ToProfileAggregateResult(this RedisResult result, AggregationRequest q)
703703
{
704704
var results = (RedisResult[])result!;
705705
var aggregateResult = results[0].ToAggregationResult(q);
706-
var profile = results[1].ToStringRedisResultDictionary();
707-
return new Tuple<AggregationResult, Dictionary<string, RedisResult>>(aggregateResult, profile);
706+
var profile = new ProfilingInformation(results[1]);
707+
return new Tuple<AggregationResult, ProfilingInformation>(aggregateResult, profile);
708708
}
709709

710710
public static AggregationResult ToAggregationResult(this RedisResult result, AggregationRequest query)

src/NRedisStack/Search/ISearchCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public interface ISearchCommands
177177
/// <param name="q">The query string.</param>
178178
/// <param name="limited">Removes details of reader iterator.</param>
179179
/// <returns></returns>
180-
Tuple<SearchResult, Dictionary<string, RedisResult>> ProfileSearch(string indexName, Query q, bool limited = false);
180+
Tuple<SearchResult, ProfilingInformation> ProfileSearch(string indexName, Query q, bool limited = false);
181181

182182
/// <summary>
183183
/// Apply FT.AGGREGATE command to collect performance details.
@@ -186,7 +186,7 @@ public interface ISearchCommands
186186
/// <param name="query">The query string.</param>
187187
/// <param name="limited">Removes details of reader iterator.</param>
188188
/// <returns></returns>
189-
Tuple<AggregationResult, Dictionary<string, RedisResult>> ProfileAggregate(string indexName, AggregationRequest query, bool limited = false);
189+
Tuple<AggregationResult, ProfilingInformation> ProfileAggregate(string indexName, AggregationRequest query, bool limited = false);
190190

191191
/// <summary>
192192
/// Search the index

src/NRedisStack/Search/ISearchCommandsAsync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public interface ISearchCommandsAsync
177177
/// <param name="q">The query string.</param>
178178
/// <param name="limited">Removes details of reader iterator.</param>
179179
/// <returns></returns>
180-
Task<Tuple<SearchResult, Dictionary<string, RedisResult>>> ProfileSearchAsync(string indexName, Query q, bool limited = false);
180+
Task<Tuple<SearchResult, ProfilingInformation>> ProfileSearchAsync(string indexName, Query q, bool limited = false);
181181

182182

183183
/// <summary>
@@ -187,7 +187,7 @@ public interface ISearchCommandsAsync
187187
/// <param name="query">The query string.</param>
188188
/// <param name="limited">Removes details of reader iterator.</param>
189189
/// <returns></returns>
190-
Task<Tuple<AggregationResult, Dictionary<string, RedisResult>>> ProfileAggregateAsync(string indexName, AggregationRequest query, bool limited = false);
190+
Task<Tuple<AggregationResult, ProfilingInformation>> ProfileAggregateAsync(string indexName, AggregationRequest query, bool limited = false);
191191

192192
/// <summary>
193193
/// Search the index
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using StackExchange.Redis;
2+
3+
namespace NRedisStack.Search
4+
{
5+
6+
public class ProfilingInformation
7+
{
8+
public RedisResult Info { get; private set; }
9+
public ProfilingInformation(RedisResult info)
10+
{
11+
this.Info = info;
12+
}
13+
14+
}
15+
}

src/NRedisStack/Search/SearchCommands.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ public InfoResult Info(RedisValue index) =>
131131
new InfoResult(_db.Execute(SearchCommandBuilder.Info(index)));
132132

133133
/// <inheritdoc/>
134-
public Tuple<SearchResult, Dictionary<string, RedisResult>> ProfileSearch(string indexName, Query q, bool limited = false)
134+
public Tuple<SearchResult, ProfilingInformation> ProfileSearch(string indexName, Query q, bool limited = false)
135135
{
136136
return _db.Execute(SearchCommandBuilder.ProfileSearch(indexName, q, limited))
137137
.ToProfileSearchResult(q);
138138
}
139139
/// <inheritdoc/>
140-
public Tuple<AggregationResult, Dictionary<string, RedisResult>> ProfileAggregate(string indexName, AggregationRequest query, bool limited = false)
140+
public Tuple<AggregationResult, ProfilingInformation> ProfileAggregate(string indexName, AggregationRequest query, bool limited = false)
141141
{
142142
setDefaultDialectIfUnset(query);
143143
return _db.Execute(SearchCommandBuilder.ProfileAggregate(indexName, query, limited))

src/NRedisStack/Search/SearchCommandsAsync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ public async Task<InfoResult> InfoAsync(RedisValue index) =>
162162
new InfoResult(await _db.ExecuteAsync(SearchCommandBuilder.Info(index)));
163163

164164
/// <inheritdoc/>
165-
public async Task<Tuple<SearchResult, Dictionary<string, RedisResult>>> ProfileSearchAsync(string indexName, Query q, bool limited = false)
165+
public async Task<Tuple<SearchResult, ProfilingInformation>> ProfileSearchAsync(string indexName, Query q, bool limited = false)
166166
{
167167
return (await _db.ExecuteAsync(SearchCommandBuilder.ProfileSearch(indexName, q, limited)))
168168
.ToProfileSearchResult(q);
169169
}
170170
/// <inheritdoc/>
171-
public async Task<Tuple<AggregationResult, Dictionary<string, RedisResult>>> ProfileAggregateAsync(string indexName, AggregationRequest query, bool limited = false)
171+
public async Task<Tuple<AggregationResult, ProfilingInformation>> ProfileAggregateAsync(string indexName, AggregationRequest query, bool limited = false)
172172
{
173173
return (await _db.ExecuteAsync(SearchCommandBuilder.ProfileAggregate(indexName, query, limited)))
174174
.ToProfileAggregateResult(query);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Xunit;
2+
3+
namespace NRedisStack.Tests;
4+
5+
public static class CustomAssertions
6+
{
7+
// Generic method to assert that 'actual' is greater than 'expected'
8+
public static void GreaterThan<T>(T actual, T expected) where T : IComparable<T>
9+
{
10+
Assert.True(actual.CompareTo(expected) > 0,
11+
$"Failure: Expected value to be greater than {expected}, but found {actual}.");
12+
}
13+
14+
// Generic method to assert that 'actual' is less than 'expected'
15+
public static void LessThan<T>(T actual, T expected) where T : IComparable<T>
16+
{
17+
Assert.True(actual.CompareTo(expected) < 0,
18+
$"Failure: Expected value to be less than {expected}, but found {actual}.");
19+
}
20+
}

0 commit comments

Comments
 (0)