You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2026/04/27 06:25:49 UTC

(lucene) branch main updated: Optimize GroupFacetCollector.getFacetEntries() (#15947)

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/main by this push:
     new b3e166335bf Optimize GroupFacetCollector.getFacetEntries() (#15947)
b3e166335bf is described below

commit b3e166335bf140176417283f5638478d10a58fc3
Author: gaobinlong <gb...@amazon.com>
AuthorDate: Mon Apr 27 14:25:43 2026 +0800

    Optimize GroupFacetCollector.getFacetEntries() (#15947)
    
    * Optimize GroupFacetCollector.getFacetEntries()
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    * Revert some change
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    
    ---------
    
    Signed-off-by: Binlong Gao <gb...@amazon.com>
    Co-authored-by: Dawid Weiss <da...@carrotsearch.com>
---
 .../org/apache/lucene/search/grouping/GroupFacetCollector.java     | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupFacetCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupFacetCollector.java
index 93efbd4a046..c2f613f3631 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupFacetCollector.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupFacetCollector.java
@@ -18,6 +18,7 @@ package org.apache.lucene.search.grouping;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.NavigableSet;
@@ -181,7 +182,11 @@ public abstract class GroupFacetCollector extends SimpleCollector {
      * @return a list of facet entries to be rendered based on the specified offset and limit
      */
     public List<FacetEntry> getFacetEntries(int offset, int limit) {
-      List<FacetEntry> entries = new ArrayList<>();
+      if (offset >= facetEntries.size()) {
+        return Collections.emptyList();
+      }
+
+      List<FacetEntry> entries = new ArrayList<>(Math.min(limit, facetEntries.size() - offset));
 
       int skipped = 0;
       int included = 0;