

PhraseQuery - Matches a sequence of Terms.

PhrasesĪnother common search is to find documents containing certain phrases. The default setting for the maximum number of clauses 1024, but this can be changed via the static method #setMaxClauseCount(int). This most often occurs when a Query is rewritten into a BooleanQuery with many TermQuery clauses, for example by WildcardQuery. If too many clauses are added, a TooMan圜lauses exception will be thrown during searching. Boolean queries are constructed by adding two or more BooleanClause instances. No document in the result set will match any such clauses. NOT - Use this operator when a clause must not occur in the result set. Every document in the result set will match all such clauses. MUST - Use this operator when a clause is required to occur in the result set. If a query is made up of all SHOULD clauses, then every document in the result set matches at least one of these clauses. SHOULD - Use this operator when a clause can occur in the result set, but is not required. A BooleanQuery contains multiple BooleanClauses, where each clause contains a sub-query ( Query instance) and an operator (from BooleanClause.Occur) describing how that sub-query is combined with the other clauses: 1. Things start to get interesting when one combines multiple TermQuery instances into a BooleanQuery.

Constructing a TermQuery is as simple as: TermQuery tq = new TermQuery(new Term("fieldName", "term")) In this example, the Query identifies all Documents that have the Field named "fieldName" containing the word "term". Thus, a TermQuery identifies and scores all Documents that have a Field with the specified string in it. A TermQuery matches all the documents that contain the specified Term, which is a word that occurs in a certain Field. Of the various implementations of Query, the TermQuery is the easiest to understand and the most often used in applications. See the Algorithm section for more notes on the process. After some infrastructure setup, control finally passes to the Weight implementation and its Scorer or BulkScore instances. Once a Query has been created and submitted to the IndexSearcher, the scoring process begins. To perform a search, applications usually call #search(Query,int) or #search(Query,Filter,int). For details on implementing your own Query class, see Custom Queries - Expert Level below. The Query Classes section below highlights some of the more important Query classes. These implementations can be combined in a wide variety of ways to provide complex querying capabilities along with information about where matches took place in the document collection. Lucene offers a wide variety of Query implementations, most of which are in this package, its subpackages ( spans, payloads), or the queries module.
