Another test for parsing "geo_distance" filter: 12mi and km

If an explicit unit is provided with "distance",
the "unit" can be safely ignored, as it works
as a fallback unit.
This commit is contained in:
Adriano Ferreira 2010-10-26 14:14:35 -02:00 committed by kimchy
parent 8c8b7bee3a
commit 2d15cd8009
2 changed files with 30 additions and 0 deletions

View File

@ -1311,6 +1311,19 @@ public class SimpleIndexQueryParserTests {
assertThat(filter.distance(), closeTo(12, 0.00001));
}
@Test public void testGeoDistanceFilter12() throws IOException {
IndexQueryParser queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance12.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(FilteredQuery.class));
FilteredQuery filteredQuery = (FilteredQuery) parsedQuery;
GeoDistanceFilter filter = (GeoDistanceFilter) filteredQuery.getFilter();
assertThat(filter.fieldName(), equalTo("location"));
assertThat(filter.lat(), closeTo(40, 0.00001));
assertThat(filter.lon(), closeTo(-70, 0.00001));
assertThat(filter.distance(), closeTo(12, 0.00001));
}
@Test public void testGeoBoundingBoxFilterNamed() throws IOException {
IndexQueryParser queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox-named.json");

View File

@ -0,0 +1,17 @@
{
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "12mi",
"unit": "km",
"person.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}