Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: Add checks to GeoDistanceQueryBuilderTests #34273

Merged
merged 3 commits into from
Oct 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void testParsingAndToQuery1() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery2() throws IOException {
Expand All @@ -166,7 +166,7 @@ public void testParsingAndToQuery2() throws IOException {
" \"" + GEO_POINT_FIELD_NAME + "\":[-70, 40]\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery3() throws IOException {
Expand All @@ -176,7 +176,7 @@ public void testParsingAndToQuery3() throws IOException {
" \"" + GEO_POINT_FIELD_NAME + "\":\"40, -70\"\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery4() throws IOException {
Expand All @@ -186,7 +186,8 @@ public void testParsingAndToQuery4() throws IOException {
" \"" + GEO_POINT_FIELD_NAME + "\":\"drn5x1g8cu2y\"\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
GeoPoint geoPoint = GeoPoint.fromGeohash("drn5x1g8cu2y");
assertGeoDistanceRangeQuery(query, geoPoint.getLat(), geoPoint.getLon(), 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery5() throws IOException {
Expand All @@ -200,7 +201,7 @@ public void testParsingAndToQuery5() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery6() throws IOException {
Expand All @@ -214,7 +215,7 @@ public void testParsingAndToQuery6() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

public void testParsingAndToQuery7() throws IOException {
Expand All @@ -227,7 +228,7 @@ public void testParsingAndToQuery7() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 0.012, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.DEFAULT);
}

public void testParsingAndToQuery8() throws IOException {
Expand All @@ -240,7 +241,7 @@ public void testParsingAndToQuery8() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.KILOMETERS);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.DEFAULT);
}

public void testParsingAndToQuery9() throws IOException {
Expand All @@ -254,7 +255,7 @@ public void testParsingAndToQuery9() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.KILOMETERS);
}

public void testParsingAndToQuery10() throws IOException {
Expand All @@ -268,7 +269,7 @@ public void testParsingAndToQuery10() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.KILOMETERS);
}

public void testParsingAndToQuery11() throws IOException {
Expand All @@ -281,7 +282,7 @@ public void testParsingAndToQuery11() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 19.312128, DistanceUnit.KILOMETERS);
}

public void testParsingAndToQuery12() throws IOException {
Expand All @@ -295,13 +296,16 @@ public void testParsingAndToQuery12() throws IOException {
" }\n" +
" }\n" +
"}\n";
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.DEFAULT);
assertGeoDistanceRangeQuery(query, 40, -70, 12, DistanceUnit.MILES);
}

private void assertGeoDistanceRangeQuery(String query, double lat, double lon, double distance, DistanceUnit distanceUnit)
throws IOException {
parseQuery(query).toQuery(createShardContext());
// TODO: what can we check? See https://github.com/elastic/elasticsearch/issues/34043
Query parsedQuery = parseQuery(query).toQuery(createShardContext());
cbuescher marked this conversation as resolved.
Show resolved Hide resolved
// The parsedQuery contains IndexOrDocValuesQuery, which wraps LatLonPointDistanceQuery which in turn has default visibility,
// so we cannot access its fields directly to check and have to use toString() here instead.
assertEquals(parsedQuery.toString(),
"mapped_geo_point:" + lat + "," + lon + " +/- " + distanceUnit.toMeters(distance) + " meters");
}

public void testFromJson() throws IOException {
Expand Down