From 4573abc737f5cb42e2dd19775298d0418fbf57b3 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 22 Oct 2012 20:04:57 +0200 Subject: [PATCH] nested facet fails with filter caching turned off fixed #2340 --- .../index/search/nested/NestedChildrenCollector.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/elasticsearch/index/search/nested/NestedChildrenCollector.java b/src/main/java/org/elasticsearch/index/search/nested/NestedChildrenCollector.java index 9bd98e26f25..99752f6e51c 100644 --- a/src/main/java/org/elasticsearch/index/search/nested/NestedChildrenCollector.java +++ b/src/main/java/org/elasticsearch/index/search/nested/NestedChildrenCollector.java @@ -20,6 +20,7 @@ package org.elasticsearch.index.search.nested; import org.apache.lucene.index.IndexReader; +import org.apache.lucene.search.DocIdSet; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Scorer; import org.apache.lucene.util.FixedBitSet; @@ -75,7 +76,14 @@ public class NestedChildrenCollector extends FacetCollector { collector.setNextReader(reader, docBase); currentReader = reader; childDocs = DocSets.convert(reader, childFilter.getDocIdSet(reader)); - parentDocs = ((FixedBitDocSet) parentFilter.getDocIdSet(reader)).set(); + DocIdSet docIdSet = parentFilter.getDocIdSet(reader); + if (docIdSet == null) { + parentDocs = null; + } else if (docIdSet instanceof FixedBitDocSet) { + parentDocs = ((FixedBitDocSet) docIdSet).set(); + } else { + parentDocs = (FixedBitSet) docIdSet; + } } @Override @@ -85,7 +93,7 @@ public class NestedChildrenCollector extends FacetCollector { @Override public void collect(int parentDoc) throws IOException { - if (parentDoc == 0) { + if (parentDoc == 0 || parentDocs == null) { return; } int prevParentDoc = parentDocs.prevSetBit(parentDoc - 1);