You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ds...@apache.org on 2015/01/15 17:09:18 UTC

svn commit: r1652156 - in /lucene/dev/branches/branch_5x: ./ lucene/ lucene/spatial/ lucene/spatial/src/java/org/apache/lucene/spatial/prefix/

Author: dsmiley
Date: Thu Jan 15 16:09:18 2015
New Revision: 1652156

URL: http://svn.apache.org/r1652156
Log:
LUCENE-6182: spatial refactor VisitorTemplate.visitScanned needn't be abstract.
And have collectDocs specify BitSet not FixedBitSet.  (these are internal APIs)

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/lucene/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/   (props changed)
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeFilter.java
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractVisitingPrefixTreeFilter.java
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java
    lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeFilter.java?rev=1652156&r1=1652155&r2=1652156&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractPrefixTreeFilter.java Thu Jan 15 16:09:18 2015
@@ -17,23 +17,21 @@ package org.apache.lucene.spatial.prefix
  * limitations under the License.
  */
 
+import java.io.IOException;
+
 import com.spatial4j.core.shape.Shape;
+import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.LeafReader;
 import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.Terms;
 import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.search.Filter;
 import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
+import org.apache.lucene.util.BitSet;
 import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.FixedBitSet;
-
-import java.io.IOException;
 
 /**
  * Base class for Lucene Filters on SpatialPrefixTree fields.
- *
  * @lucene.experimental
  */
 public abstract class AbstractPrefixTreeFilter extends Filter {
@@ -73,14 +71,15 @@ public abstract class AbstractPrefixTree
   }
 
   /** Holds transient state and docid collecting utility methods as part of
-   * traversing a {@link TermsEnum}. */
-  public abstract class BaseTermsEnumTraverser {
+   * traversing a {@link TermsEnum} for a {@link org.apache.lucene.index.LeafReaderContext}. */
+  public abstract class BaseTermsEnumTraverser {//TODO rename to LeafTermsEnumTraverser ?
+    //note: only 'fieldName' (accessed in constructor) keeps this from being a static inner class
 
     protected final LeafReaderContext context;
     protected Bits acceptDocs;
     protected final int maxDoc;
 
-    protected TermsEnum termsEnum;//remember to check for null in getDocIdSet
+    protected TermsEnum termsEnum;//remember to check for null!
     protected DocsEnum docsEnum;
 
     public BaseTermsEnumTraverser(LeafReaderContext context, Bits acceptDocs) throws IOException {
@@ -93,32 +92,12 @@ public abstract class AbstractPrefixTree
         this.termsEnum = terms.iterator(null);
     }
 
-    protected void collectDocs(FixedBitSet bitSet) throws IOException {
-      //WARN: keep this specialization in sync
+    protected void collectDocs(BitSet bitSet) throws IOException {
       assert termsEnum != null;
       docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
-      int docid;
-      while ((docid = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
-        bitSet.set(docid);
-      }
+      bitSet.or(docsEnum);
     }
 
-    /* Eventually uncomment when needed.
-
-    protected void collectDocs(Collector collector) throws IOException {
-      //WARN: keep this specialization in sync
-      assert termsEnum != null;
-      docsEnum = termsEnum.docs(acceptDocs, docsEnum, DocsEnum.FLAG_NONE);
-      int docid;
-      while ((docid = docsEnum.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) {
-        collector.collect(docid);
-      }
-    }
-
-    public abstract class Collector {
-      abstract void collect(int docid) throws IOException;
-    }
-    */
   }
 
 }

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractVisitingPrefixTreeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractVisitingPrefixTreeFilter.java?rev=1652156&r1=1652155&r2=1652156&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractVisitingPrefixTreeFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/AbstractVisitingPrefixTreeFilter.java Thu Jan 15 16:09:18 2015
@@ -17,6 +17,9 @@ package org.apache.lucene.spatial.prefix
  * limitations under the License.
  */
 
+import java.io.IOException;
+import java.util.Iterator;
+
 import com.spatial4j.core.shape.Shape;
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.index.TermsEnum;
@@ -27,9 +30,6 @@ import org.apache.lucene.spatial.prefix.
 import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 
-import java.io.IOException;
-import java.util.Iterator;
-
 /**
  * Traverses a {@link SpatialPrefixTree} indexed field, using the template and
  * visitor design patterns for subclasses to guide the traversal and collect
@@ -326,17 +326,21 @@ public abstract class AbstractVisitingPr
     protected abstract DocIdSet finish() throws IOException;
 
     /**
-     * Visit an indexed cell returned from
-     * {@link #findSubCellsToVisit(org.apache.lucene.spatial.prefix.tree.Cell)}.
+     * Visit an indexed non-leaf cell returned from
+     * {@link #findSubCellsToVisit(org.apache.lucene.spatial.prefix.tree.Cell)}
+     * that is also found in the index.
+     * It will also be called by the default implementation of
+     * {@link #visitScanned(org.apache.lucene.spatial.prefix.tree.Cell)} for
+     * cells at the bottom detail level.
      *
-     * @param cell An intersecting cell.
+     * @param cell An intersecting cell; not a leaf.
      * @return true to descend to more levels. It is an error to return true
      * if cell.level == detailLevel
      */
     protected abstract boolean visit(Cell cell) throws IOException;
 
     /**
-     * Called after visit() returns true and an indexed leaf cell is found. An
+     * Called when an indexed leaf cell is found. An
      * indexed leaf cell means associated documents generally won't be found at
      * further detail levels.
      */
@@ -345,8 +349,19 @@ public abstract class AbstractVisitingPr
     /**
      * The cell is either indexed as a leaf or is the last level of detail. It
      * might not even intersect the query shape, so be sure to check for that.
+     * The default implementation will check that and if passes then call
+     * {@link #visitLeaf(org.apache.lucene.spatial.prefix.tree.Cell)} or
+     * {@link #visit(org.apache.lucene.spatial.prefix.tree.Cell)}.
      */
-    protected abstract void visitScanned(Cell cell) throws IOException;
+    protected void visitScanned(Cell cell) throws IOException {
+      if (queryShape.relate(cell.getShape()).intersects()) {
+        if (cell.isLeaf()) {
+          visitLeaf(cell);
+        } else {
+          visit(cell);
+        }
+      }
+    }
 
     protected void preSiblings(VNode vNode) throws IOException {
     }

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java?rev=1652156&r1=1652155&r2=1652156&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/IntersectsPrefixTreeFilter.java Thu Jan 15 16:09:18 2015
@@ -17,19 +17,18 @@ package org.apache.lucene.spatial.prefix
  * limitations under the License.
  */
 
+import java.io.IOException;
+
 import com.spatial4j.core.shape.Shape;
 import com.spatial4j.core.shape.SpatialRelation;
-
 import org.apache.lucene.index.LeafReaderContext;
 import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.spatial.prefix.tree.Cell;
 import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
-import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BitDocIdSet;
+import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.FixedBitSet;
 
-import java.io.IOException;
-
 /**
  * A Filter matching documents that have an {@link SpatialRelation#INTERSECTS}
  * (i.e. not DISTINCT) relationship with a provided query shape.
@@ -90,12 +89,6 @@ public class IntersectsPrefixTreeFilter
         collectDocs(results);
       }
 
-      @Override
-      protected void visitScanned(Cell cell) throws IOException {
-        if (queryShape.relate(cell.getShape()).intersects())
-          collectDocs(results);
-      }
-
     }.getDocIdSet();
   }
 

Modified: lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java?rev=1652156&r1=1652155&r2=1652156&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java (original)
+++ lucene/dev/branches/branch_5x/lucene/spatial/src/java/org/apache/lucene/spatial/prefix/WithinPrefixTreeFilter.java Thu Jan 15 16:09:18 2015
@@ -19,15 +19,6 @@ package org.apache.lucene.spatial.prefix
 
 import java.io.IOException;
 
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.search.DocIdSet;
-import org.apache.lucene.spatial.prefix.tree.Cell;
-import org.apache.lucene.spatial.prefix.tree.CellIterator;
-import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
-import org.apache.lucene.util.Bits;
-import org.apache.lucene.util.BitDocIdSet;
-import org.apache.lucene.util.FixedBitSet;
-
 import com.spatial4j.core.context.SpatialContext;
 import com.spatial4j.core.distance.DistanceUtils;
 import com.spatial4j.core.shape.Circle;
@@ -35,6 +26,14 @@ import com.spatial4j.core.shape.Point;
 import com.spatial4j.core.shape.Rectangle;
 import com.spatial4j.core.shape.Shape;
 import com.spatial4j.core.shape.SpatialRelation;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.search.DocIdSet;
+import org.apache.lucene.spatial.prefix.tree.Cell;
+import org.apache.lucene.spatial.prefix.tree.CellIterator;
+import org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree;
+import org.apache.lucene.util.BitDocIdSet;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.FixedBitSet;
 
 /**
  * Finds docs where its indexed shape is {@link org.apache.lucene.spatial.query.SpatialOperation#IsWithin
@@ -165,7 +164,10 @@ public class WithinPrefixTreeFilter exte
 
       @Override
       protected void visitLeaf(Cell cell) throws IOException {
-        //visitRelation is declared as a field, populated by visit() so we don't recompute it
+        //visitRelation is declared as a field, populated by visit() so we don't recompute it.
+        // We have a specialized visitScanned() which doesn't call this. If we didn't, we would
+        // not be able to assume visitRelation is from a prior visit() call since in scanning,
+        // parent cells aren't visited.
         assert detailLevel != cell.getLevel();
         assert visitRelation == cell.getShape().relate(queryShape);
         if (allCellsIntersectQuery(cell, visitRelation))
@@ -199,6 +201,7 @@ public class WithinPrefixTreeFilter exte
 
       @Override
       protected void visitScanned(Cell cell) throws IOException {
+        //slightly optimize over default impl; required for our 'visitRelation' field re-use above
         if (allCellsIntersectQuery(cell, null)) {
           collectDocs(inside);
         } else {