Skip to content

Commit b614a53

Browse files
authored
Alter TopGroups.merge() to not return null if no groups (#16305)
- Add java doc for TopGroups.merge() - Alter TopGroups.merge() to not return null if no groups, this is to make it consistent with the similar method TopGroups.mergeBlockGroups(), then we don't need to handle the null case in the caller place(coming in next PR which replaces searching with collector with searching with collector manager for TopGroups) Signed-off-by: Binlong Gao <gbinlong@amazon.com>
1 parent 97c2b11 commit b614a53

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

lucene/CHANGES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ New Features
292292

293293
Improvements
294294
---------------------
295-
(No changes)
295+
* GITHUB#16170: Alter TopGroups.merge() to not return null if no groups. (Binlong Gao)
296296

297297
Optimizations
298298
---------------------

lucene/grouping/src/java/org/apache/lucene/search/grouping/TopGroups.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,18 @@ static float nonNANmax(float a, float b) {
119119
* documents of one group do only reside in one shard then the totalGroupCount is exact.
120120
*
121121
* <p><b>NOTE</b>: the topDocs in each GroupDocs is actually an instance of TopDocsAndShards
122+
*
123+
* @param shardGroups list of TopGroups to merge, one per shard; must all share the same group
124+
* sort, doc sort, and top groups.
125+
* @param groupSort the {@link Sort} used to sort the groups across shards.
126+
* @param docSort the {@link Sort} used to sort documents within each group.
127+
* @param docOffset which document to start from within each group (for pagination).
128+
* @param docTopN how many top documents to keep within each group.
129+
* @param scoreMergeMode how to merge scores across shards; see {@link ScoreMergeMode}.
130+
* @return merged TopGroups instance, if there are no groups, returns a TopGroups with an empty
131+
* groups array.
122132
*/
133+
@SuppressWarnings("unchecked")
123134
public static <T> TopGroups<T> merge(
124135
List<TopGroups<T>> shardGroups,
125136
Sort groupSort,
@@ -131,7 +142,13 @@ public static <T> TopGroups<T> merge(
131142
// System.out.println("TopGroups.merge");
132143

133144
if (shardGroups.isEmpty()) {
134-
return null;
145+
return new TopGroups<>(
146+
groupSort.getSort(),
147+
docSort.getSort(),
148+
0,
149+
0,
150+
(GroupDocs<T>[]) new GroupDocs<?>[0],
151+
Float.NaN);
135152
}
136153

137154
int totalHitCount = 0;

0 commit comments

Comments
 (0)