org.apache.lucene.search

Class BooleanQuery

Implemented Interfaces:
Cloneable, Serializable

public class BooleanQuery
extends Query

A Query that matches documents matching boolean combinations of other queries, e.g. TermQuerys, PhraseQuerys or other BooleanQuerys.
See Also:
Serialized Form

Nested Class Summary

static class
BooleanQuery.TooManyClauses
Thrown when an attempt is made to add more than getMaxClauseCount() clauses.

Field Summary

protected int
minNrShouldMatch

Constructor Summary

BooleanQuery()
Constructs an empty boolean query.
BooleanQuery(boolean disableCoord)
Constructs an empty boolean query.

Method Summary

void
add(BooleanClause clause)
Adds a clause to a boolean query.
void
add(Query query, BooleanClause.Occur occur)
Adds a clause to a boolean query.
List
clauses()
Returns the list of clauses in this query.
Object
clone()
protected Weight
createWeight(Searcher searcher)
boolean
equals(Object o)
Returns true iff o is equal to this.
void
extractTerms(Set terms)
BooleanClause[]
getClauses()
Returns the set of clauses in this query.
static int
getMaxClauseCount()
Return the maximum number of clauses permitted, 1024 by default.
int
getMinimumNumberShouldMatch()
Gets the minimum number of the optional BooleanClauses which must be satisifed.
Similarity
getSimilarity(Searcher searcher)
static boolean
getUseScorer14()
int
hashCode()
Returns a hash code value for this object.
boolean
isCoordDisabled()
Returns true iff Similarity.coord(int,int) is disabled in scoring for this query instance.
Query
rewrite(IndexReader reader)
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 satisifed.
static void
setUseScorer14(boolean use14)
String
toString(String field)
Prints a user-readable version of this query.

Methods inherited from class org.apache.lucene.search.Query

clone, combine, createWeight, extractTerms, getBoost, getSimilarity, mergeBooleanQueries, rewrite, setBoost, toString, toString, weight

Field Details

minNrShouldMatch

protected int minNrShouldMatch

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, like WildcardQuery and FuzzyQuery.
Parameters:
disableCoord - disables Similarity.coord(int,int) in scoring.

Method Details

add

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

add

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

clauses

public List clauses()
Returns the list of clauses in this query.

clone

public Object clone()
Overrides:
clone in interface Query

createWeight

protected Weight createWeight(Searcher searcher)
            throws IOException
Overrides:
createWeight in interface Query

equals

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

extractTerms

public void extractTerms(Set terms)
Overrides:
extractTerms in interface Query

getClauses

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

getMaxClauseCount

public static int getMaxClauseCount()

getMinimumNumberShouldMatch

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

getSimilarity

public Similarity getSimilarity(Searcher searcher)
Overrides:
getSimilarity in interface Query

getUseScorer14

public static boolean getUseScorer14()

hashCode

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

isCoordDisabled

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

rewrite

public Query rewrite(IndexReader reader)
            throws IOException
Overrides:
rewrite in interface Query

setMaxClauseCount

public static void setMaxClauseCount(int maxClauseCount)

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

setUseScorer14

public static void setUseScorer14(boolean use14)

toString

public String toString(String field)
Prints a user-readable version of this query.
Overrides:
toString in interface Query

Copyright © 2000-2007 Apache Software Foundation. All Rights Reserved.