Class FilteredQuery

  • All Implemented Interfaces:
    java.lang.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
    • Field Detail

      • LEAP_FROG_FILTER_FIRST_STRATEGY

        public static final FilteredQuery.FilterStrategy 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

        public static final FilteredQuery.FilterStrategy 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

        public static final FilteredQuery.FilterStrategy QUERY_FIRST_FILTER_STRATEGY
        A filter strategy that advances the Query or rather its Scorer first and consults the filter DocIdSet for each matched document.

        Note: this strategy requires a DocIdSet.bits() to return a non-null value. Otherwise this strategy falls back to LEAP_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.

    • Method Detail

      • createWeight

        public Weight createWeight​(IndexSearcher searcher)
                            throws java.io.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:
        java.io.IOException
      • rewrite

        public Query rewrite​(IndexReader reader)
                      throws java.io.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:
        java.io.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​(java.util.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 java.lang.String toString​(java.lang.String s)
        Prints a user-readable version of this query.
        Specified by:
        toString in class Query
      • equals

        public boolean equals​(java.lang.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