Skip to content
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

passing filter format down Fixes #438 #439

Merged
merged 1 commit into from
Apr 12, 2024
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
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 @@ -150,8 +151,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 @@ -666,7 +667,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");
}
}
}
Loading