private void assertGeoPointQuery(GeoDistanceRangeQueryBuilder queryBuilder, Query query) throws IOException { assertThat(query, instanceOf(XGeoPointDistanceRangeQuery.class)); XGeoPointDistanceRangeQuery geoQuery = (XGeoPointDistanceRangeQuery) query; assertThat(geoQuery.getField(), equalTo(queryBuilder.fieldName())); if (queryBuilder.point() != null) { GeoPoint expectedPoint = new GeoPoint(queryBuilder.point()); GeoUtils.normalizePoint(expectedPoint); assertThat(geoQuery.getCenterLat(), equalTo(expectedPoint.lat())); assertThat(geoQuery.getCenterLon(), equalTo(expectedPoint.lon())); } if (queryBuilder.from() != null && queryBuilder.from() instanceof Number) { double fromValue = ((Number) queryBuilder.from()).doubleValue(); if (queryBuilder.unit() != null) { fromValue = queryBuilder.unit().toMeters(fromValue); } assertThat(geoQuery.getMinRadiusMeters(), closeTo(fromValue, 1E-5)); } if (queryBuilder.to() != null && queryBuilder.to() instanceof Number) { double toValue = ((Number) queryBuilder.to()).doubleValue(); if (queryBuilder.unit() != null) { toValue = queryBuilder.unit().toMeters(toValue); } assertThat(geoQuery.getMaxRadiusMeters(), closeTo(toValue, 1E-5)); } }
private void assertLegacyQuery(GeoDistanceRangeQueryBuilder queryBuilder, Query query) throws IOException { assertThat(query, instanceOf(GeoDistanceRangeQuery.class)); GeoDistanceRangeQuery geoQuery = (GeoDistanceRangeQuery) query; assertThat(geoQuery.fieldName(), equalTo(queryBuilder.fieldName())); if (queryBuilder.point() != null) { GeoPoint expectedPoint = new GeoPoint(queryBuilder.point()); if (GeoValidationMethod.isCoerce(queryBuilder.getValidationMethod())) { GeoUtils.normalizePoint(expectedPoint, true, true); } assertThat(geoQuery.lat(), equalTo(expectedPoint.lat())); assertThat(geoQuery.lon(), equalTo(expectedPoint.lon())); } assertThat(geoQuery.geoDistance(), equalTo(queryBuilder.geoDistance())); if (queryBuilder.from() != null && queryBuilder.from() instanceof Number) { double fromValue = ((Number) queryBuilder.from()).doubleValue(); if (queryBuilder.unit() != null) { fromValue = queryBuilder.unit().toMeters(fromValue); } if (queryBuilder.geoDistance() != null) { fromValue = queryBuilder.geoDistance().normalize(fromValue, DistanceUnit.DEFAULT); } double fromSlop = Math.abs(fromValue) / 1000; if (queryBuilder.includeLower() == false) { fromSlop = NumericUtils.sortableLongToDouble( (NumericUtils.doubleToSortableLong(Math.abs(fromValue)) + 1L)) / 1000.0; } assertThat(geoQuery.minInclusiveDistance(), closeTo(fromValue, fromSlop)); } if (queryBuilder.to() != null && queryBuilder.to() instanceof Number) { double toValue = ((Number) queryBuilder.to()).doubleValue(); if (queryBuilder.unit() != null) { toValue = queryBuilder.unit().toMeters(toValue); } if (queryBuilder.geoDistance() != null) { toValue = queryBuilder.geoDistance().normalize(toValue, DistanceUnit.DEFAULT); } double toSlop = Math.abs(toValue) / 1000; if (queryBuilder.includeUpper() == false) { toSlop = NumericUtils.sortableLongToDouble( (NumericUtils.doubleToSortableLong(Math.abs(toValue)) - 1L)) / 1000.0; } assertThat(geoQuery.maxInclusiveDistance(), closeTo(toValue, toSlop)); } }