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
AbstractQuerythat match documents containing terms with a specified prefix filtered byBitsProducer. This should be used to query against anySuggestFields orContextSuggestFields 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 appropriateCompletionQuerydepending on the type (SuggestFieldorContextSuggestField) of the field the query is run against.
-
-
Field Summary
Fields Modifier and Type Field Description private BitsProducerfilterBitsProducerwhich is used to filter the document scope.private TermtermTerm to query against
-
Constructor Summary
Constructors Modifier Constructor Description protectedCompletionQuery(Term term, BitsProducer filter)Creates a base Completion query against atermwith afilterto scope the documents
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetField()Returns the field name this query should be run againstBitsProducergetFilter()Returns aBitsProducer.TermgetTerm()Returns the term to be queried againstQueryrewrite(IndexReader reader)Expert: called to re-write queries into primitive queries.java.lang.StringtoString(java.lang.String field)Prints a query to a string, withfieldassumed to be the default field and omitted.private voidvalidate(java.lang.String termText)-
Methods inherited from class org.apache.lucene.search.Query
classHash, createWeight, equals, hashCode, sameClassAs, toString, visit
-
-
-
-
Field Detail
-
term
private final Term term
Term to query against
-
filter
private final BitsProducer filter
BitsProducerwhich is used to filter the document scope.
-
-
Constructor Detail
-
CompletionQuery
protected CompletionQuery(Term term, BitsProducer filter)
Creates a base Completion query against atermwith afilterto scope the documents
-
-
Method Detail
-
getFilter
public BitsProducer getFilter()
Returns aBitsProducer. Only suggestions matching the returned bits will be returned.
-
getField
public java.lang.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 java.io.IOException
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.
-
toString
public java.lang.String toString(java.lang.String field)
Description copied from class:QueryPrints a query to a string, withfieldassumed to be the default field and omitted.
-
validate
private void validate(java.lang.String termText)
-
-