Skip to content

Commit 468767b

Browse files
committed
Added SortAnalyzer to enable case-insensitive sorting
1 parent 8de7b63 commit 468767b

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

Diff for: src/Nest/Domain/Mapping/Attributes/ElasticPropertyAttribute.cs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class ElasticPropertyAttribute : Attribute, IElasticPropertyAttribute
2121
public string Analyzer { get; set; }
2222
public string IndexAnalyzer { get; set; }
2323
public string SearchAnalyzer { get; set; }
24+
public string SortAnalyzer { get; set; }
2425
public string NullValue { get; set; }
2526
public string Similarity { get; set; }
2627

Diff for: src/Nest/Domain/Mapping/Attributes/IElasticPropertyAttribute.cs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public interface IElasticPropertyAttribute
1616
string Analyzer { get; set; }
1717
string IndexAnalyzer { get; set; }
1818
string SearchAnalyzer { get; set; }
19+
string SortAnalyzer { get; set; }
1920
string NullValue { get; set; }
2021

2122
bool OmitNorms { get; set; }

Diff for: src/Nest/Resolvers/Writers/WritePropertiesFromAttributeVisitor.cs

+11-2
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,17 @@ public void VisitBaseAttribute(IElasticPropertyAttribute att) {
131131
this._jsonWriter.WritePropertyName("type");
132132
this._jsonWriter.WriteValue(this._type);
133133
}
134-
this._jsonWriter.WritePropertyName("index");
135-
this._jsonWriter.WriteValue(Enum.GetName(typeof (FieldIndexOption), FieldIndexOption.not_analyzed));
134+
if (att.SortAnalyzer.IsNullOrEmpty())
135+
{
136+
this._jsonWriter.WritePropertyName("index");
137+
this._jsonWriter.WriteValue(Enum.GetName(typeof(FieldIndexOption), FieldIndexOption.not_analyzed));
138+
}
139+
else
140+
{
141+
this._jsonWriter.WritePropertyName("index_analyzer");
142+
this._jsonWriter.WriteValue(att.SortAnalyzer);
143+
}
144+
136145
this._jsonWriter.WriteEnd();
137146
this._jsonWriter.WriteEnd();
138147
}

Diff for: src/Tests/Nest.Tests.Unit/Core/Map/Properties/PropertiesTests.cs

+17
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ public void IPProperty()
200200
);
201201
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
202202
}
203+
204+
public class Foo
205+
{
206+
public int Id { get; set; }
207+
[ElasticProperty(AddSortField = true, SortAnalyzer = "simple")]
208+
public string Name { get; set; }
209+
}
210+
211+
[Test]
212+
public void SortAnalyzeryReadFromAttribute()
213+
{
214+
var result = _client.Map<Foo>(m => m.MapFromAttributes());
215+
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
216+
217+
}
218+
203219
[Test]
204220
public void GeoPointProperty()
205221
{
@@ -215,6 +231,7 @@ public void GeoPointProperty()
215231
);
216232
this.JsonEquals(result.ConnectionStatus.Request, MethodInfo.GetCurrentMethod());
217233
}
234+
218235
[Test]
219236
public void GeoShapeProperty()
220237
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"foo": {
3+
"properties": {
4+
"id": {
5+
"type": "integer"
6+
},
7+
"name": {
8+
"type": "multi_field",
9+
"fields": {
10+
"name": {
11+
"type": "string"
12+
},
13+
"sort": {
14+
"type": "string",
15+
"index_analyzer": "simple"
16+
}
17+
}
18+
}
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)