LUCENE-3048: Improve BooleanQuery rewrite documentation

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1097133 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2011-04-27 14:50:02 +00:00
parent 9c47a99ab6
commit 3e833dd79f
1 changed files with 10 additions and 2 deletions

View File

@ -367,8 +367,12 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
Query query = c.getQuery().rewrite(reader); // rewrite first
if (getBoost() != 1.0f) { // incorporate boost
if (query == c.getQuery()) // if rewrite was no-op
if (query == c.getQuery()) { // if rewrite was no-op
query = (Query)query.clone(); // then clone before boost
}
// Since the BooleanQuery only has 1 clause, the BooleanQuery will be
// written out. Therefore the rewritten Query's boost must incorporate both
// the clause's boost, and the boost of the BooleanQuery itself
query.setBoost(getBoost() * query.getBoost());
}
@ -381,8 +385,12 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
BooleanClause c = clauses.get(i);
Query query = c.getQuery().rewrite(reader);
if (query != c.getQuery()) { // clause rewrote: must clone
if (clone == null)
if (clone == null) {
// The BooleanQuery clone is lazily initialized so only initialize
// it if a rewritten clause differs from the original clause (and hasn't been
// initialized already). If nothing differs, the clone isn't needlessly created
clone = (BooleanQuery)this.clone();
}
clone.clauses.set(i, new BooleanClause(query, c.getOccur()));
}
}