Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-4581: GroupingSearch.setAllGroups(true) was failing to compute allMatchingGroups

Michael McCandless232f38b65d4b
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 24396607b98..5d313748b98 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -182,6 +182,10 @@ Bug Fixes
* LUCENE-4568: Fixed integer overflow in
PagedBytes.PagedBytesData{In,Out}put.getPosition. (Adrien Grand)
+* LUCENE-4581: GroupingSearch.setAllGroups(true) was failing to
+ actually compute allMatchingGroups ([email protected] via Mike
+ McCandless)
+
Optimizations
* LUCENE-2221: oal.util.BitUtil was modified to use Long.bitCount and
diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java
index ba7e877c12f..ddb5ca8a00e 100644
--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java
+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/GroupingSearch.java
@@ -210,7 +210,7 @@ public class GroupingSearch {
if (allGroupHeads || allGroups) {
List<Collector> collectors = new ArrayList<Collector>();
collectors.add(firstPassCollector);
- if (allGroupHeads) {
+ if (allGroups) {
collectors.add(allGroupsCollector);
}
if (allGroupHeads) {
@@ -403,7 +403,7 @@ public class GroupingSearch {
}
/**
- * Whether to also co0.0mpute all groups matching the query.
+ * Whether to also compute all groups matching the query.
* This can be used to determine the number of groups, which can be used for accurate pagination.
* <p/>
* When grouping by doc block the number of groups are automatically included in the {@link TopGroups} and this
diff --git a/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java b/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
index 2267fe716f3..9a5e7089ba1 100644
--- a/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
+++ b/lucene/grouping/src/test/org/apache/lucene/search/grouping/GroupingSearchTest.java
@@ -227,5 +227,29 @@ public class GroupingSearchTest extends LuceneTestCase {
return groupingSearch;
}
-
+
+ public void testSetAllGroups() throws Exception {
+ Directory dir = newDirectory();
+ RandomIndexWriter w = new RandomIndexWriter(
+ random(),
+ dir,
+ newIndexWriterConfig(TEST_VERSION_CURRENT,
+ new MockAnalyzer(random())).setMergePolicy(newLogMergePolicy()));
+ Document doc = new Document();
+ doc.add(newField("group", "foo", StringField.TYPE_NOT_STORED));
+ w.addDocument(doc);
+
+ IndexSearcher indexSearcher = new IndexSearcher(w.getReader());
+ w.close();
+
+ GroupingSearch gs = new GroupingSearch("group");
+ gs.setAllGroups(true);
+ TopGroups<?> groups = gs.search(indexSearcher, null, new TermQuery(new Term("group", "foo")), 0, 10);
+ assertEquals(1, groups.totalHitCount);
+ //assertEquals(1, groups.totalGroupCount.intValue());
+ assertEquals(1, groups.totalGroupedHitCount);
+ assertEquals(1, gs.getAllMatchingGroups().size());
+ indexSearcher.getIndexReader().close();
+ dir.close();
+ }
}