Package org.apache.lucene.spatial
Class SpatialStrategy
java.lang.Object
org.apache.lucene.spatial.SpatialStrategy
- Direct Known Subclasses:
BBoxStrategy
,CompositeSpatialStrategy
,PointVectorStrategy
,PrefixTreeStrategy
,SerializedDVStrategy
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:
- Can it index more than one shape per field?
- What types of shapes can be indexed?
- What types of query shapes can be used?
- What types of query operations are supported? This might vary per shape.
- Does it use some type of cache? When?
Note that a SpatialStrategy is not involved with the Lucene stored field values of shapes, which is immaterial to indexing and search.
Thread-safe.
This API is marked as experimental, however it is quite stable.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.locationtech.spatial4j.context.SpatialContext
-
Constructor Summary
ConstructorDescriptionSpatialStrategy
(org.locationtech.spatial4j.context.SpatialContext ctx, String fieldName) Constructs the spatial strategy with its mandatory arguments. -
Method Summary
Modifier and TypeMethodDescriptionabstract Field[]
createIndexableFields
(org.locationtech.spatial4j.shape.Shape shape) Returns the IndexableField(s) from theshape
that are to be added to theDocument
.The name of the field or the prefix of them if there are multiple fields needed internally.org.locationtech.spatial4j.context.SpatialContext
makeDistanceValueSource
(org.locationtech.spatial4j.shape.Point queryPoint) SeemakeDistanceValueSource(org.locationtech.spatial4j.shape.Point, double)
called with a multiplier of 1.0 (i.e.abstract DoubleValuesSource
makeDistanceValueSource
(org.locationtech.spatial4j.shape.Point queryPoint, double multiplier) Make a ValueSource returning the distance between the center of the indexed shape andqueryPoint
.abstract Query
makeQuery
(SpatialArgs args) final DoubleValuesSource
makeRecipDistanceValueSource
(org.locationtech.spatial4j.shape.Shape queryShape) Returns a ValueSource with values ranging from 1 to 0, depending inversely on the distance frommakeDistanceValueSource(org.locationtech.spatial4j.shape.Point,double)
.toString()
-
Field Details
-
ctx
protected final org.locationtech.spatial4j.context.SpatialContext ctx
-
-
Constructor Details
-
SpatialStrategy
Constructs the spatial strategy with its mandatory arguments.
-
-
Method Details
-
getSpatialContext
public org.locationtech.spatial4j.context.SpatialContext getSpatialContext() -
getFieldName
The name of the field or the prefix of them if there are multiple fields needed internally.- Returns:
- Not null.
-
createIndexableFields
Returns the IndexableField(s) from theshape
that are to be added to theDocument
. 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.
- Throws:
UnsupportedOperationException
- if given a shape incompatible with the strategy
-
makeDistanceValueSource
public DoubleValuesSource makeDistanceValueSource(org.locationtech.spatial4j.shape.Point queryPoint) SeemakeDistanceValueSource(org.locationtech.spatial4j.shape.Point, double)
called with a multiplier of 1.0 (i.e. units of degrees). -
makeDistanceValueSource
public abstract DoubleValuesSource makeDistanceValueSource(org.locationtech.spatial4j.shape.Point queryPoint, double multiplier) Make a ValueSource returning the distance between the center of the indexed shape andqueryPoint
. If there are multiple indexed shapes then the closest one is chosen. The result is multiplied bymultiplier
, which conveniently is used to get the desired units. -
makeQuery
Make a Query based principally onSpatialOperation
andShape
from the suppliedargs
. It should be constant scoring of 1.- Throws:
UnsupportedOperationException
- If the strategy does not support the shape inargs
UnsupportedSpatialOperation
- If the strategy does not support theSpatialOperation
inargs
.
-
makeRecipDistanceValueSource
public final DoubleValuesSource makeRecipDistanceValueSource(org.locationtech.spatial4j.shape.Shape queryShape) Returns a ValueSource with values ranging from 1 to 0, depending inversely on the distance frommakeDistanceValueSource(org.locationtech.spatial4j.shape.Point,double)
. The formula iszScaling/(d + zScaling)
where 'd' is the distance and 'zScaling' is one tenth the distance to the farthest edge from the center. Thus the scores will be 1 for indexed points at the center of the query shape and as low as ~0.1 at its furthest edges. -
toString
-