optimize match all query against a type to be wrapped with a constant score query and not filtered

This commit is contained in:
Shay Banon 2012-01-12 13:39:08 +02:00
parent 002c8a6599
commit a380e0e169
1 changed files with 8 additions and 1 deletions

View File

@ -24,6 +24,7 @@ import org.apache.lucene.search.*;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.common.lucene.search.function.BoostScoreFunction;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.index.query.ParsedQuery;
@ -81,8 +82,14 @@ public class QueryPhase implements SearchPhase {
}
Filter searchFilter = context.mapperService().searchFilter(context.types());
if (searchFilter != null) {
if (Queries.isMatchAllQuery(context.query())) {
Query q = new DeletionAwareConstantScoreQuery(context.filterCache().cache(searchFilter));
q.setBoost(context.query().getBoost());
context.parsedQuery(new ParsedQuery(q, context.parsedQuery()));
} else {
context.parsedQuery(new ParsedQuery(new FilteredQuery(context.query(), context.filterCache().cache(searchFilter)), context.parsedQuery()));
}
}
facetPhase.preProcess(context);
}