Skip to content

Commit

Permalink
Bugfix: support method call in Any() on embedded list
Browse files Browse the repository at this point in the history
  • Loading branch information
PrudiusVladislav committed Apr 26, 2024
1 parent cd8919a commit 3526fab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ We'd love your contributions! If you want to contribute please read our [Contrib
* [@mdrakib](https://github.com/mdrakib)
* [@jrpavoncello](https://github.com/jrpavoncello)
* [@axnetg](https://github.com/axnetg)
* [@PrudiusVladislav](https://github.com/PrudiusVladislav)

<!-- Logo -->
[Logo]: images/logo.svg
Expand Down
13 changes: 11 additions & 2 deletions src/Redis.OM/Common/ExpressionParserUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -960,8 +960,17 @@ private static string TranslateAnyForEmbeddedObjects(MethodCallExpression exp, L
var type = exp.Arguments.Last().Type;
var prefix = GetOperandString(exp.Arguments[0]);
var lambda = (LambdaExpression)exp.Arguments.Last();
var tempQuery = ExpressionTranslator.TranslateBinaryExpression((BinaryExpression)lambda.Body, parameters);
return tempQuery.Replace("@", $"{prefix}_");

if (lambda.Body is MethodCallExpression methodCall)
{
var tempQuery = TranslateMethodExpressions(methodCall, parameters);
return tempQuery.Replace("@", $"{prefix}_");
}
else
{
var tempQuery = ExpressionTranslator.TranslateBinaryExpression((BinaryExpression)lambda.Body, parameters);
return tempQuery.Replace("@", $"{prefix}_");
}
}

private static string ValueToString(object value)
Expand Down
20 changes: 20 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,26 @@ await _substitute.Received().ExecuteAsync(
"100");
}

[Fact]
public async Task TestAnyQueryForArrayOfEmbeddedObjectsMethodCallExpression()
{
_substitute.ClearSubstitute();
_substitute.ExecuteAsync(Arg.Any<string>(), Arg.Any<object[]>()).Returns(_mockReply);

var collection = new RedisCollection<ObjectWithEmbeddedArrayOfObjects>(_substitute);

await collection.Where(x =>
x.Addresses.Any(a => a.City.Contains("Beach"))).ToListAsync();

await _substitute.Received().ExecuteAsync(
"FT.SEARCH",
"objectwithembeddedarrayofobjects-idx",
"(@Addresses_City:{*Beach*})",
"LIMIT",
"0",
"100");
}

[Fact]
public async Task SearchWithMultipleWhereClauses()
{
Expand Down

0 comments on commit 3526fab

Please sign in to comment.