fix wrong optimization on boolean query

This commit is contained in:
kimchy 2010-05-14 08:16:10 +03:00
parent f6d4654daa
commit b49864299d
1 changed files with 0 additions and 22 deletions

View File

@ -54,31 +54,9 @@ public class Queries {
* Optimizes the given query and returns the optimized version of it. * Optimizes the given query and returns the optimized version of it.
*/ */
public static Query optimizeQuery(Query q) { public static Query optimizeQuery(Query q) {
if (q instanceof BooleanQuery) {
return optimizeBooleanQuery((BooleanQuery) q);
}
return q; return q;
} }
public static BooleanQuery optimizeBooleanQuery(BooleanQuery q) {
BooleanQuery optimized = new BooleanQuery(q.isCoordDisabled());
optimized.setMinimumNumberShouldMatch(q.getMinimumNumberShouldMatch());
optimizeBooleanQuery(optimized, q);
return optimized;
}
public static void optimizeBooleanQuery(BooleanQuery optimized, BooleanQuery q) {
for (BooleanClause clause : q.clauses()) {
Query cq = clause.getQuery();
cq.setBoost(cq.getBoost() * q.getBoost());
if (cq instanceof BooleanQuery && !clause.isRequired() && !clause.isProhibited()) {
optimizeBooleanQuery(optimized, (BooleanQuery) cq);
} else {
optimized.add(clause);
}
}
}
public static boolean isNegativeQuery(Query q) { public static boolean isNegativeQuery(Query q) {
if (!(q instanceof BooleanQuery)) { if (!(q instanceof BooleanQuery)) {
return false; return false;