Class SpanMultiTermQueryWrapper<Q extends MultiTermQuery>

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class SpanMultiTermQueryWrapper<Q extends MultiTermQuery>
    extends SpanQuery
    Wraps any MultiTermQuery as a SpanQuery, so it can be nested within other SpanQuery classes.

    The query is rewritten by default to a SpanOrQuery containing the expanded terms, but this can be customized.

    Example:

     
     WildcardQuery wildcard = new WildcardQuery(new Term("field", "bro?n"));
     SpanQuery spanWildcard = new SpanMultiTermQueryWrapper<WildcardQuery>(wildcard);
     // do something with spanWildcard, such as use it in a SpanFirstQuery
     
     
    • Constructor Detail

      • SpanMultiTermQueryWrapper

        public SpanMultiTermQueryWrapper​(Q query)
        Create a new SpanMultiTermQueryWrapper.
        Parameters:
        query - Query to wrap.

        NOTE: This will call MultiTermQuery.setRewriteMethod(MultiTermQuery.RewriteMethod) on the wrapped query, changing its rewrite method to a suitable one for spans. Be sure to not change the rewrite method on the wrapped query afterwards! Doing so will throw UnsupportedOperationException on rewriting this query!

    • Method Detail

      • getSpans

        public Spans getSpans​(AtomicReaderContext context,
                              Bits acceptDocs,
                              java.util.Map<Term,​TermContext> termContexts)
                       throws java.io.IOException
        Description copied from class: SpanQuery
        Expert: Returns the matches for this query in an index. Used internally to search for spans.
        Specified by:
        getSpans in class SpanQuery
        Throws:
        java.io.IOException
      • getField

        public java.lang.String getField()
        Description copied from class: SpanQuery
        Returns the name of the field matched by this query.

        Note that this may return null if the query matches no terms.

        Specified by:
        getField in class SpanQuery
      • getWrappedQuery

        public Query getWrappedQuery()
        Returns the wrapped query
      • toString

        public java.lang.String toString​(java.lang.String field)
        Description copied from class: Query
        Prints a query to a string, with field assumed to be the default field and omitted.
        Specified by:
        toString in class Query
      • rewrite

        public Query rewrite​(IndexReader reader)
                      throws java.io.IOException
        Description copied from class: Query
        Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
        Overrides:
        rewrite in class Query
        Throws:
        java.io.IOException
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Query
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class Query