Class BooleanQuery
- java.lang.Object
-
- org.apache.lucene.search.Query
-
- org.apache.lucene.search.BooleanQuery
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.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
Nested Classes Modifier and Type Class and Description static classBooleanQuery.TooManyClausesThrown when an attempt is made to add more thangetMaxClauseCount()clauses.
-
Constructor Summary
Constructors Constructor and Description BooleanQuery()Constructs an empty boolean query.BooleanQuery(boolean disableCoord)Constructs an empty boolean query.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description voidadd(BooleanClause clause)Adds a clause to a boolean query.voidadd(Query query, BooleanClause.Occur occur)Adds a clause to a boolean query.java.util.Listclauses()Returns the list of clauses in this query.java.lang.Objectclone()Returns a clone of this query.booleanequals(java.lang.Object o)Returns true iffois equal to this.voidextractTerms(java.util.Set terms)Expert: adds all terms occuring in this query to the terms set.static booleangetAllowDocsOutOfOrder()Whether hit docs may be collected out of docid order.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)Expert: Returns the Similarity implementation to be used for this query.static booleangetUseScorer14()Deprecated.UsegetAllowDocsOutOfOrder()instead.inthashCode()Returns a hash code value for this object.booleanisCoordDisabled()Returns true iffSimilarity.coord(int,int)is disabled in scoring for this query instance.Queryrewrite(IndexReader reader)Expert: called to re-write queries into primitive queries.static voidsetAllowDocsOutOfOrder(boolean allow)Expert: Indicates whether hit docs may be collected out of docid order.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 satisfied.static voidsetUseScorer14(boolean use14)Deprecated.UsesetAllowDocsOutOfOrder(boolean)instead.java.lang.StringtoString(java.lang.String field)Prints a user-readable version of this query.
-
-
-
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, likeWildcardQueryandFuzzyQuery.- Parameters:
disableCoord- disablesSimilarity.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 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.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
RangeQueryone can use aRangeFilter.Normally the buffers are allocated by the JVM. When using for example
MMapDirectorythe buffering is left to the operating system.
-
isCoordDisabled
public boolean isCoordDisabled()
Returns true iffSimilarity.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:QueryExpert: 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:
getSimilarityin classQuery
-
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 satisifed.
-
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 java.util.List clauses()
Returns the list of clauses in this query.
-
setAllowDocsOutOfOrder
public static void setAllowDocsOutOfOrder(boolean allow)
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, calls to
HitCollector.collect(int,float)might be invoked first for docid N and only later for docid N-1. Being static, this setting is system wide.
-
getAllowDocsOutOfOrder
public static boolean getAllowDocsOutOfOrder()
Whether hit docs may be collected out of docid order.- See Also:
setAllowDocsOutOfOrder(boolean)
-
setUseScorer14
public static void setUseScorer14(boolean use14)
Deprecated. UsesetAllowDocsOutOfOrder(boolean)instead.
-
getUseScorer14
public static boolean getUseScorer14()
Deprecated. UsegetAllowDocsOutOfOrder()instead.
-
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.
-
extractTerms
public void extractTerms(java.util.Set terms)
Description copied from class:QueryExpert: adds all terms occuring in this query to the terms set. Only works if this query is in itsrewrittenform.- Overrides:
extractTermsin classQuery
-
clone
public java.lang.Object clone()
Description copied from class:QueryReturns a clone of this query.
-
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)
Returns true iffois equal to this.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Returns a hash code value for this object.- Overrides:
hashCodein classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG