Skip to content

fix filter aggregation for string type on the right side #328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ We'd love your contributions! If you want to contribute please read our [Contrib
* [@mariusmuntean](https://github.com/mariusmuntean)
* [@jcreus1](https://github.com/jcreus1)
* [@JuliusMikkela](https://github.com/JuliusMikkela)
* [@imansafari1991](https://github.com/imansafari1991)

<!-- Logo -->
[Logo]: images/logo.svg
Expand Down
6 changes: 3 additions & 3 deletions src/Redis.OM/Common/ExpressionParserUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ internal static string ParseBinaryExpression(BinaryExpression rootBinaryExpressi
{
var right = GetOperandString(expression.Right);
var left = GetOperandString(expression.Left);

if (filterFormat && expression.Left is MemberExpression mem &&
mem.Type == typeof(string))
if (filterFormat && ((expression.Left is MemberExpression mem &&
mem.Type == typeof(string)) || (expression.Left is UnaryExpression uni &&
uni.Type == typeof(string))))
{
right = $"'{right}'";
}
Expand Down
11 changes: 11 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,17 @@ public void TestMultipleOrderBys()
_mock.Verify(x=>x.Execute("FT.AGGREGATE","person-idx", "*", "SORTBY", "4", "@Name", "ASC", "@Age", "DESC", "WITHCURSOR", "COUNT", "10000"));
}

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

[Fact]
public void TestNestedOrderBy()
{
Expand Down
5 changes: 5 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ public partial class Person

[Indexed]
public string? NullableStringField { get; set; }

[Indexed(Aggregatable = true)] public string FirstName { get; set; }
[Indexed(Aggregatable = true)] public string LastName { get; set; }


}
}