org.apache.lucene.search
Class BooleanQuery

java.lang.Object
  extended by org.apache.lucene.search.Query
      extended by org.apache.lucene.search.BooleanQuery
All Implemented Interfaces:
Serializable, Cloneable

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
protected  class BooleanQuery.BooleanWeight
          Expert: the Weight for BooleanQuery, used to normalize, score and explain these queries.
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()
          Returns a clone of this query.
 Weight createWeight(Searcher searcher)
          Expert: Constructs an appropriate Weight implementation for this query.
 boolean equals(Object o)
          Returns true iff o is equal to this.
 void extractTerms(Set terms)
          Expert: adds all terms occurring in this query to the terms set.
static boolean getAllowDocsOutOfOrder()
          Deprecated. this is not needed anymore, as Weight.scoresDocsOutOfOrder() is used.
 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 satisfied.
 Similarity getSimilarity(Searcher searcher)
          Expert: Returns the Similarity implementation to be used for this query.
static boolean getUseScorer14()
          Deprecated. Use getAllowDocsOutOfOrder() instead.
 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)
          Expert: called to re-write queries into primitive queries.
static void setAllowDocsOutOfOrder(boolean allow)
          Deprecated. this is not needed anymore, as Weight.scoresDocsOutOfOrder() is used.
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.
static void setUseScorer14(boolean use14)
          Deprecated. Use setAllowDocsOutOfOrder(boolean) instead.
 String toString(String field)
          Prints a user-readable version of this query.
 
Methods inherited from class org.apache.lucene.search.Query
combine, getBoost, mergeBooleanQueries, setBoost, toString, weight
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

minNrShouldMatch

protected int minNrShouldMatch
Constructor Detail

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 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 cause BooleanQuery.TooManyClauses to 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.


isCoordDisabled

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

See Also:
BooleanQuery(boolean)

getSimilarity

public Similarity getSimilarity(Searcher searcher)
Description copied from class: Query
Expert: Returns the Similarity implementation to be used for this query. Subclasses may override this method to specify their own Similarity implementation, perhaps one that delegates through that of the Searcher. By default the Searcher's Similarity implementation is returned.

Overrides:
getSimilarity in class Query

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.

EXPERT NOTE: Using this method may force collecting docs in order, regardless of whether setAllowDocsOutOfOrder(true) has been called.

Parameters:
min - the number of optional clauses that must match
See Also:
setAllowDocsOutOfOrder(boolean)

getMinimumNumberShouldMatch

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


add

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

Throws:
BooleanQuery.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:
BooleanQuery.TooManyClauses - if the new number of clauses exceeds the maximum clause number
See Also:
getMaxClauseCount()

getClauses

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


clauses

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


setAllowDocsOutOfOrder

public static void setAllowDocsOutOfOrder(boolean allow)
Deprecated. this is not needed anymore, as Weight.scoresDocsOutOfOrder() is used.

Expert: Indicates whether hit docs may be collected out of docid order.

Background: although the contract of the Scorer class requires that documents be iterated in order of doc id, this was not true in early versions of Lucene. Many pieces of functionality in the current Lucene code base have undefined behavior if this contract is not upheld, but in some specific simple cases may be faster. (For example: disjunction queries with less than 32 prohibited clauses; This setting has no effect for other queries.)

Specifics: By setting this option to true, docid N might be scored for a single segment before docid N-1. Across multiple segments, docs may be scored out of order regardless of this setting - it only applies to scoring a single segment. Being static, this setting is system wide.


getAllowDocsOutOfOrder

public static boolean getAllowDocsOutOfOrder()
Deprecated. this is not needed anymore, as Weight.scoresDocsOutOfOrder() is used.

Whether hit docs may be collected out of docid order.

See Also:
setAllowDocsOutOfOrder(boolean)

setUseScorer14

public static void setUseScorer14(boolean use14)
Deprecated. Use setAllowDocsOutOfOrder(boolean) instead.


getUseScorer14

public static boolean getUseScorer14()
Deprecated. Use getAllowDocsOutOfOrder() instead.


createWeight

public Weight createWeight(Searcher searcher)
                    throws IOException
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 class Query
Throws:
IOException

rewrite

public Query rewrite(IndexReader reader)
              throws IOException
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 class Query
Throws:
IOException

extractTerms

public void extractTerms(Set terms)
Description copied from class: Query
Expert: adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten form.

Overrides:
extractTerms in class Query

clone

public Object clone()
Description copied from class: Query
Returns a clone of this query.

Overrides:
clone in class Query

toString

public String toString(String field)
Prints a user-readable version of this query.

Specified by:
toString in class Query

equals

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

Overrides:
equals in class Query

hashCode

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

Overrides:
hashCode in class Query


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