You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by is...@apache.org on 2025/08/05 23:06:14 UTC
(solr) branch ishan/upgrade-to-lucene-10 updated: SOLR-17631: Fix grouping to properly combine main query with filters for scoring
This is an automated email from the ASF dual-hosted git repository.
ishan pushed a commit to branch ishan/upgrade-to-lucene-10
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/ishan/upgrade-to-lucene-10 by this push:
new a705fa75421 SOLR-17631: Fix grouping to properly combine main query with filters for scoring
a705fa75421 is described below
commit a705fa7542181167f8164a67ce0abb74c9869180
Author: Ishan Chattopadhyaya <ic...@gmail.com>
AuthorDate: Wed Aug 6 04:15:07 2025 +0530
SOLR-17631: Fix grouping to properly combine main query with filters for scoring
The grouping implementation was only using filter queries for search operations,
ignoring the main query entirely. This caused function queries like {\!func}foo2_i
to be ignored during grouping, resulting in all groups receiving a score of 1.0
from MatchAllDocsQuery instead of proper function query scores.
This broke group ordering when Sort.RELEVANCE was used (the default), as groups
were not ordered by their maximum scores as expected.
The fix uses QueryUtils.combineQueryAndFilter() to properly combine the main query
(for scoring) with filter queries (for filtering), matching the behavior of normal
Solr search operations. This ensures function queries and other scoring queries
work correctly with grouping.
Fixes TestGroupingSearch.testGroupAPI and related grouping functionality that
relies on proper query scoring.
---
solr/core/src/java/org/apache/solr/search/Grouping.java | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/solr/core/src/java/org/apache/solr/search/Grouping.java b/solr/core/src/java/org/apache/solr/search/Grouping.java
index cf1b73d8289..036cba1863a 100644
--- a/solr/core/src/java/org/apache/solr/search/Grouping.java
+++ b/solr/core/src/java/org/apache/solr/search/Grouping.java
@@ -36,6 +36,7 @@ import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.Sort;
+import org.apache.lucene.search.SortField;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopDocsCollector;
import org.apache.lucene.search.TopFieldCollector;
@@ -298,7 +299,7 @@ public class Grouping {
SolrIndexSearcher.ProcessedFilter pf = searcher.getProcessedFilter(cmd.getFilterList());
- final Query filterQuery = pf.filter == null ? new MatchAllDocsQuery() : pf.filter;
+ final Query searchQuery = QueryUtils.combineQueryAndFilter(QueryUtils.makeQueryable(cmd.getQuery()), pf.filter);
maxDoc = searcher.maxDoc();
needScores = (cmd.getFlags() & SolrIndexSearcher.GET_SCORES) != 0;
@@ -355,7 +356,7 @@ public class Grouping {
}
if (allCollectors != null) {
- searchWithTimeLimiter(filterQuery, allCollectors);
+ searchWithTimeLimiter(searchQuery, allCollectors);
if (allCollectors instanceof DelegatingCollector) {
((DelegatingCollector) allCollectors).complete();
@@ -388,14 +389,14 @@ public class Grouping {
"The grouping cache is active, but not used because it exceeded the max cache limit of %d percent",
maxDocsPercentageToCache));
log.warn("Please increase cache size or disable group caching.");
- searchWithTimeLimiter(filterQuery, secondPhaseCollectors);
+ searchWithTimeLimiter(searchQuery, secondPhaseCollectors);
}
} else {
if (pf.postFilter != null) {
pf.postFilter.setLastDelegate(secondPhaseCollectors);
secondPhaseCollectors = pf.postFilter;
}
- searchWithTimeLimiter(filterQuery, secondPhaseCollectors);
+ searchWithTimeLimiter(searchQuery, secondPhaseCollectors);
}
if (secondPhaseCollectors instanceof DelegatingCollector) {
((DelegatingCollector) secondPhaseCollectors).complete();
@@ -425,9 +426,9 @@ public class Grouping {
* Invokes search with the specified filter and collector. If a time limit has been specified,
* wrap the collector in a TimeLimitingCollector
*/
- private void searchWithTimeLimiter(final Query filterQuery, Collector collector)
+ private void searchWithTimeLimiter(final Query searchQuery, Collector collector)
throws IOException {
- searcher.search(filterQuery, collector);
+ searcher.search(searchQuery, collector);
}
/**
@@ -722,7 +723,7 @@ public class Grouping {
groupSort = groupSort == null ? Sort.RELEVANCE : groupSort;
firstPass =
new FirstPassGroupingCollector<>(
- new TermGroupSelector(groupBy), groupSort, actualGroupsToFind);
+ new TermGroupSelector(groupBy), searcher.weightSort(groupSort), actualGroupsToFind);
return firstPass;
}