LUCENE-9552: make sure we don't construct Illegal rectangles due to quantization (#2131)

This commit is contained in:
Ignacio Vera 2020-12-14 12:15:54 +01:00 committed by GitHub
parent 63943a739b
commit bc854b2627
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 5 deletions

View File

@ -104,12 +104,28 @@ public class LatLonDocValuesPointInGeometryQuery extends Query {
@Override @Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { public 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);
return new ConstantScoreWeight(this, boost) { return new ConstantScoreWeight(this, boost) {
final Component2D tree = LatLonGeometry.create(geometries);
final GeoEncodingUtils.Component2DPredicate component2DPredicate = GeoEncodingUtils.createComponentPredicate(tree);
@Override @Override
public Scorer scorer(LeafReaderContext context) throws IOException { public Scorer scorer(LeafReaderContext context) throws IOException {
final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field); final SortedNumericDocValues values = context.reader().getSortedNumericDocValues(field);

View File

@ -142,8 +142,22 @@ final class LatLonPointInGeometryQuery extends Query {
@Override @Override
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException { public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws IOException {
final Component2D tree = LatLonGeometry.create(geometries); 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); final GeoEncodingUtils.Component2DPredicate component2DPredicate = GeoEncodingUtils.createComponentPredicate(tree);
// bounding box over all geometries, this can speed up tree intersection/cheaply improve approximation for complex multi-geometries // bounding box over all geometries, this can speed up tree intersection/cheaply improve approximation for complex multi-geometries
final byte minLat[] = new byte[Integer.BYTES]; final byte minLat[] = new byte[Integer.BYTES];