Package org.apache.lucene.search
Class BooleanQuery
java.lang.Object
org.apache.lucene.search.Query
org.apache.lucene.search.BooleanQuery
- All Implemented Interfaces:
Cloneable
,Iterable<BooleanClause>
A Query that matches documents matching boolean combinations of other
queries, e.g.
TermQuery
s, PhraseQuery
s or other
BooleanQuerys.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Thrown when an attempt is made to add more thangetMaxClauseCount()
clauses. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty boolean query.BooleanQuery
(boolean disableCoord) Constructs an empty boolean query. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(BooleanClause clause) Adds a clause to a boolean query.void
add
(Query query, BooleanClause.Occur occur) Adds a clause to a boolean query.clauses()
Returns the list of clauses in this query.clone()
Returns a clone of this query.createWeight
(IndexSearcher searcher) Expert: Constructs an appropriate Weight implementation for this query.boolean
Returns true iffo
is equal to this.void
extractTerms
(Set<Term> terms) Expert: adds all terms occurring in this query to the terms set.Returns the set of clauses in this query.static int
Return the maximum number of clauses permitted, 1024 by default.int
Gets the minimum number of the optional BooleanClauses which must be satisfied.int
hashCode()
Returns a hash code value for this object.boolean
Returns true iffSimilarity.coord(int,int)
is disabled in scoring for this query instance.final Iterator
<BooleanClause> iterator()
Returns an iterator on the clauses in this query.rewrite
(IndexReader reader) Expert: called to re-write queries into primitive queries.static void
setMaxClauseCount
(int maxClauseCount) Set the maximum number of clauses permitted per BooleanQuery.void
setMinimumNumberShouldMatch
(int min) Specifies a minimum number of the optional BooleanClauses which must be satisfied.Prints a user-readable version of this query.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
BooleanQuery
public BooleanQuery()Constructs an empty boolean query. -
BooleanQuery
public BooleanQuery(boolean disableCoord) Constructs an empty boolean query.Similarity.coord(int,int)
may be disabled in scoring, as appropriate. For example, this score factor does not make sense for most automatically generated queries, likeWildcardQuery
andFuzzyQuery
.- Parameters:
disableCoord
- disablesSimilarity.coord(int,int)
in scoring.
-
-
Method Details
-
getMaxClauseCount
public static int getMaxClauseCount()Return the maximum number of clauses permitted, 1024 by default. Attempts to add more than the permitted number of clauses causeBooleanQuery.TooManyClauses
to be thrown.- See Also:
-
setMaxClauseCount
public static void setMaxClauseCount(int maxClauseCount) Set the maximum number of clauses permitted per BooleanQuery. Default value is 1024. -
isCoordDisabled
public boolean isCoordDisabled()Returns true iffSimilarity.coord(int,int)
is disabled in scoring for this query instance.- See Also:
-
setMinimumNumberShouldMatch
public void setMinimumNumberShouldMatch(int min) Specifies a minimum number of the optional BooleanClauses which must be satisfied.By default no optional clauses are necessary for a match (unless there are no required clauses). If this method is used, then the specified number of clauses is required.
Use of this method is totally independent of specifying that any specific clauses are required (or prohibited). This number will only be compared against the number of matching optional clauses.
- Parameters:
min
- the number of optional clauses that must match
-
getMinimumNumberShouldMatch
public int getMinimumNumberShouldMatch()Gets the minimum number of the optional BooleanClauses which must be satisfied. -
add
Adds a clause to a boolean query.- Throws:
BooleanQuery.TooManyClauses
- if the new number of clauses exceeds the maximum clause number- See Also:
-
add
Adds a clause to a boolean query.- Throws:
BooleanQuery.TooManyClauses
- if the new number of clauses exceeds the maximum clause number- See Also:
-
getClauses
Returns the set of clauses in this query. -
clauses
Returns the list of clauses in this query. -
iterator
Returns an iterator on the clauses in this query. It implements theIterable
interface to make it possible to do:for (BooleanClause clause : booleanQuery) {}
- Specified by:
iterator
in interfaceIterable<BooleanClause>
-
createWeight
Description copied from class:Query
Expert: Constructs an appropriate Weight implementation for this query.Only implemented by primitive queries, which re-write to themselves.
- Overrides:
createWeight
in classQuery
- Throws:
IOException
-
rewrite
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.- Overrides:
rewrite
in classQuery
- Throws:
IOException
-
extractTerms
Description copied from class:Query
Expert: adds all terms occurring in this query to the terms set. Only works if this query is in itsrewritten
form.- Overrides:
extractTerms
in classQuery
-
clone
Description copied from class:Query
Returns a clone of this query. -
toString
Prints a user-readable version of this query. -
equals
Returns true iffo
is equal to this. -
hashCode
public int hashCode()Returns a hash code value for this object.
-