org.apache.lucene.search
Class FilteredQuery

java.lang.Object
  extended by org.apache.lucene.search.Query
      extended by org.apache.lucene.search.FilteredQuery
All Implemented Interfaces:
Cloneable

public class FilteredQuery
extends Query

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:
CachingWrapperFilter

Constructor Summary
FilteredQuery(Query query, Filter filter)
          Constructs a new query which applies a filter to the results of the original query.
 
Method Summary
 Weight createWeight(IndexSearcher searcher)
          Returns a Weight that applies the filter to the enclosed query's Weight.
 boolean equals(Object o)
          Returns true iff o is equal to this.
 void extractTerms(Set<Term> terms)
          Expert: adds all terms occurring in this query to the terms set.
 Filter getFilter()
          Returns this FilteredQuery's filter
 Query getQuery()
          Returns this FilteredQuery's (unfiltered) Query
 int hashCode()
          Returns a hash code value for this object.
 Query rewrite(IndexReader reader)
          Rewrites the query.
 String toString(String s)
          Prints a user-readable version of this query.
protected  boolean useRandomAccess(Bits bits, int firstFilterDoc)
          Expert: decides if a filter should be executed as "random-access" or not.
 
Methods inherited from class org.apache.lucene.search.Query
clone, getBoost, setBoost, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FilteredQuery

public FilteredQuery(Query query,
                     Filter filter)
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 be null.
filter - Filter to apply to query results, cannot be null.
Method Detail

useRandomAccess

protected boolean useRandomAccess(Bits bits,
                                  int firstFilterDoc)
Expert: decides if a filter should be executed as "random-access" or not. random-access means the filter "filters" in a similar way as deleted docs are filtered in lucene. This is faster when the filter accepts many documents. However, when the filter is very sparse, it can be faster to execute the query+filter as a conjunction in some cases. The default implementation returns true if the first document accepted by the filter is < 100.

WARNING: This API is experimental and might change in incompatible ways in the next release.
NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

createWeight

public Weight createWeight(IndexSearcher searcher)
                    throws IOException
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 class Query
Throws:
IOException

rewrite

public Query rewrite(IndexReader reader)
              throws IOException
Rewrites the query. If the wrapped is an instance of MatchAllDocsQuery it returns a ConstantScoreQuery. Otherwise it returns a new FilteredQuery wrapping the rewritten query.

Overrides:
rewrite in class Query
Throws:
IOException

getQuery

public final Query getQuery()
Returns this FilteredQuery's (unfiltered) Query


getFilter

public final Filter getFilter()
Returns this FilteredQuery's filter


extractTerms

public void extractTerms(Set<Term> terms)
Description copied from class: Query
Expert: adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten form.

Overrides:
extractTerms in class Query

toString

public String toString(String s)
Prints a user-readable version of this query.

Specified by:
toString in class Query

equals

public boolean equals(Object o)
Returns true iff o is equal to this.

Overrides:
equals in class Query

hashCode

public int hashCode()
Returns a hash code value for this object.

Overrides:
hashCode in class Query


Copyright © 2000-2012 Apache Software Foundation. All Rights Reserved.