Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ Optimizations

* GITHUB#15886: Cache frozen FieldType to skip redundant schema validation. (Tim Brooks)

* GITHUB#15942: Skip max score computation when sorting by relevance in BlockGroupingCollector (Binlong Gao)

Bug Fixes
---------------------
* GITHUB#15754: Fix HTMLStripCharFilter to prevent tags from incorrectly consuming subsequent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ public TopGroups<?> getTopGroups(
final Score fakeScorer = new Score();

float maxScore = Float.MIN_VALUE;
final boolean groupSortByRelevance = groupSort.equals(Sort.RELEVANCE);

@SuppressWarnings({"unchecked", "rawtypes"})
final GroupDocs<Object>[] groups = new GroupDocs[groupQueue.size() - groupOffset];
Expand All @@ -286,7 +287,8 @@ public TopGroups<?> getTopGroups(
// At this point we hold all docs w/ in each group,
// unsorted; we now sort them:
final TopDocsCollector<?> collector;
if (withinGroupSort.equals(Sort.RELEVANCE)) {
final boolean withinGroupSortByRelevance = withinGroupSort.equals(Sort.RELEVANCE);
if (withinGroupSortByRelevance) {
// Sort by score
if (!needsScores) {
throw new IllegalArgumentException(
Expand All @@ -309,7 +311,9 @@ public TopGroups<?> getTopGroups(
final int doc = og.docs[docIDX];
if (needsScores) {
fakeScorer.score = og.scores[docIDX];
groupMaxScore = Math.max(groupMaxScore, fakeScorer.score);
if (!withinGroupSortByRelevance) {
groupMaxScore = Math.max(groupMaxScore, fakeScorer.score);
}
}
leafCollector.collect(doc);
}
Expand All @@ -323,6 +327,9 @@ public TopGroups<?> getTopGroups(
}

final TopDocs topDocs = collector.topDocs(withinGroupOffset, maxDocsPerGroup);
if (withinGroupSortByRelevance && topDocs.scoreDocs.length > 0) {
groupMaxScore = topDocs.scoreDocs[0].score;
}

// TODO: we could aggregate scores across children
// by Sum/Avg instead of passing NaN:
Expand All @@ -334,7 +341,13 @@ public TopGroups<?> getTopGroups(
topDocs.scoreDocs,
null,
groupSortValues);
maxScore = Math.max(maxScore, groupMaxScore);
if (!groupSortByRelevance) {
maxScore = Math.max(maxScore, groupMaxScore);
}
}

if (groupSortByRelevance) {
maxScore = groups[0].maxScore();
}

/*
Expand Down
Loading