From e41c27c284f851402f8396378effa7833badb34b Mon Sep 17 00:00:00 2001 From: SMAH1 Date: Sun, 18 May 2025 09:06:59 +0330 Subject: [PATCH 1/2] test to show a bug where Enum variable doesn't correct the statement #520 --- .../RediSearchTests/FilterPredicateTest.cs | 37 +++++++++++++++++++ .../RediSearchTests/Person.cs | 11 +++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/FilterPredicateTest.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/FilterPredicateTest.cs index 80035a43..6b0e516f 100644 --- a/test/Redis.OM.Unit.Tests/RediSearchTests/FilterPredicateTest.cs +++ b/test/Redis.OM.Unit.Tests/RediSearchTests/FilterPredicateTest.cs @@ -193,5 +193,42 @@ public void TestFilterDatetimeFunction() Assert.Equal("Blah", res[0]["FakeResult"]); } + + [Fact] + public void TestFilterEnum() + { + var expectedPredicate = "@Feel == 2"; + _substitute.Execute( + "FT.AGGREGATE", + "person-idx", + "*", + "FILTER", + expectedPredicate) + .Returns(_mockReply); + var collection = new RedisAggregationSet(_substitute); + + var res = collection.Filter(x => x.RecordShell.Feel == PersonFeel.Happy).ToArray(); + + Assert.Equal("Blah", res[0]["FakeResult"]); + } + + [Fact] + public void TestFilterEnumFromVariable() + { + var expectedPredicate = "@Feel == 2"; + _substitute.Execute( + "FT.AGGREGATE", + "person-idx", + "*", + "FILTER", + expectedPredicate) + .Returns(_mockReply); + var collection = new RedisAggregationSet(_substitute); + + PersonFeel feel = PersonFeel.Happy; + var res = collection.Filter(x => x.RecordShell.Feel == feel).ToArray(); + + Assert.Equal("Blah", res[0]["FakeResult"]); + } } } diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/Person.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/Person.cs index 79f3efe5..f2f33250 100644 --- a/test/Redis.OM.Unit.Tests/RediSearchTests/Person.cs +++ b/test/Redis.OM.Unit.Tests/RediSearchTests/Person.cs @@ -3,6 +3,14 @@ namespace Redis.OM.Unit.Tests.RediSearchTests { + public enum PersonFeel : byte + { + Sad = 0, + Upset, + Happy, + Angry, + } + [Document(StorageType = StorageType.Json, IndexName = "person-idx")] public partial class Person { @@ -72,6 +80,7 @@ public partial class Person [Indexed(Aggregatable = true)] public string FirstName { get; set; } [Indexed(Aggregatable = true)] public string LastName { get; set; } - + [Indexed] + public PersonFeel Feel { get; set; } } } From d950db36abd519cb4127c97bc5e918a7f1cd79b5 Mon Sep 17 00:00:00 2001 From: SMAH1 Date: Sun, 18 May 2025 09:07:28 +0330 Subject: [PATCH 2/2] fix bug where Enum variable doesn't correct the statement #520 --- src/Redis.OM/Common/ExpressionParserUtilities.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Redis.OM/Common/ExpressionParserUtilities.cs b/src/Redis.OM/Common/ExpressionParserUtilities.cs index db8fde41..e42cbcbe 100644 --- a/src/Redis.OM/Common/ExpressionParserUtilities.cs +++ b/src/Redis.OM/Common/ExpressionParserUtilities.cs @@ -411,6 +411,11 @@ private static string GetOperandStringForMember(MemberExpression member, bool tr return string.Join("|", ulids); } + if (resolvedType.IsEnum && member.Expression is ConstantExpression enumValue) + { + return Convert.ToInt32(resolved).ToString(); + } + if (resolvedType.IsArray || resolvedType.GetInterfaces().Contains(typeof(IEnumerable))) { var asEnumerable = (IEnumerable)resolved;