Skip to content

Commit ff528ac

Browse files
authored
issue with closures messing up contains (#277)
1 parent eac42b3 commit ff528ac

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

src/Redis.OM/Common/ExpressionParserUtilities.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,16 @@ private static string TranslateContainsStandardQuerySyntax(MethodCallExpression
648648
literal = GetOperandStringForQueryArgs(propertyExpression);
649649
if (!literal.StartsWith("@"))
650650
{
651-
propertyExpression = (MemberExpression)exp.Arguments.First();
652-
valuesExpression = (MemberExpression)exp.Arguments.Last();
651+
if (exp.Arguments.Count == 1 && exp.Object != null)
652+
{
653+
propertyExpression = (MemberExpression)exp.Object;
654+
valuesExpression = (MemberExpression)exp.Arguments.Single();
655+
}
656+
else
657+
{
658+
propertyExpression = (MemberExpression)exp.Arguments.First();
659+
valuesExpression = (MemberExpression)exp.Arguments.Last();
660+
}
653661
}
654662
else if (propertyExpression == valuesExpression)
655663
{

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,23 @@ public void SearchWithEmptyAny()
26102610
Assert.True(any);
26112611
}
26122612

2613+
[Fact]
2614+
public void TestContainsFromLocal()
2615+
{
2616+
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
2617+
.Returns(_mockReply);
2618+
var collection = new RedisCollection<Person>(_mock.Object);
2619+
var steve = "steve";
2620+
collection.Where(x => x.NickNamesList.Contains(steve)).ToList();
2621+
_mock.Verify(x => x.Execute(
2622+
"FT.SEARCH",
2623+
"person-idx",
2624+
"(@NickNamesList:{steve})",
2625+
"LIMIT",
2626+
"0",
2627+
"100"));
2628+
}
2629+
26132630
[Fact]
26142631
public void SearchGuidFieldContains()
26152632
{
@@ -2633,6 +2650,26 @@ public void SearchGuidFieldContains()
26332650
"100"));
26342651
}
26352652

2653+
[Fact]
2654+
public void TestContainsFromProperty()
2655+
{
2656+
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
2657+
.Returns(_mockReply);
2658+
var collection = new RedisCollection<Person>(_mock.Object);
2659+
var steve = new Person
2660+
{
2661+
Name = "steve"
2662+
};
2663+
collection.Where(x => x.NickNamesList.Contains(steve.Name)).ToList();
2664+
_mock.Verify(x => x.Execute(
2665+
"FT.SEARCH",
2666+
"person-idx",
2667+
"(@NickNamesList:{steve})",
2668+
"LIMIT",
2669+
"0",
2670+
"100"));
2671+
}
2672+
26362673
[Fact]
26372674
public void SearchUlidFieldContains()
26382675
{

0 commit comments

Comments
 (0)