org.apache.lucene.search

Class BooleanQuery

public class BooleanQuery extends Query

A Query that matches documents matching boolean combinations of other queries, e.g. {@link TermQuery}s, {@link PhraseQuery}s or other BooleanQuerys.
Nested Class Summary
static classBooleanQuery.TooManyClauses
Thrown when an attempt is made to add more than {@link #getMaxClauseCount()} clauses.
Field Summary
static intmaxClauseCount
protected intminNrShouldMatch
Constructor Summary
BooleanQuery()
Constructs an empty boolean query.
BooleanQuery(boolean disableCoord)
Constructs an empty boolean query.
Method Summary
voidadd(Query query, boolean required, boolean prohibited)
Adds a clause to a boolean query.
voidadd(Query query, BooleanClause.Occur occur)
Adds a clause to a boolean query.
voidadd(BooleanClause clause)
Adds a clause to a boolean query.
Objectclone()
protected WeightcreateWeight(Searcher searcher)
booleanequals(Object o)
Returns true iff o is equal to this.
voidextractTerms(Set terms)
BooleanClause[]getClauses()
Returns the set of clauses in this query.
static intgetMaxClauseCount()
Return the maximum number of clauses permitted, 1024 by default.
intgetMinimumNumberShouldMatch()
Gets the minimum number of the optional BooleanClauses which must be satisifed.
SimilaritygetSimilarity(Searcher searcher)
static booleangetUseScorer14()
inthashCode()
Returns a hash code value for this object.
booleanisCoordDisabled()
Returns true iff {@link Similarity#coord(int,int)} is disabled in scoring for this query instance.
Queryrewrite(IndexReader reader)
static voidsetMaxClauseCount(int maxClauseCount)
Set the maximum number of clauses permitted per BooleanQuery.
voidsetMinimumNumberShouldMatch(int min)
Specifies a minimum number of the optional BooleanClauses which must be satisifed.
static voidsetUseScorer14(boolean use14)
StringtoString(String field)
Prints a user-readable version of this query.

Field Detail

maxClauseCount

public static int maxClauseCount

Deprecated: use {@link #setMaxClauseCount(int)} instead

minNrShouldMatch

protected int minNrShouldMatch

Constructor Detail

BooleanQuery

public BooleanQuery()
Constructs an empty boolean query.

BooleanQuery

public BooleanQuery(boolean disableCoord)
Constructs an empty boolean query. {@link 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, like {@link WildcardQuery} and {@link FuzzyQuery}.

Parameters: disableCoord disables {@link Similarity#coord(int,int)} in scoring.

Method Detail

add

public void add(Query query, boolean required, boolean prohibited)

Deprecated: use {@link #add(Query, BooleanClause.Occur)} instead:

Adds a clause to a boolean query. Clauses may be: It is an error to specify a clause as both required and prohibited.

add

public void add(Query query, BooleanClause.Occur occur)
Adds a clause to a boolean query.

Throws: TooManyClauses if the new number of clauses exceeds the maximum clause number

See Also: getMaxClauseCount

add

public void add(BooleanClause clause)
Adds a clause to a boolean query.

Throws: TooManyClauses if the new number of clauses exceeds the maximum clause number

See Also: getMaxClauseCount

clone

public Object clone()

createWeight

protected Weight createWeight(Searcher searcher)

equals

public boolean equals(Object o)
Returns true iff o is equal to this.

extractTerms

public void extractTerms(Set terms)

getClauses

public BooleanClause[] getClauses()
Returns the set of clauses in this query.

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 cause {@link TooManyClauses} to be thrown.

See Also: BooleanQuery

getMinimumNumberShouldMatch

public int getMinimumNumberShouldMatch()
Gets the minimum number of the optional BooleanClauses which must be satisifed.

getSimilarity

public Similarity getSimilarity(Searcher searcher)

getUseScorer14

public static boolean getUseScorer14()

hashCode

public int hashCode()
Returns a hash code value for this object.

isCoordDisabled

public boolean isCoordDisabled()
Returns true iff {@link Similarity#coord(int,int)} is disabled in scoring for this query instance.

See Also: BooleanQuery

rewrite

public Query rewrite(IndexReader reader)

setMaxClauseCount

public static void setMaxClauseCount(int maxClauseCount)
Set the maximum number of clauses permitted per BooleanQuery. Default value is 1024.

TermQuery clauses are generated from for example prefix queries and fuzzy queries. Each TermQuery needs some buffer space during search, so this parameter indirectly controls the maximum buffer requirements for query search.

When this parameter becomes a bottleneck for a Query one can use a Filter. For example instead of a {@link RangeQuery} one can use a {@link RangeFilter}.

Normally the buffers are allocated by the JVM. When using for example {@link org.apache.lucene.store.MMapDirectory} the buffering is left to the operating system.

setMinimumNumberShouldMatch

public void setMinimumNumberShouldMatch(int min)
Specifies a minimum number of the optional BooleanClauses which must be satisifed.

By default no optional clauses are neccessary for a match (unless there are no required clauses). If this method is used, then the specified numebr of clauses is required.

Use of this method is totally independant of specifying that any specific clauses are required (or prohibited). This number will only be compared against the number of matching optional clauses.

EXPERT NOTE: Using this method will force the use of BooleanWeight2, regardless of wether setUseScorer14(true) has been called.

Parameters: min the number of optional clauses that must match

See Also: BooleanQuery

setUseScorer14

public static void setUseScorer14(boolean use14)

toString

public String toString(String field)
Prints a user-readable version of this query.
Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.