forked from elastic/elasticsearch-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeoDistanceAggregationDescriptor.cs
102 lines (79 loc) · 2.63 KB
/
GeoDistanceAggregationDescriptor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using Nest.Resolvers.Converters;
using Newtonsoft.Json;
namespace Nest
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
[JsonConverter(typeof(ReadAsTypeConverter<GeoDistanceAggregator>))]
public interface IGeoDistanceAggregator : IBucketAggregator
{
[JsonProperty("field")]
PropertyPathMarker Field { get; set; }
[JsonProperty("origin")]
string Origin { get; set; }
[JsonProperty("unit")]
GeoUnit? Unit { get; set; }
[JsonProperty("distance_type")]
GeoDistance? DistanceType { get; set; }
[JsonProperty(PropertyName = "ranges")]
IEnumerable<Range<double>> Ranges { get; set; }
}
public class GeoDistanceAggregator : BucketAggregator, IGeoDistanceAggregator
{
public PropertyPathMarker Field { get; set; }
public string Origin { get; set; }
public GeoUnit? Unit { get; set; }
public GeoDistance? DistanceType { get; set; }
public IEnumerable<Range<double>> Ranges { get; set; }
}
public class GeoDistanceAggregationDescriptor<T> : BucketAggregationBaseDescriptor<GeoDistanceAggregationDescriptor<T>, T>, IGeoDistanceAggregator where T : class
{
private IGeoDistanceAggregator Self { get { return this; } }
PropertyPathMarker IGeoDistanceAggregator.Field { get; set; }
string IGeoDistanceAggregator.Origin { get; set; }
GeoUnit? IGeoDistanceAggregator.Unit { get; set; }
GeoDistance? IGeoDistanceAggregator.DistanceType { get; set; }
IEnumerable<Range<double>> IGeoDistanceAggregator.Ranges { get; set; }
public GeoDistanceAggregationDescriptor<T> Field(string field)
{
Self.Field = field;
return this;
}
public GeoDistanceAggregationDescriptor<T> Field(Expression<Func<T, object>> field)
{
Self.Field = field;
return this;
}
public GeoDistanceAggregationDescriptor<T> Origin(double Lat, double Lon)
{
var c = CultureInfo.InvariantCulture;
Self.Origin = "{0}, {1}".F(Lat.ToString(c), Lon.ToString(c));
return this;
}
public GeoDistanceAggregationDescriptor<T> Origin(string geoHash)
{
Self.Origin = geoHash;
return this;
}
public GeoDistanceAggregationDescriptor<T> Unit(GeoUnit unit)
{
Self.Unit = unit;
return this;
}
public GeoDistanceAggregationDescriptor<T> DistanceType(GeoDistance geoDistance)
{
Self.DistanceType = geoDistance;
return this;
}
public GeoDistanceAggregationDescriptor<T> Ranges(params Func<Range<double>, Range<double>>[] ranges)
{
var newRanges = from range in ranges let r = new Range<double>() select range(r);
Self.Ranges = newRanges;
return this;
}
}
}