You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by iv...@apache.org on 2019/07/17 12:14:22 UTC

[lucene-solr] branch master updated: LUCENE-8914: Move compare logic to IntersectVisitor in FloatPointNearestNeighbor (#783)

This is an automated email from the ASF dual-hosted git repository.

ivera pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/master by this push:
     new f026053  LUCENE-8914: Move compare logic to IntersectVisitor in FloatPointNearestNeighbor (#783)
f026053 is described below

commit f026053d4d8269c7f7135d8a76ffa21235a05d4b
Author: Ignacio Vera <iv...@apache.org>
AuthorDate: Wed Jul 17 14:14:17 2019 +0200

    LUCENE-8914: Move compare logic to IntersectVisitor in FloatPointNearestNeighbor (#783)
    
    Move the logic for discarding inner modes to the IntersectVisitor so we take advantage of the change introduced in LUCENE-7862
---
 lucene/CHANGES.txt                                 |  3 +++
 .../lucene/document/FloatPointNearestNeighbor.java | 31 +++++++++++-----------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 86f6e0f..94726d8 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -54,6 +54,9 @@ Improvements
 
 * 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
+  of the change introduced in LUCENE-7862. (Ignacio Vera)
+
 Other
 
 * LUCENE-8778 LUCENE-8911: Define analyzer SPI names as static final fields and document the names in Javadocs.
diff --git a/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java b/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java
index 38a4103..eb3db1a 100644
--- a/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java
+++ b/lucene/sandbox/src/java/org/apache/lucene/document/FloatPointNearestNeighbor.java
@@ -190,6 +190,18 @@ public class FloatPointNearestNeighbor {
 
     @Override
     public PointValues.Relation compare(byte[] minPackedValue, byte[] maxPackedValue) {
+      for (int d = 0, offset = 0; d < dims; ++d, offset += Float.BYTES) {
+        float cellMaxAtDim = FloatPoint.decodeDimension(maxPackedValue, offset);
+        if (cellMaxAtDim < min[d]) {
+          // System.out.println("  skipped because cell max at " + d + " (" + cellMaxAtDim + ") < visitor.min[" + d + "] (" + min[d] + ")");
+          return PointValues.Relation.CELL_OUTSIDE_QUERY;
+        }
+        float cellMinAtDim = FloatPoint.decodeDimension(minPackedValue, offset);
+        if (cellMinAtDim > max[d]) {
+          // System.out.println("  skipped because cell min at " + d + " (" + cellMinAtDim + ") > visitor.max[" + d + "] (" + max[d] + ")");
+          return PointValues.Relation.CELL_OUTSIDE_QUERY;
+        }
+      }
       return PointValues.Relation.CELL_CROSSES_QUERY;
     }
   }
@@ -243,7 +255,7 @@ public class FloatPointNearestNeighbor {
           approxBestDistanceSquared(minPackedValue, maxPackedValue, origin)));
     }
 
-    LOOP_OVER_CELLS: while (cellQueue.size() > 0) {
+    while (cellQueue.size() > 0) {
       Cell cell = cellQueue.poll();
       // System.out.println("  visit " + cell);
 
@@ -262,20 +274,9 @@ public class FloatPointNearestNeighbor {
         // Non-leaf block: split into two cells and put them back into the queue:
 
         if (hitQueue.size() == topN) {
-          for (int d = 0, offset = 0; d < visitor.dims; ++d, offset += Float.BYTES) {
-            float cellMaxAtDim = FloatPoint.decodeDimension(cell.maxPacked, offset);
-            float cellMinAtDim = FloatPoint.decodeDimension(cell.minPacked, offset);
-            if (cellMaxAtDim < visitor.min[d] || cellMinAtDim > visitor.max[d]) {
-              // this cell is outside our search radius; don't bother exploring any more
-
-              // if (cellMaxAtDim < visitor.min[d]) {
-              //   System.out.println("  skipped because cell max at " + d + " (" + cellMaxAtDim + ") < visitor.min[" + d + "] (" + visitor.min[d] + ")");
-              // } else {
-              //   System.out.println("  skipped because cell min at " + d + " (" + cellMinAtDim + ") > visitor.max[" + d + "] (" + visitor.max[d] + ")");
-              // }
-
-              continue LOOP_OVER_CELLS;
-            }
+          if (visitor.compare(cell.minPacked, cell.maxPacked) == PointValues.Relation.CELL_OUTSIDE_QUERY) {
+            // this cell is outside our search radius; don't bother exploring any more
+            continue;
           }
         }
         BytesRef splitValue = BytesRef.deepCopyOf(cell.index.getSplitDimValue());