From 557b634f4a17b0de4023f1bbc7354586fc6bb4ca Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Tue, 15 Jul 2014 12:38:12 +0200 Subject: [PATCH] [SEARCH] Wrap filter only once in ApplyAcceptedDocsFilter We potentially wrap the given filter multiple times when iterating the subreaders. We only need to do this once. Closes #6873 --- .../common/lucene/index/FilterableTermsEnum.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/lucene/index/FilterableTermsEnum.java b/src/main/java/org/elasticsearch/common/lucene/index/FilterableTermsEnum.java index ef61dd373f6..eff4a640130 100644 --- a/src/main/java/org/elasticsearch/common/lucene/index/FilterableTermsEnum.java +++ b/src/main/java/org/elasticsearch/common/lucene/index/FilterableTermsEnum.java @@ -65,7 +65,7 @@ public class FilterableTermsEnum extends TermsEnum { protected final int docsEnumFlag; protected int numDocs; - public FilterableTermsEnum(IndexReader reader, String field, int docsEnumFlag, @Nullable Filter filter) throws IOException { + public FilterableTermsEnum(IndexReader reader, String field, int docsEnumFlag, @Nullable final Filter filter) throws IOException { if ((docsEnumFlag != DocsEnum.FLAG_FREQS) && (docsEnumFlag != DocsEnum.FLAG_NONE)) { throw new ElasticsearchIllegalArgumentException("invalid docsEnumFlag of " + docsEnumFlag); } @@ -73,7 +73,7 @@ public class FilterableTermsEnum extends TermsEnum { if (filter == null) { numDocs = reader.numDocs(); } - + ApplyAcceptedDocsFilter acceptedDocsFilter = filter == null ? null : new ApplyAcceptedDocsFilter(filter); List leaves = reader.leaves(); List enums = Lists.newArrayListWithExpectedSize(leaves.size()); for (AtomicReaderContext context : leaves) { @@ -86,13 +86,12 @@ public class FilterableTermsEnum extends TermsEnum { continue; } Bits bits = null; - if (filter != null) { - if (filter == Queries.MATCH_ALL_FILTER) { + if (acceptedDocsFilter != null) { + if (acceptedDocsFilter.filter() == Queries.MATCH_ALL_FILTER) { bits = context.reader().getLiveDocs(); } else { // we want to force apply deleted docs - filter = new ApplyAcceptedDocsFilter(filter); - DocIdSet docIdSet = filter.getDocIdSet(context, context.reader().getLiveDocs()); + DocIdSet docIdSet = acceptedDocsFilter.getDocIdSet(context, context.reader().getLiveDocs()); if (DocIdSets.isEmpty(docIdSet)) { // fully filtered, none matching, no need to iterate on this continue;