Module org.apache.lucene.suggest
Class CompletionQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.suggest.document.CompletionQuery
- Direct Known Subclasses:
ContextQuery,PrefixCompletionQuery,RegexCompletionQuery
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final BitsProducerBitsProducerwhich is used to filter the document scope.private final TermTerm to query against -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCompletionQuery(Term term, BitsProducer filter) Creates a base Completion query against atermwith afilterto scope the documents -
Method Summary
Modifier and TypeMethodDescriptiongetField()Returns the field name this query should be run againstReturns aBitsProducer.getTerm()Returns the term to be queried againstrewrite(IndexSearcher indexSearcher) Expert: called to re-write queries into primitive queries.Prints a query to a string, withfieldassumed to be the default field and omitted.private voidMethods inherited from class org.apache.lucene.search.Query
classHash, createWeight, equals, hashCode, rewrite, sameClassAs, toString, visit
-
Field Details
-
term
Term to query against -
filter
BitsProducerwhich is used to filter the document scope.
-
-
Constructor Details
-
CompletionQuery
Creates a base Completion query against atermwith afilterto scope the documents
-
-
Method Details
-
getFilter
Returns aBitsProducer. Only suggestions matching the returned bits will be returned. -
getField
Returns the field name this query should be run against -
getTerm
Returns the term to be queried against -
rewrite
Description copied from class:QueryExpert: 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
rewritemultiple times if necessary, until the rewritten query is the same as the original query.The rewrite process may be able to make use of IndexSearcher's executor and be executed in parallel if the executor is provided.
However, if any of the intermediary queries do not satisfy the new API, parallel rewrite is not possible for any subsequent sub-queries. To take advantage of this API, the entire query tree must override this method.
- Overrides:
rewritein classQuery- Throws:
IOException- See Also:
-
toString
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted. -
validate
-