From 8c8b7bee3a2d71629484258f6bb625f526a2b046 Mon Sep 17 00:00:00 2001 From: Adriano Ferreira Date: Tue, 26 Oct 2010 14:05:38 -0200 Subject: [PATCH] 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 --- .../xcontent/SimpleIndexQueryParserTests.java | 40 +++++++++++++++++++ .../index/query/xcontent/geo_distance10.json | 17 ++++++++ .../index/query/xcontent/geo_distance11.json | 16 ++++++++ .../index/query/xcontent/geo_distance9.json | 17 ++++++++ 4 files changed, 90 insertions(+) create mode 100644 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance10.json create mode 100644 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance11.json create mode 100644 modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance9.json diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java index 3ee18a9515e..17fd52ad41e 100644 --- a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/SimpleIndexQueryParserTests.java @@ -1271,6 +1271,46 @@ public class SimpleIndexQueryParserTests { assertThat(filter.lon(), closeTo(-70, 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 { IndexQueryParser queryParser = queryParser(); String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/geo_boundingbox-named.json"); diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance10.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance10.json new file mode 100644 index 00000000000..6d08ae7e638 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance10.json @@ -0,0 +1,17 @@ +{ + "filtered" : { + "query" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : 19.312128, + "unit": "km", + "person.location" : { + "lat" : 40, + "lon" : -70 + } + } + } + } +} diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance11.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance11.json new file mode 100644 index 00000000000..77ebf781bc2 --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance11.json @@ -0,0 +1,16 @@ +{ + "filtered" : { + "query" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "19.312128km", + "person.location" : { + "lat" : 40, + "lon" : -70 + } + } + } + } +} diff --git a/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance9.json b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance9.json new file mode 100644 index 00000000000..2e62052516a --- /dev/null +++ b/modules/elasticsearch/src/test/java/org/elasticsearch/index/query/xcontent/geo_distance9.json @@ -0,0 +1,17 @@ +{ + "filtered" : { + "query" : { + "match_all" : {} + }, + "filter" : { + "geo_distance" : { + "distance" : "19.312128", + "unit": "km", + "person.location" : { + "lat" : 40, + "lon" : -70 + } + } + } + } +}