Skip to content

Commit cd8919a

Browse files
authored
passing filter format down Fixes #438 (#439)
passing filter format down
1 parent 37d573f commit cd8919a

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/Redis.OM/Common/ExpressionParserUtilities.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ internal static class ExpressionParserUtilities
3535
/// Get's the operand string.
3636
/// </summary>
3737
/// <param name="exp">the expression to parse.</param>
38+
/// <param name="filterFormat">whether the operand should be filter formatted.</param>
3839
/// <returns>The operand string.</returns>
39-
internal static string GetOperandString(Expression exp)
40+
internal static string GetOperandString(Expression exp, bool filterFormat = false)
4041
{
4142
return exp switch
4243
{
@@ -46,7 +47,7 @@ internal static string GetOperandString(Expression exp)
4647
$"@{((ConstantExpression)method.Arguments[0]).Value}",
4748
MethodCallExpression method => GetOperandString(method),
4849
UnaryExpression unary => GetOperandString(unary.Operand),
49-
BinaryExpression binExpression => ParseBinaryExpression(binExpression),
50+
BinaryExpression binExpression => ParseBinaryExpression(binExpression, filterFormat),
5051
LambdaExpression lambda => GetOperandString(lambda.Body),
5152
_ => string.Empty
5253
};
@@ -156,8 +157,8 @@ internal static string ParseBinaryExpression(BinaryExpression rootBinaryExpressi
156157
var binExpressions = SplitBinaryExpression(rootBinaryExpression);
157158
foreach (var expression in binExpressions)
158159
{
159-
var right = GetOperandString(expression.Right);
160-
var left = GetOperandString(expression.Left);
160+
var right = GetOperandString(expression.Right, filterFormat);
161+
var left = GetOperandString(expression.Left, filterFormat);
161162
if (filterFormat && ((expression.Left is MemberExpression mem &&
162163
mem.Type == typeof(string)) || (expression.Left is UnaryExpression uni &&
163164
uni.Type == typeof(string))))
@@ -678,7 +679,7 @@ private static string TranslateFormatMethodStandardQuerySyntax(MethodCallExpress
678679
string[] args;
679680
if (exp.Arguments[1] is NewArrayExpression newArrayExpression)
680681
{
681-
args = newArrayExpression.Expressions.Select(GetOperandString).ToArray();
682+
args = newArrayExpression.Expressions.Select(x => GetOperandString(x)).ToArray();
682683
}
683684
else
684685
{

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,5 +617,17 @@ public void TestDecimalQueryTestingInvariantCultureCompliance(string lcid)
617617
{
618618
Helper.RunTestUnderDifferentCulture(lcid, _ => TestDecimalQuery());
619619
}
620+
621+
[Fact]
622+
public void TestMultiPredicateFilter()
623+
{
624+
var collection = new RedisAggregationSet<Person>(_substitute, true, chunkSize: 10000);
625+
_substitute.Execute("FT.AGGREGATE", Arg.Any<object[]>()).Returns(MockedResult);
626+
_substitute.Execute("FT.CURSOR", Arg.Any<object[]>()).Returns(MockedResultCursorEnd);
627+
628+
Expression<Func<AggregationResult<Person>, bool>> query = a => a.RecordShell!.TagField == "foo" && a.RecordShell.Address.State == "FL";
629+
_ = collection.Filter(query).ToList();
630+
_substitute.Received().Execute("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'", "WITHCURSOR", "COUNT", "10000");
631+
}
620632
}
621633
}

0 commit comments

Comments
 (0)