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,LatLonPointandXYShape. 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 classSpatialQuery.RelationScorerSupplierutility class for implementing constant score logic specific to INTERSECT, WITHIN, and DISJOINTprotected static classSpatialQuery.SpatialVisitorVisitor used for walking the BKD tree.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Stringfieldfield name(package private) ShapeField.QueryRelationqueryRelationquery relation disjoint:ShapeField.QueryRelation.DISJOINT, intersects:ShapeField.QueryRelation.INTERSECTS, within:ShapeField.QueryRelation.DISJOINT, contains:ShapeField.QueryRelation.CONTAINS
-
Constructor Summary
Constructors Modifier Constructor Description protectedSpatialQuery(java.lang.String field, ShapeField.QueryRelation queryRelation)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description WeightcreateWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)Expert: Constructs an appropriate Weight implementation for this query.booleanequals(java.lang.Object o)Override and implement query instance equivalence properly in a subclass.protected booleanequalsTo(java.lang.Object o)class specific equals checkprivate static PointValues.IntersectVisitorgetContainsDenseVisitor(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.IntersectVisitorgetDenseVisitor(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.IntersectVisitorgetEstimateVisitor(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation)create a visitor for calculating point count estimates for the provided relationjava.lang.StringgetField()returns the field nameprivate static PointValues.IntersectVisitorgetIntersectsDenseVisitor(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.IntersectVisitorgetInverseDenseVisitor(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.QueryRelationgetQueryRelation()returns the query relationprivate static PointValues.IntersectVisitorgetShallowInverseDenseVisitor(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.IntersectVisitorgetSparseVisitor(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.SpatialVisitorgetSpatialVisitor()returns the spatial visitor to be used for this query.private static booleanhasAnyHits(SpatialQuery.SpatialVisitor spatialVisitor, ShapeField.QueryRelation queryRelation, PointValues values)Return true if the query matches at least one document.inthashCode()Override and implement query hash code properly in a subclass.protected static PointValues.RelationtransposeRelation(PointValues.Relation r)transpose the relation; INSIDE becomes OUTSIDE, OUTSIDE becomes INSIDE, CROSSES remains unchangedvoidvisit(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:QueryRecurse through the query tree, visiting any child queries
-
createWeight
public final Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)
Description copied from class:QueryExpert: Constructs an appropriate Weight implementation for this query.Only implemented by primitive queries, which re-write to themselves.
- Overrides:
createWeightin classQueryscoreMode- 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:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly.- Specified by:
hashCodein classQuery- See Also:
Query.equals(Object)
-
equals
public boolean equals(java.lang.Object o)
Description copied from class:QueryOverride and implement query instance equivalence properly in a subclass. This is required so thatQueryCacheworks 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:
equalsin 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
-
-