From 1cbf5d10aa06ef3890c74128bca0fe5d8dce521c Mon Sep 17 00:00:00 2001 From: slorello89 Date: Thu, 10 Oct 2024 07:37:03 -0400 Subject: [PATCH] fixing issue with multiple where predicates paired with a select --- src/Redis.OM/Common/ExpressionTranslator.cs | 2 +- .../RediSearchTests/SearchTests.cs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Redis.OM/Common/ExpressionTranslator.cs b/src/Redis.OM/Common/ExpressionTranslator.cs index 93fe4d69..f2f2be85 100644 --- a/src/Redis.OM/Common/ExpressionTranslator.cs +++ b/src/Redis.OM/Common/ExpressionTranslator.cs @@ -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); diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs index 92625fd1..eada63d7 100644 --- a/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs +++ b/test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs @@ -3308,6 +3308,26 @@ public void TestSelectWithWhere() "Name"); } + [Fact] + public void TestSelectWithMultipleWheres() + { + _substitute.ClearSubstitute(); + _substitute.Execute(Arg.Any(), Arg.Any()).Returns(_mockReply); + IRedisCollection collection = new RedisCollection(_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()