[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
This commit is contained in:
Simon Willnauer 2014-07-15 12:38:12 +02:00
parent 7de9d3d2cb
commit 557b634f4a
1 changed files with 5 additions and 6 deletions

View File

@ -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<AtomicReaderContext> leaves = reader.leaves();
List<Holder> 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;