org.apache.lucene.spatial.prefix
Class PrefixTreeStrategy

java.lang.Object
  extended by org.apache.lucene.spatial.SpatialStrategy
      extended by org.apache.lucene.spatial.prefix.PrefixTreeStrategy
Direct Known Subclasses:
RecursivePrefixTreeStrategy, TermQueryPrefixTreeStrategy

public abstract class PrefixTreeStrategy
extends SpatialStrategy

An abstract SpatialStrategy based on SpatialPrefixTree. The two subclasses are RecursivePrefixTreeStrategy and TermQueryPrefixTreeStrategy. This strategy is most effective as a fast approximate spatial search filter.

Characteristics:

Implementation:

The SpatialPrefixTree does most of the work, for example returning a list of terms representing grids of various sizes for a supplied shape. An important configuration item is setDistErrPct(double) which balances shape precision against scalability. See those javadocs.

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

Field Summary
protected  int defaultFieldValuesArrayLen
           
protected  double distErrPct
           
static FieldType FIELD_TYPE
           
protected  SpatialPrefixTree grid
           
protected  boolean simplifyIndexedCells
           
 
Fields inherited from class org.apache.lucene.spatial.SpatialStrategy
ctx
 
Constructor Summary
PrefixTreeStrategy(SpatialPrefixTree grid, String fieldName, boolean simplifyIndexedCells)
           
 
Method Summary
 Field[] createIndexableFields(com.spatial4j.core.shape.Shape shape)
          Returns the IndexableField(s) from the shape that are to be added to the Document.
 Field[] createIndexableFields(com.spatial4j.core.shape.Shape shape, double distErr)
           
 double getDistErrPct()
           
 SpatialPrefixTree getGrid()
           
 ValueSource makeDistanceValueSource(com.spatial4j.core.shape.Point queryPoint)
          Make a ValueSource returning the distance between the center of the indexed shape and queryPoint.
 void setDefaultFieldValuesArrayLen(int defaultFieldValuesArrayLen)
          A memory hint used by makeDistanceValueSource(com.spatial4j.core.shape.Point) for how big the initial size of each Document's array should be.
 void setDistErrPct(double distErrPct)
          The default measure of shape precision affecting shapes at index and query times.
 
Methods inherited from class org.apache.lucene.spatial.SpatialStrategy
getFieldName, getSpatialContext, makeFilter, makeQuery, makeRecipDistanceValueSource, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

grid

protected final SpatialPrefixTree grid

simplifyIndexedCells

protected final boolean simplifyIndexedCells

defaultFieldValuesArrayLen

protected int defaultFieldValuesArrayLen

distErrPct

protected double distErrPct

FIELD_TYPE

public static final FieldType FIELD_TYPE
Constructor Detail

PrefixTreeStrategy

public PrefixTreeStrategy(SpatialPrefixTree grid,
                          String fieldName,
                          boolean simplifyIndexedCells)
Method Detail

setDefaultFieldValuesArrayLen

public void setDefaultFieldValuesArrayLen(int defaultFieldValuesArrayLen)
A memory hint used by makeDistanceValueSource(com.spatial4j.core.shape.Point) for how big the initial size of each Document's array should be. The default is 2. Set this to slightly more than the default expected number of points per document.


getDistErrPct

public double getDistErrPct()

setDistErrPct

public void setDistErrPct(double distErrPct)
The default measure of shape precision affecting shapes at index and query times. Points don't use this as they are always indexed at the configured maximum precision (SpatialPrefixTree.getMaxLevels()); this applies to all other shapes. Specific shapes at index and query time can use something different than this default value. If you don't set a default then the default is SpatialArgs.DEFAULT_DISTERRPCT -- 2.5%.

See Also:
SpatialArgs.getDistErrPct()

createIndexableFields

public Field[] createIndexableFields(com.spatial4j.core.shape.Shape shape)
Description copied from class: SpatialStrategy
Returns the IndexableField(s) from the shape that are to be added to the Document. These fields are expected to be marked as indexed and not stored.

Note: If you want to store the shape as a string for retrieval in search results, you could add it like this:

document.add(new StoredField(fieldName,ctx.toString(shape)));
The particular string representation used doesn't matter to the Strategy since it doesn't use it.

Specified by:
createIndexableFields in class SpatialStrategy
Returns:
Not null nor will it have null elements.

createIndexableFields

public Field[] createIndexableFields(com.spatial4j.core.shape.Shape shape,
                                     double distErr)

makeDistanceValueSource

public ValueSource makeDistanceValueSource(com.spatial4j.core.shape.Point queryPoint)
Description copied from class: SpatialStrategy
Make a ValueSource returning the distance between the center of the indexed shape and queryPoint. If there are multiple indexed shapes then the closest one is chosen.

Specified by:
makeDistanceValueSource in class SpatialStrategy

getGrid

public SpatialPrefixTree getGrid()


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