public abstract class SpatialStrategy extends Object
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 and search.
Thread-safe.
This API is marked as experimental, however it is quite stable.
| Modifier and Type | Field and Description |
|---|---|
protected com.spatial4j.core.context.SpatialContext |
ctx |
| Constructor and Description |
|---|
SpatialStrategy(com.spatial4j.core.context.SpatialContext ctx,
String fieldName)
Constructs the spatial strategy with its mandatory arguments.
|
| Modifier and Type | Method and Description |
|---|---|
abstract Field[] |
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() |
ValueSource |
makeDistanceValueSource(com.spatial4j.core.shape.Point queryPoint)
See
makeDistanceValueSource(com.spatial4j.core.shape.Point, double) called with
a multiplier of 1.0 (i.e. |
abstract ValueSource |
makeDistanceValueSource(com.spatial4j.core.shape.Point queryPoint,
double multiplier)
Make a ValueSource returning the distance between the center of the
indexed shape and
queryPoint. |
abstract Query |
makeQuery(SpatialArgs args)
|
ValueSource |
makeRecipDistanceValueSource(com.spatial4j.core.shape.Shape queryShape)
Returns a ValueSource with values ranging from 1 to 0, depending inversely
on the distance from
makeDistanceValueSource(com.spatial4j.core.shape.Point,double). |
String |
toString() |
public SpatialStrategy(com.spatial4j.core.context.SpatialContext ctx,
String fieldName)
public com.spatial4j.core.context.SpatialContext getSpatialContext()
public String getFieldName()
public abstract Field[] createIndexableFields(com.spatial4j.core.shape.Shape shape)
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.
UnsupportedOperationException - if given a shape incompatible with the strategypublic ValueSource makeDistanceValueSource(com.spatial4j.core.shape.Point queryPoint)
makeDistanceValueSource(com.spatial4j.core.shape.Point, double) called with
a multiplier of 1.0 (i.e. units of degrees).public abstract ValueSource makeDistanceValueSource(com.spatial4j.core.shape.Point queryPoint, double multiplier)
queryPoint. If there are multiple indexed shapes
then the closest one is chosen. The result is multiplied by multiplier, which
conveniently is used to get the desired units.public abstract Query makeQuery(SpatialArgs args)
SpatialOperation
and Shape from the supplied args. It should be constant scoring of 1.UnsupportedOperationException - If the strategy does not support the shape in argsUnsupportedSpatialOperation - If the strategy does not support the SpatialOperation in args.public final ValueSource makeRecipDistanceValueSource(com.spatial4j.core.shape.Shape queryShape)
makeDistanceValueSource(com.spatial4j.core.shape.Point,double).
The formula is c/(d + c) where 'd' is the distance and 'c' 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.Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.