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 1713ec8ea30..78c6ccf1c61 100644 --- a/solr/src/java/org/apache/solr/handler/component/QueryComponent.java +++ b/solr/src/java/org/apache/solr/handler/component/QueryComponent.java @@ -245,7 +245,9 @@ public class QueryComponent extends SearchComponent if (cmd.groupCommands != null) { searcher.search(result,cmd); + rb.setResult( result ); rsp.add("grouped", result.groupedResults); + // TODO: get "hits" a different way return; } } catch (ParseException e) { diff --git a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java index d0c6140694e..829e235f196 100644 --- a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -912,7 +912,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean { if (last < 0 || last > maxDoc()) last=maxDoc(); boolean needScores = (cmd.getFlags() & GET_SCORES) != 0; - + boolean getDocSet = (cmd.getFlags() & GET_DOCSET) != 0; Query query = QueryUtils.makeQueryable(cmd.getQuery()); final Filter luceneFilter = filter==null ? null : filter.getTopFilter(); @@ -943,7 +943,19 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean { } } - search(query, luceneFilter, MultiCollector.wrap(collectors)); + Collector allCollectors = MultiCollector.wrap(collectors); + DocSetCollector setCollector = null; + if (getDocSet) { + // TODO: can callCollectors be zero length? + setCollector = new DocSetDelegateCollector(maxDoc()>>6, maxDoc(), allCollectors); + allCollectors = setCollector; + } + + search(query, luceneFilter, allCollectors); + + if (getDocSet) { + qr.docListAndSet.docSet = setCollector.getDocSet(); + } // TODO: make this a generic collector list List phase2Collectors = new ArrayList(cmd.groupCommands.size()); diff --git a/solr/src/test/org/apache/solr/TestGroupingSearch.java b/solr/src/test/org/apache/solr/TestGroupingSearch.java index 6b3dcf273c2..df5ada634ff 100644 --- a/solr/src/test/org/apache/solr/TestGroupingSearch.java +++ b/solr/src/test/org/apache/solr/TestGroupingSearch.java @@ -17,6 +17,7 @@ package org.apache.solr; +import org.apache.lucene.search.FieldCache; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -214,7 +215,15 @@ public class TestGroupingSearch extends SolrTestCaseJ4 { "]}}" ); - }; + // test that faceting works with grouping + assertJQ(req("fq",filt, "q","{!func}"+f2, "group","true", "group.field",f, "fl","id" + ,"facet","true", "facet.field",f) + ,"/grouped/foo_i/matches:10:" + ,"/facet_counts/facet_fields/"+f+":['1',3, '2',3, '3',2, '4',1, '5',1]" + ); + purgeFieldCache(FieldCache.DEFAULT); // avoid FC insanity + + }; }