- All Implemented Interfaces:
public class BBoxOverlapRatioValueSource extends BBoxSimilarityValueSourceThe algorithm is implemented as envelope on envelope (rect on rect) overlays rather than complex polygon on complex polygon overlays.
Spatial relevance scoring algorithm:
- the area of the input query envelope
- the area of the target envelope (per Lucene document)
- the area of the intersection between the query and target envelopes
- A 0-1 factor that divides the score proportion between query and target. 0.5 is evenly.
- intersectionArea / queryArea; (see note)
- intersectionArea / targetArea; (see note)
- queryRatio * queryTargetProportion;
- targetRatio * (1 - queryTargetProportion);
- queryFactor + targetFactor;
minSideLengthmay be used whenever an area is calculated (queryArea, targetArea, intersectionArea). This allows for points or horizontal/vertical lines to be used as the query shape and in such case the descending order should have smallest boxes up front. Without this, a point or line query shape typically scores everything with the same value since there is 0 area.
Note: The actual computation of queryRatio and targetRatio is more complicated so that it considers points and lines. Lines have the ratio of overlap, and points are either 1.0 or 0.0 depending on whether it intersects or not.
Originally based on Geoportal's SpatialRankingValueSource but modified quite a bit. GeoPortal's algorithm will yield a score of 0 if either a line or point is compared, and it doesn't output a 0-1 normalized score (it multiplies the factors), and it doesn't support minSideLength, and it had dateline bugs.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
Constructors Constructor Description
BBoxOverlapRatioValueSource(ShapeValuesSource rectValueSource, boolean isGeo, org.locationtech.spatial4j.shape.Rectangle queryExtent, double queryTargetProportion, double minSideLength)
BBoxOverlapRatioValueSource(ShapeValuesSource rectValueSource, org.locationtech.spatial4j.shape.Rectangle queryExtent)Construct with 75% weighting towards target (roughly GeoPortal's default), geo degrees assumed, no minimum side length.
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
score(org.locationtech.spatial4j.shape.Rectangle target, AtomicReference<Explanation> exp)Return a relevancy score.
similarityDescription()A comma-separated list of configurable items of the subclass to put into
Methods inherited from class org.apache.lucene.spatial.bbox.BBoxSimilarityValueSource
explain, getValues, isCacheable, needsScores, rewrite, toString
Methods inherited from class org.apache.lucene.search.DoubleValuesSource
constant, fromDoubleField, fromField, fromFloatField, fromIntField, fromLongField, fromQuery, fromScorer, getSortField, toLongValuesSource
public BBoxOverlapRatioValueSource(ShapeValuesSource rectValueSource, boolean isGeo, org.locationtech.spatial4j.shape.Rectangle queryExtent, double queryTargetProportion, double minSideLength)
rectValueSource- mandatory; source of rectangles
isGeo- True if ctx.isGeo() and thus dateline issues should be attended to
queryExtent- mandatory; the query rectangle
queryTargetProportion- see class javadocs. Between 0 and 1.
minSideLength- see class javadocs. 0.0 will effectively disable.
public BBoxOverlapRatioValueSource(ShapeValuesSource rectValueSource, org.locationtech.spatial4j.shape.Rectangle queryExtent)
protected String similarityDescription()Description copied from class:
BBoxSimilarityValueSourceA comma-separated list of configurable items of the subclass to put into
protected double score(org.locationtech.spatial4j.shape.Rectangle target, AtomicReference<Explanation> exp)Description copied from class:
BBoxSimilarityValueSourceReturn a relevancy score. If
expis provided then diagnostic information is added.