Skip to content

Commit bbc0861

Browse files
committed
Full json test coverage for geo shape filters
1 parent cc32835 commit bbc0861

File tree

1 file changed

+258
-2
lines changed

1 file changed

+258
-2
lines changed

src/Tests/Nest.Tests.Unit/Search/Filter/Singles/GeoShapeFilterJson.cs

Lines changed: 258 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Nest.Tests.Unit.Search.Filter.Singles
88
public class GeoShapeFilterJson
99
{
1010
[Test]
11-
public void GeoShapeFilter()
11+
public void GeoShapeEnvelopeFilter()
1212
{
1313
//[13.0, 53.0], [14.0, 52.0]]
1414
var s = new SearchDescriptor<ElasticsearchProject>()
@@ -40,9 +40,265 @@ public void GeoShapeFilter()
4040
Assert.True(json.JsonEquals(expected), json);
4141
}
4242

43+
[Test]
4344
public void GeoShapeCircleFilter()
4445
{
45-
46+
var s = new SearchDescriptor<ElasticsearchProject>()
47+
.From(0)
48+
.Size(10)
49+
.Filter(f => f
50+
.Cache(true)
51+
.Name("my_geo_filter")
52+
.GeoShapeCircle(p => p.Origin, d => d
53+
.Coordinates(new[] { -45.0, 45.0 })
54+
.Radius("100m")
55+
)
56+
);
57+
58+
var json = TestElasticClient.Serialize(s);
59+
var expected = @"{ from: 0, size: 10,
60+
filter : {
61+
geo_shape: {
62+
origin: {
63+
shape: {
64+
coordinates: [ -45.0, 45.0 ],
65+
radius: ""100m"",
66+
type: ""circle""
67+
}
68+
},
69+
_cache: true,
70+
_name: ""my_geo_filter""
71+
}
72+
}
73+
}";
74+
Assert.IsTrue(json.JsonEquals(expected), json);
75+
}
76+
77+
[Test]
78+
public void GeoShapeLineStringFilter()
79+
{
80+
var s = new SearchDescriptor<ElasticsearchProject>()
81+
.From(0)
82+
.Size(10)
83+
.Filter(f => f
84+
.Cache(true)
85+
.Name("my_geo_filter")
86+
.GeoShapeLineString(p => p.Origin, d => d
87+
.Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } })
88+
)
89+
);
90+
91+
var json = TestElasticClient.Serialize(s);
92+
var expected = @"{ from: 0, size: 10,
93+
filter : {
94+
geo_shape: {
95+
origin: {
96+
shape: {
97+
coordinates: [
98+
[ 13.0, 53.0 ], [ 14.0, 52.0 ]
99+
],
100+
type: ""linestring""
101+
}
102+
},
103+
_cache: true,
104+
_name: ""my_geo_filter""
105+
}
106+
}
107+
}";
108+
Assert.IsTrue(json.JsonEquals(expected), json);
109+
}
110+
111+
[Test]
112+
public void GeoShapeMultiLineStringFilter()
113+
{
114+
var s = new SearchDescriptor<ElasticsearchProject>()
115+
.From(0)
116+
.Size(10)
117+
.Filter(f => f
118+
.Cache(true)
119+
.Name("my_geo_filter")
120+
.GeoShapeMultiLineString(p => p.Origin, d => d
121+
.Coordinates(new[] {
122+
new[] { new[] { 102.0, 2.0 }, new[] { 103.0, 2.0 }, new[] { 103.0, 3.0 }, new[] { 102.0, 3.0 } },
123+
new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 } },
124+
new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 } }
125+
})
126+
)
127+
);
128+
129+
var json = TestElasticClient.Serialize(s);
130+
var expected = @"{ from: 0, size: 10,
131+
filter : {
132+
geo_shape: {
133+
origin: {
134+
shape: {
135+
coordinates: [
136+
[ [ 102.0, 2.0 ], [ 103.0, 2.0 ], [ 103.0, 3.0 ], [ 102.0, 3.0 ] ],
137+
[ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ] ],
138+
[ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ] ]
139+
],
140+
type: ""multilinestring""
141+
}
142+
},
143+
_cache: true,
144+
_name: ""my_geo_filter""
145+
}
146+
}
147+
}";
148+
Assert.IsTrue(json.JsonEquals(expected), json);
149+
}
150+
151+
[Test]
152+
public void GeoShapePointFilter()
153+
{
154+
var s = new SearchDescriptor<ElasticsearchProject>()
155+
.From(0)
156+
.Size(10)
157+
.Filter(f => f
158+
.Cache(true)
159+
.Name("my_geo_filter")
160+
.GeoShapePoint(p => p.Origin, d => d
161+
.Coordinates(new [] { 1.0, 2.0 })
162+
)
163+
);
164+
165+
var json = TestElasticClient.Serialize(s);
166+
var expected = @"{ from: 0, size: 10,
167+
filter : {
168+
geo_shape: {
169+
origin: {
170+
shape: {
171+
coordinates:[ 1.0, 2.0 ],
172+
type: ""point""
173+
}
174+
},
175+
_cache: true,
176+
_name: ""my_geo_filter""
177+
}
178+
}
179+
}";
180+
Assert.IsTrue(json.JsonEquals(expected), json);
181+
}
182+
183+
public void GeoShapeMultiPointFilter()
184+
{
185+
var s = new SearchDescriptor<ElasticsearchProject>()
186+
.From(0)
187+
.Size(10)
188+
.Filter(f => f
189+
.Cache(true)
190+
.Name("my_geo_filter")
191+
.GeoShapeMultiPoint(p => p.Origin, d => d
192+
.Coordinates(new[] { new[] { 13.0, 53.0 }, new[] { 14.0, 52.0 } })
193+
)
194+
);
195+
196+
var json = TestElasticClient.Serialize(s);
197+
var expected = @"{ from: 0, size: 10,
198+
filter : {
199+
geo_shape: {
200+
origin: {
201+
shape: {
202+
coordinates:[ [ 13.0, 53.0 ], [ 14.0, 52.0 ] ],
203+
type: ""multipoint""
204+
}
205+
},
206+
_cache: true,
207+
_name: ""my_geo_filter""
208+
}
209+
}
210+
}";
211+
Assert.IsTrue(json.JsonEquals(expected), json);
212+
}
213+
214+
[Test]
215+
public void GeoShapePolygonFilter()
216+
{
217+
var s = new SearchDescriptor<ElasticsearchProject>()
218+
.From(0)
219+
.Size(10)
220+
.Filter(f => f
221+
.Cache(true)
222+
.Name("my_geo_filter")
223+
.GeoShapePolygon(p => p.Origin, d => d
224+
.Coordinates(new[] {
225+
new[] { new[] { 100.0, 0.0 }, new[] { 101.0, 0.0 }, new[] { 101.0, 1.0 }, new[] { 100.0, 1.0 }, new [] { 100.0, 0.0 } },
226+
new[] { new[] { 100.2, 0.2 }, new[] { 100.8, 0.2 }, new[] { 100.8, 0.8 }, new[] { 100.2, 0.8 }, new [] { 100.2, 0.2 } }
227+
})
228+
)
229+
);
230+
231+
var json = TestElasticClient.Serialize(s);
232+
var expected = @"{ from: 0, size: 10,
233+
filter : {
234+
geo_shape: {
235+
origin: {
236+
shape: {
237+
coordinates: [
238+
[ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ],
239+
[ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ], [ 100.2, 0.2 ] ]
240+
],
241+
type: ""polygon""
242+
}
243+
},
244+
_cache: true,
245+
_name: ""my_geo_filter""
246+
}
247+
}
248+
}";
249+
Assert.IsTrue(json.JsonEquals(expected), json);
250+
}
251+
252+
[Test]
253+
public void GeoShapeMultiPolygonFilter()
254+
{
255+
var s = new SearchDescriptor<ElasticsearchProject>()
256+
.From(0)
257+
.Size(10)
258+
.Filter(f => f
259+
.Cache(true)
260+
.Name("my_geo_filter")
261+
.GeoShapeMultiPolygon(p => p.Origin, d => d
262+
.Coordinates(new[] {
263+
new [] {
264+
new [] {
265+
new [] { 102.0, 2.0 }, new [] { 103.0, 2.0 }, new [] { 103.0, 3.0 }, new [] { 102.0, 3.0 }, new [] { 102.0, 2.0 }
266+
}
267+
},
268+
new [] {
269+
new [] {
270+
new [] { 100.0, 0.0 }, new [] { 101.0, 0.0 }, new [] { 101.0, 1.0 }, new [] {100.0, 1.0 }, new [] { 100.0, 0.0 }
271+
},
272+
new [] {
273+
new [] { 100.2, 0.2 }, new [] { 100.8, 0.2 }, new [] { 100.8, 0.8 }, new [] { 100.2, 0.8 }, new [] { 100.2, 0.2 }
274+
}
275+
}
276+
})
277+
)
278+
);
279+
280+
var json = TestElasticClient.Serialize(s);
281+
var expected = @"{ from: 0, size: 10,
282+
filter : {
283+
geo_shape: {
284+
origin: {
285+
shape: {
286+
coordinates:[
287+
[ [ [ 102.0, 2.0 ], [ 103.0, 2.0 ], [ 103.0, 3.0 ], [ 102.0, 3.0 ], [ 102.0, 2.0 ] ] ],
288+
[
289+
[ [ 100.0, 0.0 ], [ 101.0, 0.0 ], [ 101.0, 1.0 ], [ 100.0, 1.0 ], [ 100.0, 0.0 ] ],
290+
[ [ 100.2, 0.2 ], [ 100.8, 0.2 ], [ 100.8, 0.8 ], [ 100.2, 0.8 ], [ 100.2, 0.2 ] ]
291+
]
292+
],
293+
type: ""multipolygon""
294+
}
295+
},
296+
_cache: true,
297+
_name: ""my_geo_filter""
298+
}
299+
}
300+
}";
301+
Assert.IsTrue(json.JsonEquals(expected), json);
46302
}
47303
}
48304
}

0 commit comments

Comments
 (0)