Package org.apache.lucene.search
Class BooleanQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.search.BooleanQuery
-
- All Implemented Interfaces:
java.lang.Iterable<BooleanClause>
public class BooleanQuery extends Query implements java.lang.Iterable<BooleanClause>
A Query that matches documents matching boolean combinations of other queries, e.g.TermQuerys,PhraseQuerys or other BooleanQuerys.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBooleanQuery.BuilderA builder for boolean queries.static classBooleanQuery.TooManyClausesThrown when an attempt is made to add more thangetMaxClauseCount()clauses.
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<BooleanClause>clausesprivate java.util.Map<BooleanClause.Occur,java.util.Collection<Query>>clauseSetsprivate inthashCodeprivate static intmaxClauseCountprivate intminimumNumberShouldMatch
-
Constructor Summary
Constructors Modifier Constructor Description privateBooleanQuery(int minimumNumberShouldMatch, BooleanClause[] clauses)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.List<BooleanClause>clauses()Return a list of the clauses of thisBooleanQuery.private intcomputeHashCode()WeightcreateWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost)Expert: Constructs an appropriate Weight implementation for this query.booleanequals(java.lang.Object o)Compares the specified object with this boolean query for equality.private booleanequalsTo(BooleanQuery other)(package private) java.util.Collection<Query>getClauses(BooleanClause.Occur occur)Return the collection of queries for the givenBooleanClause.Occur.static intgetMaxClauseCount()Return the maximum number of clauses permitted, 1024 by default.intgetMinimumNumberShouldMatch()Gets the minimum number of the optional BooleanClauses which must be satisfied.inthashCode()Override and implement query hash code properly in a subclass.(package private) booleanisPureDisjunction()Whether this query is a pure disjunction, ie.java.util.Iterator<BooleanClause>iterator()Returns an iterator on the clauses in this query.Queryrewrite(IndexReader reader)Expert: called to re-write queries into primitive queries.private BooleanQueryrewriteNoScoring()static voidsetMaxClauseCount(int maxClauseCount)Set the maximum number of clauses permitted per BooleanQuery.java.lang.StringtoString(java.lang.String field)Prints a user-readable version of this query.voidvisit(QueryVisitor visitor)Recurse through the query tree, visiting any child queries-
Methods inherited from class org.apache.lucene.search.Query
classHash, sameClassAs, toString
-
-
-
-
Field Detail
-
maxClauseCount
private static int maxClauseCount
-
minimumNumberShouldMatch
private final int minimumNumberShouldMatch
-
clauses
private final java.util.List<BooleanClause> clauses
-
clauseSets
private final java.util.Map<BooleanClause.Occur,java.util.Collection<Query>> clauseSets
-
hashCode
private int hashCode
-
-
Constructor Detail
-
BooleanQuery
private BooleanQuery(int minimumNumberShouldMatch, BooleanClause[] clauses)
-
-
Method Detail
-
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.TooManyClausesto be thrown.- See Also:
setMaxClauseCount(int)
-
setMaxClauseCount
public static void setMaxClauseCount(int maxClauseCount)
Set the maximum number of clauses permitted per BooleanQuery. Default value is 1024.
-
getMinimumNumberShouldMatch
public int getMinimumNumberShouldMatch()
Gets the minimum number of the optional BooleanClauses which must be satisfied.
-
clauses
public java.util.List<BooleanClause> clauses()
Return a list of the clauses of thisBooleanQuery.
-
getClauses
java.util.Collection<Query> getClauses(BooleanClause.Occur occur)
Return the collection of queries for the givenBooleanClause.Occur.
-
isPureDisjunction
boolean isPureDisjunction()
Whether this query is a pure disjunction, ie. it only has SHOULD clauses and it is enough for a single clause to match for this boolean query to match.
-
iterator
public final java.util.Iterator<BooleanClause> iterator()
Returns an iterator on the clauses in this query. It implements theIterableinterface to make it possible to do:for (BooleanClause clause : booleanQuery) {}- Specified by:
iteratorin interfacejava.lang.Iterable<BooleanClause>
-
rewriteNoScoring
private BooleanQuery rewriteNoScoring()
-
createWeight
public Weight createWeight(IndexSearcher searcher, ScoreMode scoreMode, float boost) throws java.io.IOException
Description copied from class:QueryExpert: Constructs an appropriate Weight implementation for this query.Only implemented by primitive queries, which re-write to themselves.
- Overrides:
createWeightin classQueryscoreMode- How the produced scorers will be consumed.boost- The boost that is propagated by the parent queries.- Throws:
java.io.IOException
-
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.
-
visit
public void visit(QueryVisitor visitor)
Description copied from class:QueryRecurse through the query tree, visiting any child queries
-
toString
public java.lang.String toString(java.lang.String field)
Prints a user-readable version of this query.
-
equals
public boolean equals(java.lang.Object o)
Compares the specified object with this boolean query for equality. Returns true if and only if the provided object- is also a
BooleanQuery, - has the same value of
getMinimumNumberShouldMatch() - has the same
BooleanClause.Occur.SHOULDclauses, regardless of the order - has the same
BooleanClause.Occur.MUSTclauses, regardless of the order - has the same set of
BooleanClause.Occur.FILTERclauses, regardless of the order and regardless of duplicates - has the same set of
BooleanClause.Occur.MUST_NOTclauses, regardless of the order and regardless of duplicates
- Specified by:
equalsin classQuery- See Also:
Query.sameClassAs(Object),Query.classHash()
- is also a
-
equalsTo
private boolean equalsTo(BooleanQuery other)
-
computeHashCode
private int computeHashCode()
-
hashCode
public int hashCode()
Description copied from class:QueryOverride and implement query hash code properly in a subclass. This is required so thatQueryCacheworks properly.- Specified by:
hashCodein classQuery- See Also:
Query.equals(Object)
-
-