Package org.apache.lucene.document
Class SpatialQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.document.SpatialQuery
-
- Direct Known Subclasses:
LatLonPointQuery
,LatLonShapeBoundingBoxQuery
,LatLonShapeQuery
,XYShapeQuery
abstract class SpatialQuery extends Query
Base query class for all spatial geometries:LatLonShape
,LatLonPoint
andXYShape
. In order to create a query, use the factory methods on those classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
SpatialQuery.RelationScorerSupplier
utility class for implementing constant score logic specific to INTERSECT, WITHIN, and DISJOINTprotected static class
SpatialQuery.SpatialVisitor
Visitor used for walking the BKD tree.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.String
field
field name(package private) ShapeField.QueryRelation
queryRelation
query relation disjoint:ShapeField.QueryRelation.DISJOINT
, intersects:ShapeField.QueryRelation.INTERSECTS
, within:ShapeField.QueryRelation.DISJOINT
, contains:ShapeField.QueryRelation.CONTAINS
-
Constructor Summary
Constructors Modifier Constructor Description protected
SpatialQuery(java.lang.String field, ShapeField.QueryRelation queryRelation)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Weight
createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
Expert: Constructs an appropriate Weight implementation for this query.boolean
equals(java.lang.Object o)
Override and implement query instance equivalence properly in a subclass.protected boolean
equalsTo(java.lang.Object o)
class specific equals checkprivate static PointValues.IntersectVisitor
getContainsDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, FixedBitSet excluded, long[] cost)
create a visitor that adds documents that match the query using a dense bitset; used with CONTAINSprivate static PointValues.IntersectVisitor
getDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, FixedBitSet excluded, long[] cost)
create a visitor that adds documents that match the query using a dense bitset; used with WITHIN & DISJOINTprivate static PointValues.IntersectVisitor
getEstimateVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation)
create a visitor for calculating point count estimates for the provided relationjava.lang.String
getField()
returns the field nameprivate static PointValues.IntersectVisitor
getIntersectsDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, long[] cost)
Scorer used for INTERSECTS when the number of points > 4 * number of docsprivate static PointValues.IntersectVisitor
getInverseDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, long[] cost)
create a visitor that clears documents that do not match the polygon query using a dense bitset; used with WITHIN & DISJOINTShapeField.QueryRelation
getQueryRelation()
returns the query relationprivate static PointValues.IntersectVisitor
getShallowInverseDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result)
create a visitor that clears documents that do not match the polygon query using a dense bitset; used with WITHIN & DISJOINT.private static PointValues.IntersectVisitor
getSparseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, DocIdSetBuilder result)
create a visitor that adds documents that match the query using a sparse bitset.protected abstract SpatialQuery.SpatialVisitor
getSpatialVisitor()
returns the spatial visitor to be used for this query.private static boolean
hasAnyHits(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, PointValues values)
Return true if the query matches at least one document.int
hashCode()
Override and implement query hash code properly in a subclass.protected static PointValues.Relation
transposeRelation(PointValues.Relation r)
transpose the relation; INSIDE becomes OUTSIDE, OUTSIDE becomes INSIDE, CROSSES remains unchangedvoid
visit(QueryVisitor visitor)
Recurse through the query tree, visiting any child queries
-
-
-
Field Detail
-
field
final java.lang.String field
field name
-
queryRelation
final ShapeField.QueryRelation queryRelation
query relation disjoint:ShapeField.QueryRelation.DISJOINT
, intersects:ShapeField.QueryRelation.INTERSECTS
, within:ShapeField.QueryRelation.DISJOINT
, contains:ShapeField.QueryRelation.CONTAINS
-
-
Constructor Detail
-
SpatialQuery
protected SpatialQuery(java.lang.String field, ShapeField.QueryRelation queryRelation)
-
-
Method Detail
-
getSpatialVisitor
protected abstract SpatialQuery.SpatialVisitor getSpatialVisitor()
returns the spatial visitor to be used for this query. Called before generating the queryWeight
-
visit
public void visit(QueryVisitor visitor)
Description copied from class:Query
Recurse through the query tree, visiting any child queries
-
createWeight
public final Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
Description copied from class:Query
Expert: Constructs an appropriate Weight implementation for this query.Only implemented by primitive queries, which re-write to themselves.
- Overrides:
createWeight
in classQuery
scoreMode
- How the produced scorers will be consumed.boost
- The boost that is propagated by the parent queries.
-
getField
public java.lang.String getField()
returns the field name
-
getQueryRelation
public ShapeField.QueryRelation getQueryRelation()
returns the query relation
-
hashCode
public int hashCode()
Description copied from class:Query
Override and implement query hash code properly in a subclass. This is required so thatQueryCache
works properly.- Specified by:
hashCode
in classQuery
- See Also:
Query.equals(Object)
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:Query
Override and implement query instance equivalence properly in a subclass. This is required so thatQueryCache
works properly. Typically a query will be equal to another only if it's an instance of the same class and its document-filtering properties are identical that other instance. Utility methods are provided for certain repetitive code.- Specified by:
equals
in classQuery
- See Also:
Query.sameClassAs(Object)
,Query.classHash()
-
equalsTo
protected boolean equalsTo(java.lang.Object o)
class specific equals check
-
transposeRelation
protected static PointValues.Relation transposeRelation(PointValues.Relation r)
transpose the relation; INSIDE becomes OUTSIDE, OUTSIDE becomes INSIDE, CROSSES remains unchanged
-
getEstimateVisitor
private static PointValues.IntersectVisitor getEstimateVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation)
create a visitor for calculating point count estimates for the provided relation
-
getSparseVisitor
private static PointValues.IntersectVisitor getSparseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, DocIdSetBuilder result)
create a visitor that adds documents that match the query using a sparse bitset. (Used by INTERSECT when the number of docs <= 4 * number of points )
-
getIntersectsDenseVisitor
private static PointValues.IntersectVisitor getIntersectsDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, long[] cost)
Scorer used for INTERSECTS when the number of points > 4 * number of docs
-
getDenseVisitor
private static PointValues.IntersectVisitor getDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, FixedBitSet excluded, long[] cost)
create a visitor that adds documents that match the query using a dense bitset; used with WITHIN & DISJOINT
-
getContainsDenseVisitor
private static PointValues.IntersectVisitor getContainsDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, FixedBitSet excluded, long[] cost)
create a visitor that adds documents that match the query using a dense bitset; used with CONTAINS
-
getInverseDenseVisitor
private static PointValues.IntersectVisitor getInverseDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result, long[] cost)
create a visitor that clears documents that do not match the polygon query using a dense bitset; used with WITHIN & DISJOINT
-
getShallowInverseDenseVisitor
private static PointValues.IntersectVisitor getShallowInverseDenseVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, FixedBitSet result)
create a visitor that clears documents that do not match the polygon query using a dense bitset; used with WITHIN & DISJOINT. This visitor only takes into account inner nodes
-
hasAnyHits
private static boolean hasAnyHits(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, PointValues values) throws java.io.IOException
Return true if the query matches at least one document. It creates a visitor that terminates as soon as one or more docs are matched.- Throws:
java.io.IOException
-
-