diff --git a/src/Redis.OM/Common/ExpressionParserUtilities.cs b/src/Redis.OM/Common/ExpressionParserUtilities.cs index db8fde4..e42cbcb 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; diff --git a/test/Redis.OM.Unit.Tests/RediSearchTests/FilterPredicateTest.cs b/test/Redis.OM.Unit.Tests/RediSearchTests/FilterPredicateTest.cs index 80035a4..6b0e516 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 79f3efe..f2f3325 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; } } }