| diff --git a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.java b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.java |
| index 4827779375c..124bc43c134 100644 |
| --- a/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.java |
| +++ b/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/TaxonomyFacetSumIntAssociations.java |
| @@ -48,8 +48,7 @@ public class TaxonomyFacetSumIntAssociations extends IntTaxonomyFacets { |
| sumValues(fc.getMatchingDocs()); |
| } |
| |
| - private final void sumValues(List<MatchingDocs> matchingDocs) throws IOException { |
| - // System.out.println("count matchingDocs=" + matchingDocs + " facetsField=" + facetsFieldName); |
| + private void sumValues(List<MatchingDocs> matchingDocs) throws IOException { |
| for (MatchingDocs hits : matchingDocs) { |
| BinaryDocValues dv = hits.context.reader().getBinaryDocValues(indexFieldName); |
| if (dv == null) { // this reader does not have DocValues for the requested category list |
| @@ -59,21 +58,43 @@ public class TaxonomyFacetSumIntAssociations extends IntTaxonomyFacets { |
| DocIdSetIterator docs = hits.bits.iterator(); |
| |
| int doc; |
| - while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { |
| - if (dv.docID() < doc) { |
| - dv.advance(doc); |
| + if (values != null) { |
| + while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { |
| + if (dv.docID() < doc) { |
| + dv.advance(doc); |
| + } |
| + if (dv.docID() == doc) { |
| + final BytesRef bytesRef = dv.binaryValue(); |
| + byte[] bytes = bytesRef.bytes; |
| + int end = bytesRef.offset + bytesRef.length; |
| + int offset = bytesRef.offset; |
| + while (offset < end) { |
| + int ord = (int) BitUtil.VH_BE_INT.get(bytes, offset); |
| + offset += 4; |
| + int value = (int) BitUtil.VH_BE_INT.get(bytes, offset); |
| + offset += 4; |
| + values[ord] += value; |
| + } |
| + } |
| } |
| - if (dv.docID() == doc) { |
| - final BytesRef bytesRef = dv.binaryValue(); |
| - byte[] bytes = bytesRef.bytes; |
| - int end = bytesRef.offset + bytesRef.length; |
| - int offset = bytesRef.offset; |
| - while (offset < end) { |
| - int ord = (int) BitUtil.VH_BE_INT.get(bytes, offset); |
| - offset += 4; |
| - int value = (int) BitUtil.VH_BE_INT.get(bytes, offset); |
| - offset += 4; |
| - increment(ord, value); |
| + } else { |
| + assert sparseValues != null; |
| + while ((doc = docs.nextDoc()) != DocIdSetIterator.NO_MORE_DOCS) { |
| + if (dv.docID() < doc) { |
| + dv.advance(doc); |
| + } |
| + if (dv.docID() == doc) { |
| + final BytesRef bytesRef = dv.binaryValue(); |
| + byte[] bytes = bytesRef.bytes; |
| + int end = bytesRef.offset + bytesRef.length; |
| + int offset = bytesRef.offset; |
| + while (offset < end) { |
| + int ord = (int) BitUtil.VH_BE_INT.get(bytes, offset); |
| + offset += 4; |
| + int value = (int) BitUtil.VH_BE_INT.get(bytes, offset); |
| + offset += 4; |
| + sparseValues.addTo(ord, value); |
| + } |
| } |
| } |
| } |