diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java index 00e5ce81656..526590f4343 100644 --- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java +++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/term/TermGroupFacetCollector.java @@ -186,11 +186,23 @@ public abstract class TermGroupFacetCollector extends AbstractGroupFacetCollecto } public void collect(int doc) throws IOException { + int groupOrd = groupFieldTermsIndex.getOrd(doc); if (facetFieldDocTermOrds.isEmpty()) { + int segmentGroupedFacetsIndex = groupOrd * (facetFieldDocTermOrds.numTerms() + 1); + if (facetPrefix != null || segmentGroupedFacetHits.exists(segmentGroupedFacetsIndex)) { + return; + } + + segmentTotalCount++; + segmentFacetCounts[facetFieldDocTermOrds.numTerms()]++; + + segmentGroupedFacetHits.put(segmentGroupedFacetsIndex); + groupedFacetHits.add( + new GroupedFacetHit(groupOrd == 0 ? null : groupFieldTermsIndex.lookup(groupOrd, new BytesRef()), null) + ); return; } - int groupOrd = groupFieldTermsIndex.getOrd(doc); if (facetOrdTermsEnum != null) { reuse = facetFieldDocTermOrds.lookup(doc, reuse); } diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java index aa87303a32c..1e1de173628 100644 --- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java +++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupFacetCollectorTest.java @@ -30,6 +30,7 @@ import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.grouping.dv.DVGroupFacetCollector; import org.apache.lucene.search.grouping.term.TermGroupFacetCollector; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util._TestUtil; @@ -291,7 +292,7 @@ public class GroupFacetCollectorTest extends AbstractGroupingTestCase { indexSearcher.search(new MatchAllDocsQuery(), groupedAirportFacetCollector); TermGroupFacetCollector.GroupedFacetResult airportResult = groupedAirportFacetCollector.mergeSegmentResults(10, 0, false); assertEquals(3, airportResult.getTotalCount()); - assertEquals(0, airportResult.getTotalMissingCount()); + assertEquals(1, airportResult.getTotalMissingCount()); List entries = airportResult.getFacetEntries(0, 10); assertEquals(2, entries.size());