Package org.apache.lucene.search
Class FilteredQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.FilteredQuery
- All Implemented Interfaces:
Cloneable
A query that applies a filter to the results of another query.
Note: the bits are retrieved from the filter each time this query is used in a search - use a CachingWrapperFilter to avoid regenerating the bits every time.
- Since:
- 1.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Abstract class that defines how the filter (DocIdSet
) applied during document collection.static class
AFilteredQuery.FilterStrategy
that conditionally uses a random access filter if the givenDocIdSet
supports random access (returns a non-null value fromDocIdSet.bits()
) andFilteredQuery.RandomAccessFilterStrategy.useRandomAccess(Bits, int)
returnstrue
. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FilteredQuery.FilterStrategy
A filter strategy that uses a "leap-frog" approach (also called "zig-zag join").static final FilteredQuery.FilterStrategy
A filter strategy that uses a "leap-frog" approach (also called "zig-zag join").static final FilteredQuery.FilterStrategy
static final FilteredQuery.FilterStrategy
AFilteredQuery.FilterStrategy
that conditionally uses a random access filter if the givenDocIdSet
supports random access (returns a non-null value fromDocIdSet.bits()
) andFilteredQuery.RandomAccessFilterStrategy.useRandomAccess(Bits, int)
returnstrue
. -
Constructor Summary
ConstructorsConstructorDescriptionFilteredQuery
(Query query, Filter filter) Constructs a new query which applies a filter to the results of the original query.FilteredQuery
(Query query, Filter filter, FilteredQuery.FilterStrategy strategy) Expert: Constructs a new query which applies a filter to the results of the original query. -
Method Summary
Modifier and TypeMethodDescriptioncreateWeight
(IndexSearcher searcher) Returns a Weight that applies the filter to the enclosed query's Weight.boolean
Returns true iffo
is equal to this.void
extractTerms
(Set<Term> terms) Expert: adds all terms occurring in this query to the terms set.final Filter
Returns this FilteredQuery's filterReturns this FilteredQuery'sFilteredQuery.FilterStrategy
final Query
getQuery()
Returns this FilteredQuery's (unfiltered) Queryint
hashCode()
Returns a hash code value for this object.rewrite
(IndexReader reader) Rewrites the query.Prints a user-readable version of this query.
-
Field Details
-
RANDOM_ACCESS_FILTER_STRATEGY
AFilteredQuery.FilterStrategy
that conditionally uses a random access filter if the givenDocIdSet
supports random access (returns a non-null value fromDocIdSet.bits()
) andFilteredQuery.RandomAccessFilterStrategy.useRandomAccess(Bits, int)
returnstrue
. Otherwise this strategy falls back to a "zig-zag join" (LEAP_FROG_FILTER_FIRST_STRATEGY
) strategy.Note: this strategy is the default strategy in
FilteredQuery
-
LEAP_FROG_FILTER_FIRST_STRATEGY
A filter strategy that uses a "leap-frog" approach (also called "zig-zag join"). The scorer and the filter take turns trying to advance to each other's next matching document, often jumping past the target document. When both land on the same document, it's collected.Note: This strategy uses the filter to lead the iteration.
-
LEAP_FROG_QUERY_FIRST_STRATEGY
A filter strategy that uses a "leap-frog" approach (also called "zig-zag join"). The scorer and the filter take turns trying to advance to each other's next matching document, often jumping past the target document. When both land on the same document, it's collected.Note: This strategy uses the query to lead the iteration.
-
QUERY_FIRST_FILTER_STRATEGY
A filter strategy that advances the Query or rather itsScorer
first and consults the filterDocIdSet
for each matched document.Note: this strategy requires a
DocIdSet.bits()
to return a non-null value. Otherwise this strategy falls back toLEAP_FROG_QUERY_FIRST_STRATEGY
Use this strategy if the filter computation is more expensive than document scoring or if the filter has a linear running time to compute the next matching doc like exact geo distances.
-
-
Constructor Details
-
FilteredQuery
Constructs a new query which applies a filter to the results of the original query.Filter.getDocIdSet(org.apache.lucene.index.AtomicReaderContext, org.apache.lucene.util.Bits)
will be called every time this query is used in a search.- Parameters:
query
- Query to be filtered, cannot benull
.filter
- Filter to apply to query results, cannot benull
.
-
FilteredQuery
Expert: Constructs a new query which applies a filter to the results of the original query.Filter.getDocIdSet(org.apache.lucene.index.AtomicReaderContext, org.apache.lucene.util.Bits)
will be called every time this query is used in a search.- Parameters:
query
- Query to be filtered, cannot benull
.filter
- Filter to apply to query results, cannot benull
.strategy
- a filter strategy used to create a filtered scorer.- See Also:
-
-
Method Details
-
createWeight
Returns a Weight that applies the filter to the enclosed query's Weight. This is accomplished by overriding the Scorer returned by the Weight.- Overrides:
createWeight
in classQuery
- Throws:
IOException
-
rewrite
Rewrites the query. If the wrapped is an instance ofMatchAllDocsQuery
it returns aConstantScoreQuery
. Otherwise it returns a newFilteredQuery
wrapping the rewritten query.- Overrides:
rewrite
in classQuery
- Throws:
IOException
-
getQuery
Returns this FilteredQuery's (unfiltered) Query -
getFilter
Returns this FilteredQuery's filter -
getFilterStrategy
Returns this FilteredQuery'sFilteredQuery.FilterStrategy
-
extractTerms
Description copied from class:Query
Expert: adds all terms occurring in this query to the terms set. Only works if this query is in itsrewritten
form.- Overrides:
extractTerms
in classQuery
-
toString
Prints a user-readable version of this query. -
equals
Returns true iffo
is equal to this. -
hashCode
public int hashCode()Returns a hash code value for this object.
-