Skip to content

Commit e2503f4

Browse files
committed
Hit<T> sorts is not always a float caused a nasty serialization bug! Fixes #121
1 parent 76e3406 commit e2503f4

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

src/Nest.Tests.Integration/Search/QueryResponseMapperTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void HitsMaxScoreIsSet()
5858
}
5959

6060
[Test]
61-
public void HitsScoreIsSet()
61+
public void HitsSortsIsSet()
6262
{
6363
//arrange
6464
//pull existing example through method we know is functional based on other passing unit tests
@@ -72,6 +72,19 @@ public void HitsScoreIsSet()
7272

7373
Assert.True(hits.Hits.All(h=>h.Sorts.Count() == 2));
7474
}
75+
[Test]
76+
public void HitsSortsIsSetWithStringSort()
77+
{
78+
var queryResults = this.ConnectedClient.Search<ElasticSearchProject>(s => s
79+
.QueryString("*")
80+
.SortAscending(p=>p.Name.Suffix("sort"))
81+
.SortDescending(p => p.Id)
82+
);
83+
84+
var hits = queryResults.Hits;
85+
86+
Assert.True(hits.Hits.All(h => h.Sorts.Count() == 2));
87+
}
7588

7689
[Test]
7790
public void BoolQuery()

src/Nest/Domain/Hit/Hit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class Hit<T> where T : class
2525
public string Id { get; internal set; }
2626

2727
[JsonProperty(PropertyName = "sort")]
28-
public IEnumerable<float> Sorts { get; internal set; }
28+
public IEnumerable<object> Sorts { get; internal set; }
2929

3030
[JsonProperty(PropertyName = "highlight")]
3131
public Dictionary<string, List<string>> Highlight { get; internal set; }

src/Nest/Resolvers/PropertyNameResolver.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Nest.Resolvers
1616

1717
public class PropertyNameResolver : ExpressionVisitor
1818
{
19-
private static readonly ElasticResolver ContractResolver = new ElasticResolver();
19+
private static readonly ElasticResolver ContractResolver = new ElasticResolver();
2020

2121
public ElasticPropertyAttribute GetElasticProperty(MemberInfo info)
2222
{
@@ -25,19 +25,19 @@ public ElasticPropertyAttribute GetElasticProperty(MemberInfo info)
2525
return ((ElasticPropertyAttribute)attributes.First());
2626
return null;
2727
}
28-
28+
2929
public ElasticTypeAttribute GetElasticPropertyFor<T>() where T : class
3030
{
3131
return GetElasticPropertyForType(typeof(T));
3232
}
33-
33+
3434
public ElasticTypeAttribute GetElasticPropertyFor(Type type)
3535
{
3636
if (!type.IsClass && !type.IsInterface)
3737
throw new ArgumentException("Type is not a class or interface", "type");
3838
return GetElasticPropertyForType(type);
3939
}
40-
40+
4141
private ElasticTypeAttribute GetElasticPropertyForType(Type type)
4242
{
4343
if (!type.IsClass && !type.IsInterface)
@@ -66,7 +66,7 @@ public string Resolve(Expression expression)
6666
{
6767
var stack = new Stack<string>();
6868
var properties = new Stack<ElasticPropertyAttribute>();
69-
Visit(expression, stack, properties);
69+
Visit(expression, stack, properties);
7070
return stack
7171
.Aggregate(
7272
new StringBuilder(),
@@ -75,7 +75,7 @@ public string Resolve(Expression expression)
7575
.ToString();
7676
}
7777

78-
protected override Expression VisitMemberAccess(MemberExpression expression, Stack<string> stack, Stack<ElasticPropertyAttribute> properties)
78+
protected override Expression VisitMemberAccess(MemberExpression expression, Stack<string> stack, Stack<ElasticPropertyAttribute> properties)
7979
{
8080
if (stack != null)
8181
{
@@ -94,7 +94,7 @@ protected override Expression VisitMemberAccess(MemberExpression expression, Sta
9494
}
9595
stack.Push(resolvedName);
9696
}
97-
return base.VisitMemberAccess(expression, stack, properties);
97+
return base.VisitMemberAccess(expression, stack, properties);
9898
}
9999

100100
protected override Expression VisitMethodCall(MethodCallExpression m, Stack<string> stack, Stack<ElasticPropertyAttribute> properties)

0 commit comments

Comments
 (0)