LUCENE-8955: Move compare logic to IntersectVisitor in NearestNeighbor (#842)

This commit is contained in:
Ignacio Vera 2019-08-26 09:35:57 +02:00 committed by GitHub
parent 0ad8c1f302
commit ff1e2fa658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 9 deletions

View File

@ -88,8 +88,11 @@ Improvements
* LUCENE-8894: Add APIs to find SPI names for Tokenizer/CharFilter/TokenFilter factory classes. (Tomoko Uchida) * LUCENE-8894: Add APIs to find SPI names for Tokenizer/CharFilter/TokenFilter factory classes. (Tomoko Uchida)
* LUCENE-8914: move the logic for discarding inner modes to the IntersectVisitor so we take advantage * LUCENE-8914: move the logic for discarding inner modes in FloatPointNearestNeighbor to the IntersectVisitor
of the change introduced in LUCENE-7862. (Ignacio Vera) so we take advantage of the change introduced in LUCENE-7862. (Ignacio Vera)
* LUCENE-8955: move the logic for discarding inner modes in LatLonPoint NearestNeighbor to the IntersectVisitor
so we take advantage of the change introduced in LUCENE-7862. (Ignacio Vera)
* LUCENE-8918: PhraseQuery throws exceptions at construction time if it is passed * LUCENE-8918: PhraseQuery throws exceptions at construction time if it is passed
null arguments. (Alan Woodward) null arguments. (Alan Woodward)

View File

@ -182,6 +182,15 @@ class NearestNeighbor {
@Override @Override
public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) { public Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
double cellMinLat = decodeLatitude(minPackedValue, 0);
double cellMinLon = decodeLongitude(minPackedValue, Integer.BYTES);
double cellMaxLat = decodeLatitude(maxPackedValue, 0);
double cellMaxLon = decodeLongitude(maxPackedValue, Integer.BYTES);
if (cellMaxLat < minLat || maxLat < cellMinLat || ((cellMaxLon < minLon || maxLon < cellMinLon) && cellMaxLon < minLon2)) {
// this cell is outside our search bbox; don't bother exploring any more
return Relation.CELL_OUTSIDE_QUERY;
}
return Relation.CELL_CROSSES_QUERY; return Relation.CELL_CROSSES_QUERY;
} }
} }
@ -266,13 +275,7 @@ class NearestNeighbor {
//System.out.println(" non-leaf"); //System.out.println(" non-leaf");
// Non-leaf block: split into two cells and put them back into the queue: // Non-leaf block: split into two cells and put them back into the queue:
double cellMinLat = decodeLatitude(cell.minPacked, 0); if (visitor.compare(cell.minPacked, cell.maxPacked) == Relation.CELL_OUTSIDE_QUERY) {
double cellMinLon = decodeLongitude(cell.minPacked, Integer.BYTES);
double cellMaxLat = decodeLatitude(cell.maxPacked, 0);
double cellMaxLon = decodeLongitude(cell.maxPacked, Integer.BYTES);
if (cellMaxLat < visitor.minLat || visitor.maxLat < cellMinLat || ((cellMaxLon < visitor.minLon || visitor.maxLon < cellMinLon) && cellMaxLon < visitor.minLon2)) {
// this cell is outside our search bbox; don't bother exploring any more
continue; continue;
} }