Class BooleanQuery
A Query that matches documents matching boolean combinations of other queries, e.g. TermQuerys, PhraseQuerys or other BooleanQuerys.
Collection initializer note: To create and populate a BooleanQuery in a single statement, you can use the following example as a guide:var booleanQuery = new BooleanQuery() {
{ new WildcardQuery(new Term("field2", "foobar")), Occur.SHOULD },
{ new MultiPhraseQuery() {
new Term("field", "microsoft"),
new Term("field", "office")
}, Occur.SHOULD }
};
// or
var booleanQuery = new BooleanQuery() {
new BooleanClause(new WildcardQuery(new Term("field2", "foobar")), Occur.SHOULD),
new BooleanClause(new MultiPhraseQuery() {
new Term("field", "microsoft"),
new Term("field", "office")
}, Occur.SHOULD)
};
Inherited Members
Namespace: Lucene.Net.Search
Assembly: Lucene.Net.dll
Syntax
public class BooleanQuery : Query, IEnumerable<BooleanClause>, IEnumerable
Constructors
BooleanQuery()
Constructs an empty boolean query.
Declaration
public BooleanQuery()
BooleanQuery(bool)
Constructs an empty boolean query.
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.Declaration
public BooleanQuery(bool disableCoord)
Parameters
Type | Name | Description |
---|---|---|
bool | disableCoord | Disables Coord(int, int) in scoring. |
Fields
m_minNrShouldMatch
A Query that matches documents matching boolean combinations of other queries, e.g. TermQuerys, PhraseQuerys or other BooleanQuerys.
Collection initializer note: To create and populate a BooleanQuery in a single statement, you can use the following example as a guide:var booleanQuery = new BooleanQuery() {
{ new WildcardQuery(new Term("field2", "foobar")), Occur.SHOULD },
{ new MultiPhraseQuery() {
new Term("field", "microsoft"),
new Term("field", "office")
}, Occur.SHOULD }
};
// or
var booleanQuery = new BooleanQuery() {
new BooleanClause(new WildcardQuery(new Term("field2", "foobar")), Occur.SHOULD),
new BooleanClause(new MultiPhraseQuery() {
new Term("field", "microsoft"),
new Term("field", "office")
}, Occur.SHOULD)
};
Declaration
protected int m_minNrShouldMatch
Field Value
Type | Description |
---|---|
int |
Properties
Clauses
Returns the list of clauses in this query.
Declaration
public virtual IList<BooleanClause> Clauses { get; }
Property Value
Type | Description |
---|---|
IList<BooleanClause> |
CoordDisabled
Returns true if Coord(int, int) is disabled in scoring for this query instance.
Declaration
public virtual bool CoordDisabled { get; }
Property Value
Type | Description |
---|---|
bool |
See Also
MaxClauseCount
Return the maximum number of clauses permitted, 1024 by default. Attempts to add more than the permitted number of clauses cause BooleanQuery.TooManyClausesException to be thrown.
Declaration
public static int MaxClauseCount { get; set; }
Property Value
Type | Description |
---|---|
int |
MinimumNumberShouldMatch
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.
Declaration
public virtual int MinimumNumberShouldMatch { get; set; }
Property Value
Type | Description |
---|---|
int |
Methods
Add(BooleanClause)
Adds a clause to a boolean query.
Declaration
public virtual void Add(BooleanClause clause)
Parameters
Type | Name | Description |
---|---|---|
BooleanClause | clause |
Exceptions
Type | Condition |
---|---|
BooleanQuery.TooManyClausesException | If the new number of clauses exceeds the maximum clause number |
See Also
Add(Query, Occur)
Adds a clause to a boolean query.
Declaration
public virtual void Add(Query query, Occur occur)
Parameters
Type | Name | Description |
---|---|---|
Query | query | |
Occur | occur |
Exceptions
Type | Condition |
---|---|
BooleanQuery.TooManyClausesException | If the new number of clauses exceeds the maximum clause number |
See Also
Clone()
Returns a clone of this query.
Declaration
public override object Clone()
Returns
Type | Description |
---|---|
object |
Overrides
CreateWeight(IndexSearcher)
Expert: Constructs an appropriate Weight implementation for this query.
Only implemented by primitive queries, which re-write to themselves.Declaration
public override Weight CreateWeight(IndexSearcher searcher)
Parameters
Type | Name | Description |
---|---|---|
IndexSearcher | searcher |
Returns
Type | Description |
---|---|
Weight |
Overrides
Equals(object)
Returns true
if o
is equal to this.
Declaration
public override bool Equals(object o)
Parameters
Type | Name | Description |
---|---|---|
object | o |
Returns
Type | Description |
---|---|
bool |
Overrides
ExtractTerms(ISet<Term>)
Expert: adds all terms occurring in this query to the terms set. Only works if this query is in its rewritten (Rewrite(IndexReader)) form.
Declaration
public override void ExtractTerms(ISet<Term> terms)
Parameters
Type | Name | Description |
---|---|---|
ISet<Term> | terms |
Overrides
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If this query is not yet rewritten |
GetClauses()
Returns the set of clauses in this query.
Declaration
public virtual BooleanClause[] GetClauses()
Returns
Type | Description |
---|---|
BooleanClause[] |
GetEnumerator()
Returns an iterator on the clauses in this query. It implements the IEnumerable{BooleanClause} interface to make it possible to do:
foreach (BooleanClause clause in booleanQuery) {}
Declaration
public IEnumerator<BooleanClause> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<BooleanClause> |
GetHashCode()
Returns a hash code value for this object.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int |
Overrides
Rewrite(IndexReader)
Expert: called to re-write queries into primitive queries. For example, a PrefixQuery will be rewritten into a BooleanQuery that consists of TermQuerys.
Declaration
public override Query Rewrite(IndexReader reader)
Parameters
Type | Name | Description |
---|---|---|
IndexReader | reader |
Returns
Type | Description |
---|---|
Query |
Overrides
ToString(string)
Prints a user-readable version of this query.
Declaration
public override string ToString(string field)
Parameters
Type | Name | Description |
---|---|---|
string | field |
Returns
Type | Description |
---|---|
string |