Skip to content

Commit e0adc1f

Browse files
fix filter aggregation for string type on the right side (#328)
1 parent 9c45dc7 commit e0adc1f

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ We'd love your contributions! If you want to contribute please read our [Contrib
361361
* [@mariusmuntean](https://github.com/mariusmuntean)
362362
* [@jcreus1](https://github.com/jcreus1)
363363
* [@JuliusMikkela](https://github.com/JuliusMikkela)
364+
* [@imansafari1991](https://github.com/imansafari1991)
364365

365366
<!-- Logo -->
366367
[Logo]: images/logo.svg

src/Redis.OM/Common/ExpressionParserUtilities.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ internal static string ParseBinaryExpression(BinaryExpression rootBinaryExpressi
121121
{
122122
var right = GetOperandString(expression.Right);
123123
var left = GetOperandString(expression.Left);
124-
125-
if (filterFormat && expression.Left is MemberExpression mem &&
126-
mem.Type == typeof(string))
124+
if (filterFormat && ((expression.Left is MemberExpression mem &&
125+
mem.Type == typeof(string)) || (expression.Left is UnaryExpression uni &&
126+
uni.Type == typeof(string))))
127127
{
128128
right = $"'{right}'";
129129
}

test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,17 @@ public void TestMultipleOrderBys()
387387
_mock.Verify(x=>x.Execute("FT.AGGREGATE","person-idx", "*", "SORTBY", "4", "@Name", "ASC", "@Age", "DESC", "WITHCURSOR", "COUNT", "10000"));
388388
}
389389

390+
[Fact]
391+
public void TestRightSideStringTypeFilter()
392+
{
393+
var collection = new RedisAggregationSet<Person>(_mock.Object, true, chunkSize: 10000);
394+
_mock.Setup(x => x.Execute("FT.AGGREGATE", It.IsAny<string[]>())).Returns(MockedResult);
395+
_mock.Setup(x => x.Execute("FT.CURSOR", It.IsAny<string[]>())).Returns(MockedResultCursorEnd);
396+
_ = collection.Apply(x => string.Format("{0} {1}", x.RecordShell.FirstName, x.RecordShell.LastName),
397+
"FullName").Filter(p => p.Aggregations["FullName"] == "Bruce Wayne").ToList();
398+
_mock.Verify(x => x.Execute("FT.AGGREGATE", "person-idx", "*", "APPLY", "format(\"%s %s\",@FirstName,@LastName)", "AS", "FullName", "FILTER", "@FullName == 'Bruce Wayne'", "WITHCURSOR", "COUNT", "10000"));
399+
}
400+
390401
[Fact]
391402
public void TestNestedOrderBy()
392403
{

test/Redis.OM.Unit.Tests/RediSearchTests/Person.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,10 @@ public partial class Person
6666

6767
[Indexed]
6868
public string? NullableStringField { get; set; }
69+
70+
[Indexed(Aggregatable = true)] public string FirstName { get; set; }
71+
[Indexed(Aggregatable = true)] public string LastName { get; set; }
72+
73+
6974
}
7075
}

0 commit comments

Comments
 (0)