java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.suggest.document.CompletionQuery
Direct Known Subclasses:
ContextQuery, PrefixCompletionQuery, RegexCompletionQuery

public abstract class CompletionQuery extends Query
Abstract Query that match documents containing terms with a specified prefix filtered by BitsProducer. This should be used to query against any SuggestFields or ContextSuggestFields of documents.

Use SuggestIndexSearcher.suggest(CompletionQuery, int, boolean) to execute any query that provides a concrete implementation of this query. Example below shows using this query to retrieve the top 5 documents.

  SuggestIndexSearcher searcher = new SuggestIndexSearcher(reader);
  TopSuggestDocs suggestDocs = searcher.suggest(query, 5);
 
This query rewrites to an appropriate CompletionQuery depending on the type (SuggestField or ContextSuggestField) of the field the query is run against.
  • Field Details

    • term

      private final Term term
      Term to query against
    • filter

      private final BitsProducer filter
      BitsProducer which is used to filter the document scope.
  • Constructor Details

    • CompletionQuery

      protected CompletionQuery(Term term, BitsProducer filter)
      Creates a base Completion query against a term with a filter to scope the documents
  • Method Details

    • getFilter

      public BitsProducer getFilter()
      Returns a BitsProducer. Only suggestions matching the returned bits will be returned.
    • getField

      public String getField()
      Returns the field name this query should be run against
    • getTerm

      public Term getTerm()
      Returns the term to be queried against
    • rewrite

      public Query rewrite(IndexReader reader) throws 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.

      Callers are expected to call rewrite multiple times if necessary, until the rewritten query is the same as the original query.

      Overrides:
      rewrite in class Query
      Throws:
      IOException
      See Also:
    • toString

      public String toString(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
    • validate

      private void validate(String termText)