org.apache.lucene.spatial
Class SpatialStrategy

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

public abstract class SpatialStrategy
extends Object

The SpatialStrategy encapsulates an approach to indexing and searching based on shapes.

Different implementations will support different features. A strategy should document these common elements:

Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes, which is immaterial to indexing & search.

Thread-safe.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Field Summary
protected  com.spatial4j.core.context.SpatialContext ctx
           
protected  boolean ignoreIncompatibleGeometry
           
 
Constructor Summary
SpatialStrategy(com.spatial4j.core.context.SpatialContext ctx, String fieldName)
          Constructs the spatial strategy with its mandatory arguments.
 
Method Summary
abstract  IndexableField[] createIndexableFields(com.spatial4j.core.shape.Shape shape)
          Returns the IndexableField(s) from the shape that are to be added to the Document.
 String getFieldName()
          The name of the field or the prefix of them if there are multiple fields needed internally.
 com.spatial4j.core.context.SpatialContext getSpatialContext()
           
 boolean isIgnoreIncompatibleGeometry()
           
abstract  Filter makeFilter(SpatialArgs args)
          Make a Filter
 Query makeQuery(SpatialArgs args)
          Make a query which has a score based on the distance from the data to the query shape.
abstract  ValueSource makeValueSource(SpatialArgs args)
          The value source yields a number that is proportional to the distance between the query shape and indexed data.
 void setIgnoreIncompatibleGeometry(boolean ignoreIncompatibleGeometry)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ignoreIncompatibleGeometry

protected boolean ignoreIncompatibleGeometry

ctx

protected final com.spatial4j.core.context.SpatialContext ctx
Constructor Detail

SpatialStrategy

public SpatialStrategy(com.spatial4j.core.context.SpatialContext ctx,
                       String fieldName)
Constructs the spatial strategy with its mandatory arguments.

Method Detail

getSpatialContext

public com.spatial4j.core.context.SpatialContext getSpatialContext()

getFieldName

public String getFieldName()
The name of the field or the prefix of them if there are multiple fields needed internally.

Returns:
Not null.

createIndexableFields

public abstract IndexableField[] createIndexableFields(com.spatial4j.core.shape.Shape shape)
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.

Returns:
Not null nor will it have null elements.

makeValueSource

public abstract ValueSource makeValueSource(SpatialArgs args)
The value source yields a number that is proportional to the distance between the query shape and indexed data.


makeQuery

public Query makeQuery(SpatialArgs args)
Make a query which has a score based on the distance from the data to the query shape. The default implementation constructs a FilteredQuery based on makeFilter(org.apache.lucene.spatial.query.SpatialArgs) and makeValueSource(org.apache.lucene.spatial.query.SpatialArgs).


makeFilter

public abstract Filter makeFilter(SpatialArgs args)
Make a Filter


isIgnoreIncompatibleGeometry

public boolean isIgnoreIncompatibleGeometry()

setIgnoreIncompatibleGeometry

public void setIgnoreIncompatibleGeometry(boolean ignoreIncompatibleGeometry)

toString

public String toString()
Overrides:
toString in class Object


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