Apache Lucene open-source search software
SOLR-2243: support group.limit=0
Yonik Seeley4194ef01c45b
diff --git a/solr/src/java/org/apache/solr/search/Grouping.java b/solr/src/java/org/apache/solr/search/Grouping.javaindex 9839ceea97f..e90e0f6effe 100755--- a/solr/src/java/org/apache/solr/search/Grouping.java+++ b/solr/src/java/org/apache/solr/search/Grouping.java@@ -64,7 +64,8 @@ public class Grouping {}DocList getDocList(TopDocsCollector collector) {- int docsToCollect = getMax(groupOffset, docsPerGroup, maxDoc);+ int max = collector.getTotalHits();+ int docsToCollect = getMax(groupOffset, docsPerGroup, max);// TODO: implement a DocList impl that doesn't need to start at offset=0TopDocs topDocs = collector.topDocs(0, docsToCollect);@@ -161,6 +162,7 @@ public class Grouping {if (numGroups == 0) return null;int docsToCollect = getMax(groupOffset, docsPerGroup, maxDoc);+ docsToCollect = Math.max(docsToCollect, 1);if (false && groupBy instanceof StrFieldSource) {collector2 = new Phase2StringGroupCollector(collector, groupBy, context, groupSort, docsToCollect, needScores, offset);@@ -182,8 +184,6 @@ public class Grouping {if (collector.orderedGroups == null) collector.buildSet();--int skipCount = offset;for (SearchGroup group : collector.orderedGroups) {if (skipCount > 0) {@@ -506,6 +506,8 @@ class TopGroupCollector extends GroupCollector {// remove current smallest groupSearchGroup smallest = orderedGroups.pollLast();+ assert orderedGroups.size() == nGroups -1;+groupMap.remove(smallest.groupValue);// reuse the removed SearchGroup@@ -518,6 +520,7 @@ class TopGroupCollector extends GroupCollector {groupMap.put(smallest.groupValue, smallest);orderedGroups.add(smallest);+ assert orderedGroups.size() == nGroups;for (FieldComparator fc : comparators)fc.setBottom(orderedGroups.last().comparatorSlot);@@ -560,6 +563,7 @@ class TopGroupCollector extends GroupCollector {if (orderedGroups != null) {prevLast = orderedGroups.last();orderedGroups.remove(group);+ assert orderedGroups.size() == nGroups-1;}group.topDoc = docBase + doc;@@ -569,6 +573,7 @@ class TopGroupCollector extends GroupCollector {// re-add the changed groupif (orderedGroups != null) {orderedGroups.add(group);+ assert orderedGroups.size() == nGroups;SearchGroup newLast = orderedGroups.last();// if we changed the value of the last group, or changed which group was last, then update bottomif (group == newLast || prevLast != newLast) {diff --git a/solr/src/test/org/apache/solr/TestGroupingSearch.java b/solr/src/test/org/apache/solr/TestGroupingSearch.javaindex e648e6e30db..b244e521c6c 100644--- a/solr/src/test/org/apache/solr/TestGroupingSearch.java+++ b/solr/src/test/org/apache/solr/TestGroupingSearch.java@@ -385,9 +385,7 @@ public class TestGroupingSearch extends SolrTestCaseJ4 {int rows = random.nextInt(10)==0 ? random.nextInt(model.size()+2) : random.nextInt(11)-1;int start = random.nextInt(5)==0 ? random.nextInt(model.size()+2) : random.nextInt(5); // pick a small start normally for better coverage- int group_limit = random.nextInt(10)==0 ? random.nextInt(model.size()+2) : random.nextInt(11)-1;-// TODO: remove restriction on 0-group_limit = random.nextInt(10)+1;+ int group_limit = random.nextInt(10)==0 ? random.nextInt(model.size()+2) : random.nextInt(11)-1;int group_offset = random.nextInt(10)==0 ? random.nextInt(model.size()+2) : random.nextInt(2); // pick a small start normally for better coverageString[] stringSortA = new String[1];@@ -482,7 +480,7 @@ groupSortStr = null;List docs = new ArrayList();resultSet.put("docs", docs);for (int j=group_offset; j<grp.docs.size(); j++) {- if (group_offset != -1 && docs.size() >= group_limit) break;+ if (group_limit != -1 && docs.size() >= group_limit) break;docs.add( grp.docs.get(j).toObject(schema) );}}