| Method from org.apache.lucene.search.BooleanQuery Detail: |
public void add(BooleanClause clause) {
if (clauses.size() >= maxClauseCount)
throw new TooManyClauses();
clauses.add(clause);
}
Adds a clause to a boolean query. |
public void add(Query query,
Occur occur) {
add(new BooleanClause(query, occur));
}
Adds a clause to a boolean query. |
public List clauses() {
return clauses;
}
Returns the list of clauses in this query. |
public Object clone() {
BooleanQuery clone = (BooleanQuery)super.clone();
clone.clauses = (ArrayList)this.clauses.clone();
return clone;
}
|
protected Weight createWeight(Searcher searcher) throws IOException {
return new BooleanWeight(searcher);
}
|
public boolean equals(Object o) {
if (!(o instanceof BooleanQuery))
return false;
BooleanQuery other = (BooleanQuery)o;
return (this.getBoost() == other.getBoost())
&& this.clauses.equals(other.clauses)
&& this.getMinimumNumberShouldMatch() == other.getMinimumNumberShouldMatch();
}
Returns true iff o is equal to this. |
public void extractTerms(Set terms) {
for (Iterator i = clauses.iterator(); i.hasNext();) {
BooleanClause clause = (BooleanClause) i.next();
clause.getQuery().extractTerms(terms);
}
}
|
public static boolean getAllowDocsOutOfOrder() {
return allowDocsOutOfOrder;
}
Whether hit docs may be collected out of docid order. |
public BooleanClause[] getClauses() {
return (BooleanClause[])clauses.toArray(new BooleanClause[clauses.size()]);
}
Returns the set of clauses in this query. |
public static int getMaxClauseCount() {
return maxClauseCount;
}
Return the maximum number of clauses permitted, 1024 by default.
Attempts to add more than the permitted number of clauses cause TooManyClauses to be thrown. |
public int getMinimumNumberShouldMatch() {
return minNrShouldMatch;
}
Gets the minimum number of the optional BooleanClauses
which must be satisifed. |
public Similarity getSimilarity(Searcher searcher) {
Similarity result = super.getSimilarity(searcher);
if (disableCoord) { // disable coord as requested
result = new SimilarityDelegator(result) {
public float coord(int overlap, int maxOverlap) {
return 1.0f;
}
};
}
return result;
}
|
public static boolean getUseScorer14() {
return getAllowDocsOutOfOrder();
} Deprecated! Use - #getAllowDocsOutOfOrder() instead.
|
public int hashCode() {
return Float.floatToIntBits(getBoost()) ^ clauses.hashCode()
+ getMinimumNumberShouldMatch();
}
Returns a hash code value for this object. |
public boolean isCoordDisabled() {
return disableCoord;
}
|
public Query rewrite(IndexReader reader) throws IOException {
if (clauses.size() == 1) { // optimize 1-clause queries
BooleanClause c = (BooleanClause)clauses.get(0);
if (!c.isProhibited()) { // just return clause
Query query = c.getQuery().rewrite(reader); // rewrite first
if (getBoost() != 1.0f) { // incorporate boost
if (query == c.getQuery()) // if rewrite was no-op
query = (Query)query.clone(); // then clone before boost
query.setBoost(getBoost() * query.getBoost());
}
return query;
}
}
BooleanQuery clone = null; // recursively rewrite
for (int i = 0 ; i < clauses.size(); i++) {
BooleanClause c = (BooleanClause)clauses.get(i);
Query query = c.getQuery().rewrite(reader);
if (query != c.getQuery()) { // clause rewrote: must clone
if (clone == null)
clone = (BooleanQuery)this.clone();
clone.clauses.set(i, new BooleanClause(query, c.getOccur()));
}
}
if (clone != null) {
return clone; // some clauses rewrote
} else
return this; // no clauses rewrote
}
|
public static void setAllowDocsOutOfOrder(boolean allow) {
allowDocsOutOfOrder = 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.
|
public static void setMaxClauseCount(int maxClauseCount) {
if (maxClauseCount < 1)
throw new IllegalArgumentException("maxClauseCount must be >= 1");
BooleanQuery.maxClauseCount = 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 RangeQuery one can use a
RangeFilter .
Normally the buffers are allocated by the JVM. When using for example
org.apache.lucene.store.MMapDirectory the buffering is left to
the operating system. |
public void setMinimumNumberShouldMatch(int min) {
this.minNrShouldMatch = 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.
|
public static void setUseScorer14(boolean use14) {
setAllowDocsOutOfOrder(use14);
} Deprecated! Use - #setAllowDocsOutOfOrder(boolean) instead.
|
public String toString(String field) {
StringBuffer buffer = new StringBuffer();
boolean needParens=(getBoost() != 1.0) || (getMinimumNumberShouldMatch() >0) ;
if (needParens) {
buffer.append("(");
}
for (int i = 0 ; i < clauses.size(); i++) {
BooleanClause c = (BooleanClause)clauses.get(i);
if (c.isProhibited())
buffer.append("-");
else if (c.isRequired())
buffer.append("+");
Query subQuery = c.getQuery();
if (subQuery instanceof BooleanQuery) { // wrap sub-bools in parens
buffer.append("(");
buffer.append(c.getQuery().toString(field));
buffer.append(")");
} else
buffer.append(c.getQuery().toString(field));
if (i != clauses.size()-1)
buffer.append(" ");
}
if (needParens) {
buffer.append(")");
}
if (getMinimumNumberShouldMatch() >0) {
buffer.append('~");
buffer.append(getMinimumNumberShouldMatch());
}
if (getBoost() != 1.0f)
{
buffer.append(ToStringUtils.boost(getBoost()));
}
return buffer.toString();
}
Prints a user-readable version of this query. |