org.apache.lucene.spatial.prefix
Class AbstractVisitingPrefixTreeFilter.VisitorTemplate

java.lang.Object
  extended by org.apache.lucene.spatial.prefix.AbstractPrefixTreeFilter.BaseTermsEnumTraverser
      extended by org.apache.lucene.spatial.prefix.AbstractVisitingPrefixTreeFilter.VisitorTemplate
Enclosing class:
AbstractVisitingPrefixTreeFilter

public abstract class AbstractVisitingPrefixTreeFilter.VisitorTemplate
extends AbstractPrefixTreeFilter.BaseTermsEnumTraverser

An abstract class designed to make it easy to implement predicates or other operations on a SpatialPrefixTree indexed field. An instance of this class is not designed to be re-used across AtomicReaderContext instances so simply create a new one for each call to, say a Filter.getDocIdSet(org.apache.lucene.index.AtomicReaderContext, org.apache.lucene.util.Bits). The getDocIdSet() method here starts the work. It first checks that there are indexed terms; if not it quickly returns null. Then it calls start() so a subclass can set up a return value, like an OpenBitSet. Then it starts the traversal process, calling findSubCellsToVisit(org.apache.lucene.spatial.prefix.tree.Node) which by default finds the top cells that intersect queryShape. If there isn't an indexed cell for a corresponding cell returned for this method then it's short-circuited until it finds one, at which point visit(org.apache.lucene.spatial.prefix.tree.Node) is called. At some depths, of the tree, the algorithm switches to a scanning mode that finds calls visitScanned(org.apache.lucene.spatial.prefix.tree.Node, com.spatial4j.core.shape.Shape) for each leaf cell found.

NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

Field Summary
protected  boolean hasIndexedLeaves
           
 
Fields inherited from class org.apache.lucene.spatial.prefix.AbstractPrefixTreeFilter.BaseTermsEnumTraverser
acceptDocs, context, docsEnum, maxDoc, termsEnum
 
Constructor Summary
AbstractVisitingPrefixTreeFilter.VisitorTemplate(AtomicReaderContext context, Bits acceptDocs, boolean hasIndexedLeaves)
           
 
Method Summary
protected  Iterator<Node> findSubCellsToVisit(Node cell)
          Called when doing a divide & conquer to find the next intersecting cells of the query shape that are beneath cell.
protected abstract  DocIdSet finish()
          Called last to return the result.
 DocIdSet getDocIdSet()
           
protected  void postSiblings(AbstractVisitingPrefixTreeFilter.VNode vNode)
           
protected  void preSiblings(AbstractVisitingPrefixTreeFilter.VNode vNode)
           
protected  void scan(int scanDetailLevel)
          Scans (termsEnum.next()) terms until a term is found that does not start with curVNode's cell.
protected abstract  void start()
          Called first to setup things.
protected abstract  boolean visit(Node cell)
          Visit an indexed cell returned from findSubCellsToVisit(org.apache.lucene.spatial.prefix.tree.Node).
protected abstract  void visitLeaf(Node cell)
          Called after visit() returns true and an indexed leaf cell is found.
protected abstract  void visitScanned(Node cell, com.spatial4j.core.shape.Shape cellShape)
          The cell is either indexed as a leaf or is the last level of detail.
 
Methods inherited from class org.apache.lucene.spatial.prefix.AbstractPrefixTreeFilter.BaseTermsEnumTraverser
collectDocs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hasIndexedLeaves

protected final boolean hasIndexedLeaves
Constructor Detail

AbstractVisitingPrefixTreeFilter.VisitorTemplate

public AbstractVisitingPrefixTreeFilter.VisitorTemplate(AtomicReaderContext context,
                                                        Bits acceptDocs,
                                                        boolean hasIndexedLeaves)
                                                 throws IOException
Throws:
IOException
Method Detail

getDocIdSet

public DocIdSet getDocIdSet()
                     throws IOException
Throws:
IOException

findSubCellsToVisit

protected Iterator<Node> findSubCellsToVisit(Node cell)
Called when doing a divide & conquer to find the next intersecting cells of the query shape that are beneath cell. cell is guaranteed to have an intersection and thus this must return some number of nodes.


scan

protected void scan(int scanDetailLevel)
             throws IOException
Scans (termsEnum.next()) terms until a term is found that does not start with curVNode's cell. If it finds a leaf cell or a cell at level scanDetailLevel then it calls visitScanned(org.apache.lucene.spatial.prefix.tree.Node, com.spatial4j.core.shape.Shape).

Throws:
IOException

start

protected abstract void start()
                       throws IOException
Called first to setup things.

Throws:
IOException

finish

protected abstract DocIdSet finish()
                            throws IOException
Called last to return the result.

Throws:
IOException

visit

protected abstract boolean visit(Node cell)
                          throws IOException
Visit an indexed cell returned from findSubCellsToVisit(org.apache.lucene.spatial.prefix.tree.Node).

Parameters:
cell - An intersecting cell.
Returns:
true to descend to more levels. It is an error to return true if cell.level == detailLevel
Throws:
IOException

visitLeaf

protected abstract void visitLeaf(Node cell)
                           throws IOException
Called after visit() returns true and an indexed leaf cell is found. An indexed leaf cell means associated documents generally won't be found at further detail levels.

Throws:
IOException

visitScanned

protected abstract void visitScanned(Node cell,
                                     com.spatial4j.core.shape.Shape cellShape)
                              throws IOException
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. Use cellShape instead of cell.getCellShape for the cell's shape.

Throws:
IOException

preSiblings

protected void preSiblings(AbstractVisitingPrefixTreeFilter.VNode vNode)
                    throws IOException
Throws:
IOException

postSiblings

protected void postSiblings(AbstractVisitingPrefixTreeFilter.VNode vNode)
                     throws IOException
Throws:
IOException


Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.