Skip to content

Commit 722d48d

Browse files
authored
fixing issue with index null checking, and equality check for numerics (#23)
* fixing issue with index null checking, and equality check for numerics
1 parent 2b26041 commit 722d48d

File tree

5 files changed

+66
-4
lines changed

5 files changed

+66
-4
lines changed

src/Redis.OM/Common/ExpressionTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ internal static RedisQuery BuildQueryFromExpression(Expression expression, Type
260260
/// <returns>The index field type.</returns>
261261
internal static SearchFieldType DetermineIndexFieldsType(MemberInfo member)
262262
{
263-
if (TypeDeterminationUtilities.IsNumeric(member.DeclaringType!))
263+
if (member is PropertyInfo info && TypeDeterminationUtilities.IsNumeric(info.PropertyType))
264264
{
265265
return SearchFieldType.NUMERIC;
266266
}

src/Redis.OM/Redis.OM.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<RootNamespace>Redis.OM</RootNamespace>
77
<Nullable>enable</Nullable>
88
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
9-
<PackageVersion>0.1.1</PackageVersion>
10-
<Version>0.1.1</Version>
9+
<PackageVersion>0.1.2</PackageVersion>
10+
<Version>0.1.2</Version>
1111
<Description>Object Mapping and More for Redis</Description>
1212
<Title>Redis OM</Title>
1313
<Authors>Steve Lorello</Authors>

src/Redis.OM/Searching/RedisQueryProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public SearchResponse<T> ExecuteQuery<T>(Expression expression)
111111
attr = type.GetCustomAttribute<DocumentAttribute>();
112112
}
113113

114-
if (attr == null || string.IsNullOrEmpty(attr.IndexName))
114+
if (attr == null)
115115
{
116116
throw new InvalidOperationException("Searches can only be performed on objects decorated with a RedisObjectDefinitionAttribute that specifies a particular index");
117117
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Redis.OM.Modeling;
2+
3+
namespace Redis.OM.Unit.Tests.RediSearchTests
4+
{
5+
[Document]
6+
public class PersonNoName
7+
{
8+
[Indexed]
9+
public int Age { get; set; }
10+
}
11+
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,57 @@ public void TestBasicQueryWithVariable()
8585
"100"));
8686
}
8787

88+
[Fact]
89+
public void TestBasicQueryWithExactNumericMatch()
90+
{
91+
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
92+
.Returns(_mockReply);
93+
var y = 33;
94+
var collection = new RedisCollection<Person>(_mock.Object);
95+
var res = collection.Where(x => x.Age == y).ToList();
96+
_mock.Verify(x => x.Execute(
97+
"FT.SEARCH",
98+
"person-idx",
99+
"(@Age:[33 33])",
100+
"LIMIT",
101+
"0",
102+
"100"));
103+
}
104+
105+
[Fact]
106+
public void TestBasicFirstOrDefaultQuery()
107+
{
108+
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
109+
.Returns(_mockReply);
110+
var y = 33;
111+
var collection = new RedisCollection<Person>(_mock.Object);
112+
var res = collection.FirstOrDefault(x => x.Age == y);
113+
_mock.Verify(x => x.Execute(
114+
"FT.SEARCH",
115+
"person-idx",
116+
"(@Age:[33 33])",
117+
"LIMIT",
118+
"0",
119+
"1"));
120+
}
121+
122+
[Fact]
123+
public void TestBasicQueryNoNameIndex()
124+
{
125+
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
126+
.Returns(_mockReply);
127+
var y = 33;
128+
var collection = new RedisCollection<PersonNoName>(_mock.Object);
129+
var res = collection.FirstOrDefault(x => x.Age == y);
130+
_mock.Verify(x => x.Execute(
131+
"FT.SEARCH",
132+
"personnoname-idx",
133+
"(@Age:[33 33])",
134+
"LIMIT",
135+
"0",
136+
"1"));
137+
}
138+
88139
[Fact]
89140
public void TestBasicOrQuery()
90141
{

0 commit comments

Comments
 (0)