mirror of https://github.com/apache/lucene.git
GeoPointField now validates incoming lat/lon
This commit is contained in:
parent
574da7667f
commit
6a5e935aa6
|
@ -16,13 +16,14 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.lucene.spatial.geopoint.document;
|
package org.apache.lucene.spatial.geopoint.document;
|
||||||
|
|
||||||
|
import org.apache.lucene.analysis.Analyzer;
|
||||||
|
import org.apache.lucene.analysis.TokenStream;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.FieldType;
|
import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.index.DocValuesType;
|
import org.apache.lucene.index.DocValuesType;
|
||||||
import org.apache.lucene.index.IndexOptions;
|
import org.apache.lucene.index.IndexOptions;
|
||||||
import org.apache.lucene.analysis.Analyzer;
|
|
||||||
import org.apache.lucene.analysis.TokenStream;
|
|
||||||
import org.apache.lucene.spatial.util.GeoEncodingUtils;
|
import org.apache.lucene.spatial.util.GeoEncodingUtils;
|
||||||
|
import org.apache.lucene.spatial.util.GeoUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -162,6 +163,14 @@ public final class GeoPointField extends Field {
|
||||||
public GeoPointField(String name, double lat, double lon, FieldType type) {
|
public GeoPointField(String name, double lat, double lon, FieldType type) {
|
||||||
super(name, type);
|
super(name, type);
|
||||||
|
|
||||||
|
if (GeoUtils.isValidLat(lat) == false) {
|
||||||
|
throw new IllegalArgumentException("invalid lat=" + lat + " for field \"" + name + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GeoUtils.isValidLon(lon) == false) {
|
||||||
|
throw new IllegalArgumentException("invalid lon=" + lon + " for field \"" + name + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
// field must be indexed
|
// field must be indexed
|
||||||
// todo does it make sense here to provide the ability to store a GeoPointField but not index?
|
// todo does it make sense here to provide the ability to store a GeoPointField but not index?
|
||||||
if (type.indexOptions() == IndexOptions.NONE && type.stored() == false) {
|
if (type.indexOptions() == IndexOptions.NONE && type.stored() == false) {
|
||||||
|
|
|
@ -237,4 +237,19 @@ public class TestGeoPointField extends LuceneTestCase {
|
||||||
TopDocs td = geoDistanceRangeQuery(0.0, 0.0, 10, 20000000, 20);
|
TopDocs td = geoDistanceRangeQuery(0.0, 0.0, 10, 20000000, 20);
|
||||||
assertEquals("GeoDistanceRangeQuery failed", 24, td.totalHits);
|
assertEquals("GeoDistanceRangeQuery failed", 24, td.totalHits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testInvalidLatLon() throws Exception {
|
||||||
|
IllegalArgumentException e;
|
||||||
|
e= expectThrows(IllegalArgumentException.class,
|
||||||
|
() -> {
|
||||||
|
new GeoPointField("field", 180.0, 0.0, Field.Store.NO);
|
||||||
|
});
|
||||||
|
assertEquals("invalid lat=180.0 for field \"field\"", e.getMessage());
|
||||||
|
|
||||||
|
e = expectThrows(IllegalArgumentException.class,
|
||||||
|
() -> {
|
||||||
|
new GeoPointField("field", 0.0, 190.0, Field.Store.NO);
|
||||||
|
});
|
||||||
|
assertEquals("invalid lon=190.0 for field \"field\"", e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue