You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2010/11/19 23:42:15 UTC
svn commit: r1037068 - in /lucene/dev/trunk/solr/src:
java/org/apache/solr/search/Grouping.java
test/org/apache/solr/TestGroupingSearch.java
Author: yonik
Date: Fri Nov 19 22:42:15 2010
New Revision: 1037068
URL: http://svn.apache.org/viewvc?rev=1037068&view=rev
Log:
SOLR-2243: support group.limit=0
Modified:
lucene/dev/trunk/solr/src/java/org/apache/solr/search/Grouping.java
lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java
Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/Grouping.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/Grouping.java?rev=1037068&r1=1037067&r2=1037068&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/Grouping.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/Grouping.java Fri Nov 19 22:42:15 2010
@@ -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=0
TopDocs 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 GroupCol
// remove current smallest group
SearchGroup smallest = orderedGroups.pollLast();
+ assert orderedGroups.size() == nGroups -1;
+
groupMap.remove(smallest.groupValue);
// reuse the removed SearchGroup
@@ -518,6 +520,7 @@ class TopGroupCollector extends GroupCol
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 GroupCol
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 GroupCol
// re-add the changed group
if (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 bottom
if (group == newLast || prevLast != newLast) {
Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java?rev=1037068&r1=1037067&r2=1037068&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java Fri Nov 19 22:42:15 2010
@@ -385,9 +385,7 @@ public class TestGroupingSearch extends
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 coverage
String[] 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) );
}
}