public class BBoxStrategy extends SpatialStrategy
SpatialOperation
s and
has a custom overlap relevancy. It is based on GeoPortal's SpatialClauseAdapter.
Characteristics:
SpatialOperation
s but not Overlaps.Implementation:
This uses 4 double fields for minX, maxX, minY, maxY
and a boolean to mark a dateline cross. Depending on the particular SpatialOperation
s, there are a variety of range queries on DoublePoint
s to be
done.
The #makeOverlapRatioValueSource(org.locationtech.spatial4j.shape.Rectangle, double)
works by calculating the query bbox overlap percentage against the indexed
shape overlap percentage. The indexed shape's coordinates are retrieved from
LeafReader.getNumericDocValues(java.lang.String)
.
Modifier and Type | Field and Description |
---|---|
static FieldType |
DEFAULT_FIELDTYPE
pointValues, docValues, and nothing else.
|
static FieldType |
LEGACY_FIELDTYPE
Deprecated.
|
static String |
SUFFIX_MAXX |
static String |
SUFFIX_MAXY |
static String |
SUFFIX_MINX |
static String |
SUFFIX_MINY |
static String |
SUFFIX_XDL |
ctx
Constructor and Description |
---|
BBoxStrategy(SpatialContext ctx,
String fieldNamePrefix,
FieldType fieldType)
Creates this strategy.
|
Modifier and Type | Method and Description |
---|---|
Field[] |
createIndexableFields(Shape shape)
Returns the IndexableField(s) from the
shape that are to be
added to the Document . |
FieldType |
getFieldType()
Returns a field type representing the set of field options.
|
ValueSource |
makeDistanceValueSource(Point queryPoint,
double multiplier)
Make a ValueSource returning the distance between the center of the
indexed shape and
queryPoint . |
ValueSource |
makeOverlapRatioValueSource(Rectangle queryBox,
double queryTargetProportion)
Returns a similarity based on
BBoxOverlapRatioValueSource . |
Query |
makeQuery(SpatialArgs args)
|
ValueSource |
makeShapeValueSource()
Provides access to each rectangle per document as a ValueSource in which
FunctionValues.objectVal(int) returns a Shape . |
static BBoxStrategy |
newInstance(SpatialContext ctx,
String fieldNamePrefix)
Creates a new
BBoxStrategy instance that uses DoublePoint and DoublePoint.newRangeQuery(java.lang.String, double, double) |
static BBoxStrategy |
newLegacyInstance(SpatialContext ctx,
String fieldNamePrefix)
Deprecated.
LegacyNumerics will be removed
|
getFieldName, getSpatialContext, makeDistanceValueSource, makeRecipDistanceValueSource, toString
public static FieldType DEFAULT_FIELDTYPE
@Deprecated public static FieldType LEGACY_FIELDTYPE
public static final String SUFFIX_MINX
public static final String SUFFIX_MAXX
public static final String SUFFIX_MINY
public static final String SUFFIX_MAXY
public static final String SUFFIX_XDL
public BBoxStrategy(SpatialContext ctx, String fieldNamePrefix, FieldType fieldType)
fieldType
is used to customize the indexing options of the 4 number fields, and to a lesser degree the XDL
field too. Search requires pointValues (or legacy numerics), and relevancy requires docValues. If these features
aren't needed then disable them.public static BBoxStrategy newInstance(SpatialContext ctx, String fieldNamePrefix)
BBoxStrategy
instance that uses DoublePoint
and DoublePoint.newRangeQuery(java.lang.String, double, double)
@Deprecated public static BBoxStrategy newLegacyInstance(SpatialContext ctx, String fieldNamePrefix)
BBoxStrategy
instance that uses LegacyDoubleField
for backwards compatibilitypublic FieldType getFieldType()
public Field[] createIndexableFields(Shape shape)
SpatialStrategy
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.
createIndexableFields
in class SpatialStrategy
public ValueSource makeShapeValueSource()
FunctionValues.objectVal(int)
returns a Shape
.public ValueSource makeDistanceValueSource(Point queryPoint, double multiplier)
SpatialStrategy
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.makeDistanceValueSource
in class SpatialStrategy
public ValueSource makeOverlapRatioValueSource(Rectangle queryBox, double queryTargetProportion)
BBoxOverlapRatioValueSource
. This is just a
convenience method.public Query makeQuery(SpatialArgs args)
SpatialStrategy
SpatialOperation
and Shape
from the supplied args
. It should be constant scoring of 1.makeQuery
in class SpatialStrategy