Skip to content

Commit

Permalink
fixing issue with multiple where predicates paired with a select (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorello89 authored Oct 21, 2024
1 parent cc3eafb commit 1956366
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Redis.OM/Common/ExpressionTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ internal static RedisQuery BuildQueryFromExpression(Expression expression, Type
query.GeoFilter = ExpressionParserUtilities.TranslateGeoFilter(exp);
break;
case "Where":
query.QueryText = TranslateWhereMethod(exp, parameters);
query.QueryText = query.QueryText == "*" ? TranslateWhereMethod(exp, parameters) : $"({TranslateWhereMethod(exp, parameters)} {query.QueryText})";
break;
case "NearestNeighbors":
query.NearestNeighbors = ParseNearestNeighborsFromExpression(exp);
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 @@ -3325,6 +3325,26 @@ public void TestSelectWithWhere()
"Name");
}

[Fact]
public void TestSelectWithMultipleWheres()
{
_substitute.ClearSubstitute();
_substitute.Execute(Arg.Any<string>(), Arg.Any<object[]>()).Returns(_mockReply);
IRedisCollection<Person> collection = new RedisCollection<Person>(_substitute);
collection = collection.Where(x => x.Name == "Steve");
_ = collection.Where(x => x.Age == 33).Select(x => x.Name).ToList();
_substitute.Received().Execute(
"FT.SEARCH",
"person-idx",
"((@Name:\"Steve\") (@Age:[33 33]))",
"LIMIT",
"0",
"100",
"RETURN",
"1",
"Name");
}

[Fact]
public void TestNullableEnumQueries()

Expand Down

0 comments on commit 1956366

Please sign in to comment.