org.apache.lucene.search.suggest.document

## Class CompletionQuery

- 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 `SuggestField`s or `ContextSuggestField`s 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.
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `CompletionQuery(Term term, BitsProducer filter)` Creates a base Completion query against a `term` with a `filter` to scope the documents

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `String` | `getField()` Returns the field name this query should be run against
    `BitsProducer` | `getFilter()` Returns a `BitsProducer`.
    `Term` | `getTerm()` Returns the term to be queried against
    `Query` | `rewrite(IndexReader reader)`
    `String` | `toString(String field)`

    - ### Methods inherited from class org.apache.lucene.search.Query

      `classHash, createWeight, equals, hashCode, sameClassAs, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### CompletionQuery

          protected CompletionQuery(Term term,
                                    BitsProducer filter)

      Creates a base Completion query against a `term` with a `filter` to scope the documents

  - ### Method Detail

    - #### 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

      Overrides:
        `rewrite` in class `Query`
      Throws:
        `IOException`

    - #### toString

          public String toString(String field)

      Specified by:
        `toString` in class `Query`

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