diff --git a/lucene/contrib/CHANGES.txt b/lucene/contrib/CHANGES.txt index 61ecf4eb4ab..35017b65ad4 100644 --- a/lucene/contrib/CHANGES.txt +++ b/lucene/contrib/CHANGES.txt @@ -105,6 +105,9 @@ Bug Fixes * LUCENE-3045: fixed QueryNodeImpl.containsTag(String key) that was not lowercasing the key before checking for the tag (Adriano Crestani) + * LUCENE-3890: Fixed NPE for grouped faceting on multi-valued fields. + (Michael McCandless, Martijn van Groningen) + Optimizations * LUCENE-3468: Replaced last() and remove() with pollLast() in diff --git a/modules/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java b/modules/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java index 0012561ecfb..77a78aa9e44 100644 --- a/modules/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java +++ b/modules/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java @@ -187,12 +187,14 @@ public abstract class TermGroupFacetCollector extends AbstractGroupFacetCollecto public void collect(int doc) throws IOException { int groupOrd = groupFieldTermsIndex.getOrd(doc); - reuse = facetFieldDocTermOrds.lookup(doc, reuse); + if (facetOrdTermsEnum != null) { + reuse = facetFieldDocTermOrds.lookup(doc, reuse); + } int chunk; boolean first = true; int[] buffer = new int[5]; do { - chunk = reuse.read(buffer); + chunk = reuse != null ? reuse.read(buffer) : 0; if (first && chunk == 0) { chunk = 1; buffer[0] = facetFieldDocTermOrds.numTerms(); // this facet ord is reserved for docs not containing facet field. @@ -246,7 +248,7 @@ public abstract class TermGroupFacetCollector extends AbstractGroupFacetCollecto int facetOrd; if (groupedFacetHit.facetValue != null) { - if (!facetOrdTermsEnum.seekExact(groupedFacetHit.facetValue, true)) { + if (facetOrdTermsEnum == null || !facetOrdTermsEnum.seekExact(groupedFacetHit.facetValue, true)) { continue; } facetOrd = (int) facetOrdTermsEnum.ord(); @@ -260,7 +262,13 @@ public abstract class TermGroupFacetCollector extends AbstractGroupFacetCollecto } if (facetPrefix != null) { - TermsEnum.SeekStatus seekStatus = facetOrdTermsEnum.seekCeil(facetPrefix, true); + TermsEnum.SeekStatus seekStatus; + if (facetOrdTermsEnum != null) { + seekStatus = facetOrdTermsEnum.seekCeil(facetPrefix, true); + } else { + seekStatus = TermsEnum.SeekStatus.END; + } + if (seekStatus != TermsEnum.SeekStatus.END) { startFacetOrd = (int) facetOrdTermsEnum.ord(); } else { @@ -296,8 +304,10 @@ public abstract class TermGroupFacetCollector extends AbstractGroupFacetCollecto endFacetOrd == missingCountIndex + 1 ? missingCountIndex : endFacetOrd); this.tenum = tenum; this.mergePos = startFacetOrd; - tenum.seekExact(mergePos); - mergeTerm = tenum.term(); + if (tenum != null) { + tenum.seekExact(mergePos); + mergeTerm = tenum.term(); + } } protected void nextTerm() throws IOException {