Package org.apache.lucene.document
Class ShapeQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.document.ShapeQuery
-
- Direct Known Subclasses:
LatLonShapeBoundingBoxQuery
,LatLonShapeLineQuery
,LatLonShapePolygonQuery
,XYShapeBoundingBoxQuery
,XYShapeLineQuery
,XYShapePolygonQuery
abstract class ShapeQuery extends Query
Base query class for all spatial geometries:LatLonShape
andXYShape
.The field must be indexed using either
LatLonShape.createIndexableFields(java.lang.String, org.apache.lucene.geo.Polygon)
orXYShape.createIndexableFields(java.lang.String, org.apache.lucene.geo.XYPolygon)
and the corresponding factory method must be used:newBoxQuery()
for matching geo shapes that have someShapeField.QueryRelation
with a bounding box.newLineQuery()
for matching geo shapes that have someShapeField.QueryRelation
with a linestring.newPolygonQuery()
for matching geo shapes that have someShapeField.QueryRelation
with a polygon.newBoxQuery()
for matching cartesian shapes that have someShapeField.QueryRelation
with a bounding box.newLineQuery()
for matching cartesian shapes that have someShapeField.QueryRelation
with a linestring.newPolygonQuery()
for matching cartesian shapes that have someShapeField.QueryRelation
with a polygon.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ShapeQuery.RelationScorerSupplier
utility class for implementing constant score logic specific to INTERSECT, WITHIN, and DISJOINT
-
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
ShapeQuery(java.lang.String field, ShapeField.QueryRelation queryType)
-
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)
private static PointValues.IntersectVisitor
getContainsDenseVisitor(ShapeQuery query, 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(ShapeQuery query, 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(ShapeQuery query)
create a visitor for calculating point count estimates for the provided relationjava.lang.String
getField()
returns the field nameprivate static PointValues.IntersectVisitor
getInverseDenseVisitor(ShapeQuery query, 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(ShapeQuery query, 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(ShapeQuery query, DocIdSetBuilder result)
create a visitor that adds documents that match the query using a sparse bitset.private static boolean
hasAnyHits(ShapeQuery query, 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 abstract boolean
queryMatches(byte[] triangle, ShapeField.DecodedTriangle scratchTriangle, ShapeField.QueryRelation queryRelation)
returns true if the provided triangle matches the queryprotected abstract Component2D.WithinRelation
queryWithin(byte[] triangle, ShapeField.DecodedTriangle scratchTriangle)
Return the within relationship between the query and the indexed shape.protected abstract PointValues.Relation
relateRangeBBoxToQuery(int minXOffset, int minYOffset, byte[] minTriangle, int maxXOffset, int maxYOffset, byte[] maxTriangle)
relates an internal node (bounding box of a range of triangles) to the target query Note: logic is specific to query type seerelateRangeToQuery(byte[], byte[], org.apache.lucene.document.ShapeField.QueryRelation)
andrelateRangeToQuery(byte[], byte[], org.apache.lucene.document.ShapeField.QueryRelation)
protected PointValues.Relation
relateRangeToQuery(byte[] minTriangle, byte[] maxTriangle, ShapeField.QueryRelation queryRelation)
relates a range of triangles (internal node) to the queryprivate 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
-
ShapeQuery
protected ShapeQuery(java.lang.String field, ShapeField.QueryRelation queryType)
-
-
Method Detail
-
relateRangeBBoxToQuery
protected abstract PointValues.Relation relateRangeBBoxToQuery(int minXOffset, int minYOffset, byte[] minTriangle, int maxXOffset, int maxYOffset, byte[] maxTriangle)
relates an internal node (bounding box of a range of triangles) to the target query Note: logic is specific to query type seerelateRangeToQuery(byte[], byte[], org.apache.lucene.document.ShapeField.QueryRelation)
andrelateRangeToQuery(byte[], byte[], org.apache.lucene.document.ShapeField.QueryRelation)
-
queryMatches
protected abstract boolean queryMatches(byte[] triangle, ShapeField.DecodedTriangle scratchTriangle, ShapeField.QueryRelation queryRelation)
returns true if the provided triangle matches the query
-
queryWithin
protected abstract Component2D.WithinRelation queryWithin(byte[] triangle, ShapeField.DecodedTriangle scratchTriangle)
Return the within relationship between the query and the indexed shape.
-
relateRangeToQuery
protected PointValues.Relation relateRangeToQuery(byte[] minTriangle, byte[] maxTriangle, ShapeField.QueryRelation queryRelation)
relates a range of triangles (internal node) to the query
-
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)
-
transposeRelation
private 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(ShapeQuery query)
create a visitor for calculating point count estimates for the provided relation
-
getSparseVisitor
private static PointValues.IntersectVisitor getSparseVisitor(ShapeQuery query, DocIdSetBuilder result)
create a visitor that adds documents that match the query using a sparse bitset. (Used by INTERSECT)
-
getDenseVisitor
private static PointValues.IntersectVisitor getDenseVisitor(ShapeQuery query, 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(ShapeQuery query, 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(ShapeQuery query, 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(ShapeQuery query, 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(ShapeQuery query, 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
-
-