GeoDistanceRangeQueryBuilder to not change its state when calling toQuery

The geoPoint gets normalized while calling toQuery. That should happen on a copy of the point though, the state of the request should never change as part of toQuery execution. Also updated corresponding test to support point normalization.

Closes 
This commit is contained in:
javanna 2015-10-07 12:53:19 +02:00 committed by Luca Cavanna
parent a024125f8d
commit 53f316b540
2 changed files with 8 additions and 2 deletions
core/src
main/java/org/elasticsearch/index/query
test/java/org/elasticsearch/index/query

View File

@ -221,6 +221,7 @@ public class GeoDistanceRangeQueryBuilder extends AbstractQueryBuilder<GeoDistan
} }
} }
GeoPoint point = new GeoPoint(this.point);
if (GeoValidationMethod.isCoerce(validationMethod)) { if (GeoValidationMethod.isCoerce(validationMethod)) {
GeoUtils.normalizePoint(point, true, true); GeoUtils.normalizePoint(point, true, true);
} }

View File

@ -22,6 +22,7 @@ package org.elasticsearch.index.query;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.common.geo.GeoDistance; import org.elasticsearch.common.geo.GeoDistance;
import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoPoint;
import org.elasticsearch.common.geo.GeoUtils;
import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.unit.DistanceUnit;
import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery; import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery;
import org.junit.Test; import org.junit.Test;
@ -108,8 +109,12 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase<GeoDistanc
GeoDistanceRangeQuery geoQuery = (GeoDistanceRangeQuery) query; GeoDistanceRangeQuery geoQuery = (GeoDistanceRangeQuery) query;
assertThat(geoQuery.fieldName(), equalTo(queryBuilder.fieldName())); assertThat(geoQuery.fieldName(), equalTo(queryBuilder.fieldName()));
if (queryBuilder.point() != null) { if (queryBuilder.point() != null) {
assertThat(geoQuery.lat(), equalTo(queryBuilder.point().lat())); GeoPoint expectedPoint = new GeoPoint(queryBuilder.point());
assertThat(geoQuery.lon(), equalTo(queryBuilder.point().lon())); 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())); assertThat(geoQuery.geoDistance(), equalTo(queryBuilder.geoDistance()));
if (queryBuilder.from() != null && queryBuilder.from() instanceof Number) { if (queryBuilder.from() != null && queryBuilder.from() instanceof Number) {