Skip to content

Apache Lucene open-source search software

SOLR-236: simplify by using groupSort in base class

Yonik Seeleybdb729a13701
diff --git a/solr/src/java/org/apache/solr/handler/component/QueryComponent.java b/solr/src/java/org/apache/solr/handler/component/QueryComponent.java
index 0415f2992cc..96f38931808 100644
--- a/solr/src/java/org/apache/solr/handler/component/QueryComponent.java
+++ b/solr/src/java/org/apache/solr/handler/component/QueryComponent.java
@@ -217,14 +217,8 @@ public class QueryComponent extends SearchComponent
for (String groupByStr : funcs) {
QParser parser = QParser.getParser(groupByStr, "func", rb.req);
Query q = parser.getQuery();
- SolrIndexSearcher.GroupCommandFunc gc;
- if (groupSort != null) {
- SolrIndexSearcher.GroupSortCommand gcSort = new SolrIndexSearcher.GroupSortCommand();
- gcSort.sort = groupSort;
- gc = gcSort;
- } else {
- gc = new SolrIndexSearcher.GroupCommandFunc();
- }
+ SolrIndexSearcher.GroupCommandFunc gc = new SolrIndexSearcher.GroupCommandFunc();
+ gc.groupSort = groupSort;
if (q instanceof FunctionQuery) {
gc.groupBy = ((FunctionQuery)q).getValueSource();
diff --git a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
index b62c3ff90e4..a4a67be6301 100644
--- a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -930,9 +930,8 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
Map context = ValueSource.newContext();
gc.groupBy.createWeight(context, this);
TopGroupCollector collector;
- if (gc instanceof GroupSortCommand) {
- GroupSortCommand sortGc = (GroupSortCommand) gc;
- collector = new TopGroupSortCollector(gc.groupBy, context, sort, sortGc.sort, last);
+ if (gc.groupSort != null && gc.groupSort != sort) {
+ collector = new TopGroupSortCollector(gc.groupBy, context, sort, gc.groupSort, last);
} else {
collector = new TopGroupCollector(gc.groupBy, context, sort, last);
}
@@ -963,13 +962,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
for (GroupCommand groupCommand : cmd.groupCommands) {
if (groupCommand instanceof GroupCommandFunc) {
GroupCommandFunc gc = (GroupCommandFunc)groupCommand;
- Sort collectorSort;
- if (gc instanceof GroupSortCommand) {
- collectorSort = ((GroupSortCommand) gc).sort;
- } else {
- collectorSort = sort;
- }
-
+ Sort collectorSort = gc.groupSort == null ? sort : gc.groupSort;
Phase2GroupCollector collector = new Phase2GroupCollector((TopGroupCollector)gc.collector, gc.groupBy, gc.context, collectorSort, gc.docsPerGroup, needScores);
phase2Collectors.add(collector);
}
@@ -1985,9 +1978,6 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
public Sort groupSort; // the sort of the documents *within* a single group.
public int groupLimit; // how many groups - defaults to the "rows" parameter
public int docsPerGroup; // how many docs in each group - from "group.limit" param, default=1
-
-
-
}
public static class GroupCommandFunc extends GroupCommand {
@@ -1999,10 +1989,6 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
transient Collector collector;
}
- public static class GroupSortCommand extends GroupCommandFunc {
- public Sort sort;
- }
-
/**
* The result of a search.
*/