From c33ca2921d83b1bceb417b3790b51e1cec5dec83 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Tue, 21 Aug 2012 19:32:55 +0200 Subject: [PATCH] small optimization for global facet with facet filter, by removing the double check on the facet filter --- .../elasticsearch/search/facet/AbstractFacetCollector.java | 6 ++++++ .../java/org/elasticsearch/search/facet/FacetPhase.java | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/search/facet/AbstractFacetCollector.java b/src/main/java/org/elasticsearch/search/facet/AbstractFacetCollector.java index 03b49384ae2..126dd3dcd16 100644 --- a/src/main/java/org/elasticsearch/search/facet/AbstractFacetCollector.java +++ b/src/main/java/org/elasticsearch/search/facet/AbstractFacetCollector.java @@ -48,6 +48,12 @@ public abstract class AbstractFacetCollector extends FacetCollector { return this.filter; } + public Filter getAndClearFilter() { + Filter filter = this.filter; + this.filter = null; + return filter; + } + @Override public void setFilter(Filter filter) { if (this.filter == null) { diff --git a/src/main/java/org/elasticsearch/search/facet/FacetPhase.java b/src/main/java/org/elasticsearch/search/facet/FacetPhase.java index ff3fb5191e3..1c46544f648 100644 --- a/src/main/java/org/elasticsearch/search/facet/FacetPhase.java +++ b/src/main/java/org/elasticsearch/search/facet/FacetPhase.java @@ -103,7 +103,9 @@ public class FacetPhase implements SearchPhase { if (collector instanceof AbstractFacetCollector) { AbstractFacetCollector facetCollector = (AbstractFacetCollector) collector; if (facetCollector.getFilter() != null) { - filter = facetCollector.getFilter(); + // we can clear the filter, since we are anyhow going to iterate over it + // so no need to double check it... + filter = facetCollector.getAndClearFilter(); } } List list = filtersByCollector.get(filter);