From 95604518960faabb39869404de7e2ef7d8a4d7f1 Mon Sep 17 00:00:00 2001 From: kimchy Date: Wed, 2 Mar 2011 00:18:26 +0200 Subject: [PATCH] optimize query facet to extract filter from constant_score queries automatically --- .../search/facet/query/QueryFacetCollector.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/query/QueryFacetCollector.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/query/QueryFacetCollector.java index b1bdb5067cd..9b900f20837 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/query/QueryFacetCollector.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/facet/query/QueryFacetCollector.java @@ -20,10 +20,7 @@ package org.elasticsearch.search.facet.query; import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.Filter; -import org.apache.lucene.search.FilteredQuery; -import org.apache.lucene.search.Query; -import org.apache.lucene.search.QueryWrapperFilter; +import org.apache.lucene.search.*; import org.elasticsearch.common.lucene.docset.DocSet; import org.elasticsearch.common.lucene.docset.DocSets; import org.elasticsearch.common.lucene.search.Queries; @@ -50,7 +47,7 @@ public class QueryFacetCollector extends AbstractFacetCollector { if (possibleFilter != null) { this.filter = possibleFilter; } else { - this.filter = new QueryWrapperFilter(query); + this.filter = filterCache.weakCache(new QueryWrapperFilter(query)); } } @@ -77,6 +74,10 @@ public class QueryFacetCollector extends AbstractFacetCollector { if (Queries.isMatchAllQuery(fQuery.getQuery())) { return fQuery.getFilter(); } + } else if (query instanceof DeletionAwareConstantScoreQuery) { + return ((DeletionAwareConstantScoreQuery) query).getFilter(); + } else if (query instanceof ConstantScoreQuery) { + return ((ConstantScoreQuery) query).getFilter(); } return null; }