Skip to content

Commit

Permalink
passing filter format down Fixes #438 (#439)
Browse files Browse the repository at this point in the history
passing filter format down
  • Loading branch information
slorello89 committed Apr 12, 2024
1 parent 2b516c0 commit 875227a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Redis.OM/Common/ExpressionParserUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ internal static class ExpressionParserUtilities
/// Get's the operand string.
/// </summary>
/// <param name="exp">the expression to parse.</param>
/// <param name="filterFormat">whether the operand should be filter formatted.</param>
/// <returns>The operand string.</returns>
internal static string GetOperandString(Expression exp)
internal static string GetOperandString(Expression exp, bool filterFormat = false)
{
return exp switch
{
Expand All @@ -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
};
Expand Down Expand Up @@ -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))))
Expand Down Expand Up @@ -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
{
Expand Down
12 changes: 12 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/AggregationSetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,5 +617,17 @@ public void TestDecimalQueryTestingInvariantCultureCompliance(string lcid)
{
Helper.RunTestUnderDifferentCulture(lcid, _ => TestDecimalQuery());
}

[Fact]
public void TestMultiPredicateFilter()
{
var collection = new RedisAggregationSet<Person>(_substitute, true, chunkSize: 10000);
_substitute.Execute("FT.AGGREGATE", Arg.Any<object[]>()).Returns(MockedResult);
_substitute.Execute("FT.CURSOR", Arg.Any<object[]>()).Returns(MockedResultCursorEnd);

Expression<Func<AggregationResult<Person>, bool>> query = a => a.RecordShell!.TagField == "foo" && a.RecordShell.Address.State == "FL";
_ = collection.Filter(query).ToList();
_substitute.Received().Execute("FT.AGGREGATE", "person-idx", "*", "FILTER", "@TagField == 'foo' && @Address_State == 'FL'", "WITHCURSOR", "COUNT", "10000");
}
}
}

0 comments on commit 875227a

Please sign in to comment.