From cd8919a9052affdf60cf22504864b3cdd4d8f708 Mon Sep 17 00:00:00 2001
From: Steve Lorello <42971704+slorello89@users.noreply.github.com>
Date: Fri, 12 Apr 2024 14:19:49 -0400
Subject: [PATCH] passing filter format down Fixes #438 (#439)
passing filter format down
---
src/Redis.OM/Common/ExpressionParserUtilities.cs | 11 ++++++-----
.../RediSearchTests/AggregationSetTests.cs | 12 ++++++++++++
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/Redis.OM/Common/ExpressionParserUtilities.cs b/src/Redis.OM/Common/ExpressionParserUtilities.cs
index f502a609..cba92666 100644
--- a/src/Redis.OM/Common/ExpressionParserUtilities.cs
+++ b/src/Redis.OM/Common/ExpressionParserUtilities.cs
@@ -35,8 +35,9 @@ internal static class ExpressionParserUtilities
/// Get's the operand string.
///
/// the expression to parse.
+ /// whether the operand should be filter formatted.
/// The operand string.
- internal static string GetOperandString(Expression exp)
+ internal static string GetOperandString(Expression exp, bool filterFormat = false)
{
return exp switch
{
@@ -46,7 +47,7 @@ internal static string GetOperandString(Expression exp)
$"@{((ConstantExpression)method.Arguments[0]).Value}",
MethodCallExpression method => GetOperandString(method),
UnaryExpression unary => GetOperandString(unary.Operand),
- BinaryExpression binExpression => ParseBinaryExpression(binExpression),
+ BinaryExpression binExpression => ParseBinaryExpression(binExpression, filterFormat),
LambdaExpression lambda => GetOperandString(lambda.Body),
_ => string.Empty
};
@@ -156,8 +157,8 @@ internal static string ParseBinaryExpression(BinaryExpression rootBinaryExpressi
var binExpressions = SplitBinaryExpression(rootBinaryExpression);
foreach (var expression in binExpressions)
{
- var right = GetOperandString(expression.Right);
- var left = GetOperandString(expression.Left);
+ var right = GetOperandString(expression.Right, filterFormat);
+ var left = GetOperandString(expression.Left, filterFormat);
if (filterFormat && ((expression.Left is MemberExpression mem &&
mem.Type == typeof(string)) || (expression.Left is UnaryExpression uni &&
uni.Type == typeof(string))))
@@ -678,7 +679,7 @@ private static string TranslateFormatMethodStandardQuerySyntax(MethodCallExpress
string[] args;
if (exp.Arguments[1] is NewArrayExpression newArrayExpression)
{
- args = newArrayExpression.Expressions.Select(GetOperandString).ToArray();
+ args = newArrayExpression.Expressions.Select(x => GetOperandString(x)).ToArray();
}
else
{
diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs
index d32ba7e4..288b1fa7 100644
--- a/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs
+++ b/test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs
@@ -617,5 +617,17 @@ public void TestDecimalQueryTestingInvariantCultureCompliance(string lcid)
{
Helper.RunTestUnderDifferentCulture(lcid, _ => TestDecimalQuery());
}
+
+ [Fact]
+ public void TestMultiPredicateFilter()
+ {
+ var collection = new RedisAggregationSet(_substitute, true, chunkSize: 10000);
+ _substitute.Execute("FT.AGGREGATE", Arg.Any