From f3c068f6371578e6613636b37f2f59728913996d Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 24 Jun 2013 18:01:22 +0200 Subject: [PATCH] only call terms lookup once and not per segment --- .../cache/filter/terms/IndicesTermsFilterCache.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/elasticsearch/indices/cache/filter/terms/IndicesTermsFilterCache.java b/src/main/java/org/elasticsearch/indices/cache/filter/terms/IndicesTermsFilterCache.java index bd472b7cd91..e0de300ec1d 100644 --- a/src/main/java/org/elasticsearch/indices/cache/filter/terms/IndicesTermsFilterCache.java +++ b/src/main/java/org/elasticsearch/indices/cache/filter/terms/IndicesTermsFilterCache.java @@ -145,6 +145,8 @@ public class IndicesTermsFilterCache extends AbstractComponent { private final TermsLookup lookup; private final CacheKeyFilter.Key cacheKey; private final IndicesTermsFilterCache cache; + boolean termsFilterCalled; + private Filter termsFilter; LookupTermsFilter(TermsLookup lookup, CacheKeyFilter.Key cacheKey, IndicesTermsFilterCache cache) { this.lookup = lookup; @@ -154,9 +156,12 @@ public class IndicesTermsFilterCache extends AbstractComponent { @Override public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException { - Filter filter = cache.termsFilter(cacheKey, lookup); - if (filter == null) return null; - return filter.getDocIdSet(context, acceptDocs); + // only call the terms filter once per execution (across segments per single search request) + if (!termsFilterCalled) { + termsFilter = cache.termsFilter(cacheKey, lookup); + } + if (termsFilter == null) return null; + return termsFilter.getDocIdSet(context, acceptDocs); } @Override