Apache Solr open-source search software
LUCENE-9552: make sure we don't construct Illegal rectangles due to quantization (#2131)
Ignacio Verabc854b262769
diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesPointInGeometryQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesPointInGeometryQuery.javaindex 3d6f25b9c04..04cb612dc10 100644--- a/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesPointInGeometryQuery.java+++ b/lucene/core/src/java/org/apache/lucene/document/LatLonDocValuesPointInGeometryQuery.java@@ -104,12 +104,28 @@ public class LatLonDocValuesPointInGeometryQuery extends Query {@Overridepublic Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {+ final Component2D tree = LatLonGeometry.create(geometries);++ if (tree.getMinY() > tree.getMaxY()) {+ // encodeLatitudeCeil may cause minY to be > maxY iff+ // the delta between the longitude < the encoding resolution+ return new ConstantScoreWeight(this, boost) {+ @Override+ public Scorer scorer(LeafReaderContext context) {+ return null;+ }- return new ConstantScoreWeight(this, boost) {-- final Component2D tree = LatLonGeometry.create(geometries);- final GeoEncodingUtils.Component2DPredicate component2DPredicate = GeoEncodingUtils.createComponentPredicate(tree);+ @Override+ public boolean isCacheable(LeafReaderContext ctx) {+ return false;+ }+ };+ }+ final GeoEncodingUtils.Component2DPredicate component2DPredicate = GeoEncodingUtils.createComponentPredicate(tree);++ return new ConstantScoreWeight(this, boost) {+@Overridepublic Scorer scorer(LeafReaderContext context) throws IOException {final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field);diff --git a/lucene/core/src/java/org/apache/lucene/document/LatLonPointInGeometryQuery.java b/lucene/core/src/java/org/apache/lucene/document/LatLonPointInGeometryQuery.javaindex adeba14e5d4..2d749cc7a3f 100644--- a/lucene/core/src/java/org/apache/lucene/document/LatLonPointInGeometryQuery.java+++ b/lucene/core/src/java/org/apache/lucene/document/LatLonPointInGeometryQuery.java@@ -142,8 +142,22 @@ final class LatLonPointInGeometryQuery extends Query {@Overridepublic Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {-final Component2D tree = LatLonGeometry.create(geometries);+ if (tree.getMinY() > tree.getMaxY()) {+ // encodeLatitudeCeil may cause minY to be > maxY iff+ // the delta between the longitude < the encoding resolution+ return new ConstantScoreWeight(this, boost) {+ @Override+ public Scorer scorer(LeafReaderContext context) {+ return null;+ }++ @Override+ public boolean isCacheable(LeafReaderContext ctx) {+ return false;+ }+ };+ }final GeoEncodingUtils.Component2DPredicate component2DPredicate = GeoEncodingUtils.createComponentPredicate(tree);// bounding box over all geometries, this can speed up tree intersection/cheaply improve approximation for complex multi-geometriesfinal byte minLat[] = new byte[Integer.BYTES];