Package org.apache.lucene.spatial.bbox
Class BBoxOverlapRatioValueSource
java.lang.Object
org.apache.lucene.search.DoubleValuesSource
org.apache.lucene.spatial.bbox.BBoxSimilarityValueSource
org.apache.lucene.spatial.bbox.BBoxOverlapRatioValueSource
- All Implemented Interfaces:
SegmentCacheable
The algorithm is implemented as envelope on envelope (rect on rect) overlays rather than complex
polygon on complex polygon overlays.
Spatial relevance scoring algorithm:
- queryArea
- the area of the input query envelope
- targetArea
- the area of the target envelope (per Lucene document)
- intersectionArea
- the area of the intersection between the query and target envelopes
- queryTargetProportion
- A 0-1 factor that divides the score proportion between query and target. 0.5 is evenly.
- queryRatio
- intersectionArea / queryArea; (see note)
- targetRatio
- intersectionArea / targetArea; (see note)
- queryFactor
- queryRatio * queryTargetProportion;
- targetFactor
- targetRatio * (1 - queryTargetProportion);
- score
- queryFactor + targetFactor;
minSideLength
may 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.
-
Field Summary
Fields inherited from class org.apache.lucene.search.DoubleValuesSource
SCORES
-
Constructor Summary
ConstructorDescriptionBBoxOverlapRatioValueSource
(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. -
Method Summary
Modifier and TypeMethodDescriptionboolean
int
hashCode()
protected double
score
(org.locationtech.spatial4j.shape.Rectangle target, AtomicReference<Explanation> exp) Return a relevancy score.protected String
A comma-separated list of configurable items of the subclass to put intoBBoxSimilarityValueSource.toString()
.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, similarityToQueryVector, similarityToQueryVector, toLongValuesSource
-
Constructor Details
-
BBoxOverlapRatioValueSource
public BBoxOverlapRatioValueSource(ShapeValuesSource rectValueSource, boolean isGeo, org.locationtech.spatial4j.shape.Rectangle queryExtent, double queryTargetProportion, double minSideLength) - Parameters:
rectValueSource
- mandatory; source of rectanglesisGeo
- True if ctx.isGeo() and thus dateline issues should be attended toqueryExtent
- mandatory; the query rectanglequeryTargetProportion
- see class javadocs. Between 0 and 1.minSideLength
- see class javadocs. 0.0 will effectively disable.
-
BBoxOverlapRatioValueSource
public 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.
-
-
Method Details
-
equals
- Overrides:
equals
in classBBoxSimilarityValueSource
-
hashCode
public int hashCode()- Overrides:
hashCode
in classBBoxSimilarityValueSource
-
similarityDescription
Description copied from class:BBoxSimilarityValueSource
A comma-separated list of configurable items of the subclass to put intoBBoxSimilarityValueSource.toString()
.- Specified by:
similarityDescription
in classBBoxSimilarityValueSource
-
score
protected double score(org.locationtech.spatial4j.shape.Rectangle target, AtomicReference<Explanation> exp) Description copied from class:BBoxSimilarityValueSource
Return a relevancy score. Ifexp
is provided then diagnostic information is added.- Specified by:
score
in classBBoxSimilarityValueSource
- Parameters:
target
- The indexed rectangle; not null.exp
- Optional diagnostic holder.- Returns:
- a score.
-