Skip to content

Commit 5689e5f

Browse files
authored
fix parser for new reponse in FT.PROFILE #306 (#307)
* fix parser for new reponse in FT.PROFILE #306 * version guards for ft.profile integration tests * disable redisgraph and add sortable to index schema
1 parent 2d5babb commit 5689e5f

File tree

4 files changed

+77
-10
lines changed

4 files changed

+77
-10
lines changed

.github/dockers/cluster.redis.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
protected-mode no
22
enable-debug-command yes
33
loadmodule /opt/redis-stack/lib/redisearch.so
4-
loadmodule /opt/redis-stack/lib/redisgraph.so
4+
# loadmodule /opt/redis-stack/lib/redisgraph.so
55
loadmodule /opt/redis-stack/lib/redistimeseries.so
66
loadmodule /opt/redis-stack/lib/rejson.so
77
loadmodule /opt/redis-stack/lib/redisbloom.so

src/NRedisStack/ResponseParser.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,14 @@ public static Dictionary<string, RedisResult> ToStringRedisResultDictionary(this
673673
foreach (var pair in res)
674674
{
675675
var arr = (RedisResult[])pair!;
676-
dict.Add(arr[0].ToString()!, arr[1]);
676+
if (arr.Length > 1)
677+
{
678+
dict.Add(arr[0].ToString()!, arr[1]);
679+
}
680+
else
681+
{
682+
dict.Add(arr[0].ToString()!, null);
683+
}
677684
}
678685
return dict;
679686
}

src/NRedisStack/Search/AggregationResult.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
1414
{
1515
var arr = (RedisResult[])result!;
1616

17-
// the first element is always the number of results
18-
TotalResults = (long)arr[0];
17+
// this statement below is not true as explained in the document https://redis.io/docs/latest/commands/ft.aggregate/#return
18+
// // the first element is always the number of results
19+
// TotalResults = (long)arr[0];
1920

2021
_results = new Dictionary<string, RedisValue>[arr.Length - 1];
2122
for (int i = 1; i < arr.Length; i++)
@@ -33,7 +34,7 @@ internal AggregationResult(RedisResult result, long cursorId = -1)
3334

3435
_results[i - 1] = cur;
3536
}
36-
37+
TotalResults = _results.Length;
3738
CursorId = cursorId;
3839
}
3940

tests/NRedisStack.Tests/Search/SearchTests.cs

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public void TestApplyAndFilterAggregations()
507507

508508
// actual search
509509
AggregationResult res = ft.Aggregate(index, r);
510-
Assert.Equal(3, res.TotalResults);
510+
Assert.Equal(2, res.TotalResults);
511511

512512
Row r1 = res.GetRow(0);
513513
Assert.Equal("def", r1.GetString("name"));
@@ -2668,7 +2668,7 @@ public async Task TestProfileSearchAsync()
26682668
}
26692669

26702670

2671-
[SkipIfRedis(Is.Enterprise)]
2671+
[SkipIfRedis(Is.Enterprise, Comparison.GreaterThanOrEqual, "7.3.240")]
26722672
public void TestProfile()
26732673
{
26742674
IDatabase db = redisFixture.Redis.GetDatabase();
@@ -2695,10 +2695,10 @@ public void TestProfile()
26952695
var aggregateRes = profileAggregate.Item1;
26962696
var aggregateDet = profileAggregate.Item2;
26972697
Assert.Equal(5, aggregateDet.Count);
2698-
Assert.Equal(1, aggregateRes.TotalResults);
2698+
Assert.Equal(2, aggregateRes.TotalResults);
26992699
}
27002700

2701-
[SkipIfRedis(Is.Enterprise)]
2701+
[SkipIfRedis(Is.Enterprise, Comparison.GreaterThanOrEqual, "7.3.240")]
27022702
public async Task TestProfileAsync()
27032703
{
27042704
IDatabase db = redisFixture.Redis.GetDatabase();
@@ -2724,7 +2724,66 @@ public async Task TestProfileAsync()
27242724
var aggregateRes = profileAggregate.Item1;
27252725
var aggregateDet = profileAggregate.Item2;
27262726
Assert.Equal(5, aggregateDet.Count);
2727-
Assert.Equal(1, aggregateRes.TotalResults);
2727+
Assert.Equal(2, aggregateRes.TotalResults);
2728+
}
2729+
2730+
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
2731+
public void TestProfileIssue306()
2732+
{
2733+
IDatabase db = redisFixture.Redis.GetDatabase();
2734+
db.Execute("FLUSHALL");
2735+
var ft = db.FT();
2736+
2737+
ft.Create(index, new Schema().AddTextField("t", sortable: true)); // Calling FT.CREATR without FTCreateParams
2738+
db.HashSet("1", "t", "hello");
2739+
db.HashSet("2", "t", "world");
2740+
2741+
// check using Query
2742+
var q = new Query("hello|world").SetNoContent();
2743+
var profileSearch = ft.ProfileSearch(index, q);
2744+
var searchRes = profileSearch.Item1;
2745+
var searchDet = profileSearch.Item2;
2746+
2747+
Assert.Equal(6, searchDet.Count);
2748+
Assert.Equal(2, searchRes.Documents.Count);
2749+
2750+
2751+
// check using AggregationRequest
2752+
var aggReq = new AggregationRequest("*").Load(FieldName.Of("t")).Apply("startswith(@t, 'hel')", "prefix");
2753+
var profileAggregate = ft.ProfileAggregate(index, aggReq);
2754+
var aggregateRes = profileAggregate.Item1;
2755+
var aggregateDet = profileAggregate.Item2;
2756+
Assert.True(aggregateDet.Count >= 6);
2757+
Assert.Equal(2, aggregateRes.TotalResults);
2758+
}
2759+
2760+
[SkipIfRedis(Is.Enterprise, Comparison.LessThan, "7.3.240")]
2761+
public async Task TestProfileAsyncIssue306()
2762+
{
2763+
IDatabase db = redisFixture.Redis.GetDatabase();
2764+
db.Execute("FLUSHALL");
2765+
var ft = db.FT();
2766+
2767+
await ft.CreateAsync(index, new Schema().AddTextField("t", sortable: true)); // Calling FT.CREATR without FTCreateParams
2768+
db.HashSet("1", "t", "hello");
2769+
db.HashSet("2", "t", "world");
2770+
2771+
// check using Query
2772+
var q = new Query("hello|world").SetNoContent();
2773+
var profileSearch = await ft.ProfileSearchAsync(index, q);
2774+
var searchRes = profileSearch.Item1;
2775+
var searchDet = profileSearch.Item2;
2776+
2777+
Assert.Equal(6, searchDet.Count);
2778+
Assert.Equal(2, searchRes.Documents.Count);
2779+
2780+
// check using AggregationRequest
2781+
var aggReq = new AggregationRequest("*").Load(FieldName.Of("t")).Apply("startswith(@t, 'hel')", "prefix");
2782+
var profileAggregate = await ft.ProfileAggregateAsync(index, aggReq);
2783+
var aggregateRes = profileAggregate.Item1;
2784+
var aggregateDet = profileAggregate.Item2;
2785+
Assert.True(aggregateDet.Count >= 6);
2786+
Assert.Equal(2, aggregateRes.TotalResults);
27282787
}
27292788

27302789
[Fact]

0 commit comments

Comments
 (0)