From a380e0e16910d54fc6b098373be55e75ff3b3062 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 12 Jan 2012 13:39:08 +0200 Subject: [PATCH] optimize match all query against a type to be wrapped with a constant score query and not filtered --- .../java/org/elasticsearch/search/query/QueryPhase.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/search/query/QueryPhase.java b/src/main/java/org/elasticsearch/search/query/QueryPhase.java index 5311551ca64..31021f33f03 100644 --- a/src/main/java/org/elasticsearch/search/query/QueryPhase.java +++ b/src/main/java/org/elasticsearch/search/query/QueryPhase.java @@ -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,7 +82,13 @@ public class QueryPhase implements SearchPhase { } Filter searchFilter = context.mapperService().searchFilter(context.types()); if (searchFilter != null) { - context.parsedQuery(new ParsedQuery(new FilteredQuery(context.query(), context.filterCache().cache(searchFilter)), context.parsedQuery())); + 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); }