Skip to content

fixing issue with index null checking, and equality check for numerics #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Redis.OM/Common/ExpressionTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ internal static RedisQuery BuildQueryFromExpression(Expression expression, Type
/// <returns>The index field type.</returns>
internal static SearchFieldType DetermineIndexFieldsType(MemberInfo member)
{
if (TypeDeterminationUtilities.IsNumeric(member.DeclaringType!))
if (member is PropertyInfo info && TypeDeterminationUtilities.IsNumeric(info.PropertyType))
{
return SearchFieldType.NUMERIC;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Redis.OM/Redis.OM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<RootNamespace>Redis.OM</RootNamespace>
<Nullable>enable</Nullable>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PackageVersion>0.1.1</PackageVersion>
<Version>0.1.1</Version>
<PackageVersion>0.1.2</PackageVersion>
<Version>0.1.2</Version>
<Description>Object Mapping and More for Redis</Description>
<Title>Redis OM</Title>
<Authors>Steve Lorello</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/Redis.OM/Searching/RedisQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public SearchResponse<T> ExecuteQuery<T>(Expression expression)
attr = type.GetCustomAttribute<DocumentAttribute>();
}

if (attr == null || string.IsNullOrEmpty(attr.IndexName))
if (attr == null)
{
throw new InvalidOperationException("Searches can only be performed on objects decorated with a RedisObjectDefinitionAttribute that specifies a particular index");
}
Expand Down
11 changes: 11 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/PersonNoName.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Redis.OM.Modeling;

namespace Redis.OM.Unit.Tests.RediSearchTests
{
[Document]
public class PersonNoName
{
[Indexed]
public int Age { get; set; }
}
}
51 changes: 51 additions & 0 deletions test/Redis.OM.Unit.Tests/RediSearchTests/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,57 @@ public void TestBasicQueryWithVariable()
"100"));
}

[Fact]
public void TestBasicQueryWithExactNumericMatch()
{
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
.Returns(_mockReply);
var y = 33;
var collection = new RedisCollection<Person>(_mock.Object);
var res = collection.Where(x => x.Age == y).ToList();
_mock.Verify(x => x.Execute(
"FT.SEARCH",
"person-idx",
"(@Age:[33 33])",
"LIMIT",
"0",
"100"));
}

[Fact]
public void TestBasicFirstOrDefaultQuery()
{
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
.Returns(_mockReply);
var y = 33;
var collection = new RedisCollection<Person>(_mock.Object);
var res = collection.FirstOrDefault(x => x.Age == y);
_mock.Verify(x => x.Execute(
"FT.SEARCH",
"person-idx",
"(@Age:[33 33])",
"LIMIT",
"0",
"1"));
}

[Fact]
public void TestBasicQueryNoNameIndex()
{
_mock.Setup(x => x.Execute(It.IsAny<string>(), It.IsAny<string[]>()))
.Returns(_mockReply);
var y = 33;
var collection = new RedisCollection<PersonNoName>(_mock.Object);
var res = collection.FirstOrDefault(x => x.Age == y);
_mock.Verify(x => x.Execute(
"FT.SEARCH",
"personnoname-idx",
"(@Age:[33 33])",
"LIMIT",
"0",
"1"));
}

[Fact]
public void TestBasicOrQuery()
{
Expand Down