Three tests for parsing "geo_distance" filter: 12 miles in km

The added test files should be equivalent. Actually they
hit the same bug as change

    Two tests for parsing "geo_distance" filter: distance/unit parameters
This commit is contained in:
Adriano Ferreira 2010-10-26 14:05:38 -02:00 committed by kimchy
parent 244a566e49
commit 8c8b7bee3a
4 changed files with 90 additions and 0 deletions

View File

@ -1271,6 +1271,46 @@ public class SimpleIndexQueryParserTests {
assertThat(filter.lon(), closeTo(-70, 0.00001)); assertThat(filter.lon(), closeTo(-70, 0.00001));
assertThat(filter.distance(), closeTo(12, 0.00001)); assertThat(filter.distance(), closeTo(12, 0.00001));
} }
@Test public void testGeoDistanceFilter9() throws IOException {
IndexQueryParser queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance9.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 testGeoDistanceFilter10() throws IOException {
IndexQueryParser queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance10.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 testGeoDistanceFilter11() throws IOException {
IndexQueryParser queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_distance11.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 { @Test public void testGeoBoundingBoxFilterNamed() throws IOException {
IndexQueryParser queryParser = queryParser(); IndexQueryParser queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox-named.json"); 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" : 19.312128,
"unit": "km",
"person.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}

View File

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

View File

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