lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m..@apache.org
Subject svn commit: r1338227 - in /lucene/dev/branches/lucene_solr_3_6/solr: ./ core/src/java/org/apache/solr/handler/component/ core/src/java/org/apache/solr/search/grouping/distributed/command/ core/src/java/org/apache/solr/search/grouping/distributed/respon...
Date Mon, 14 May 2012 14:38:38 GMT
Author: mvg
Date: Mon May 14 14:38:37 2012
New Revision: 1338227

URL: http://svn.apache.org/viewvc?rev=1338227&view=rev
Log:
SOLR-3436: Group count incorrect when not all shards are queried in the second pass.

Added:
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java
Modified:
    lucene/dev/branches/lucene_solr_3_6/solr/CHANGES.txt
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/TopGroupsFieldCommand.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java
    lucene/dev/branches/lucene_solr_3_6/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java

Modified: lucene/dev/branches/lucene_solr_3_6/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/CHANGES.txt?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/CHANGES.txt Mon May 14 14:38:37 2012
@@ -33,6 +33,9 @@ Bug Fixes:
 
 * SOLR-3375: Fix charset problems with HttpSolrServer (Roger HÃ¥kansson, yonik, siren)
 
+* SOLR-3436: Group count incorrect when not all shards are queried in the second
+  pass. (Francois Perron, Martijn van Groningen)
+
 ==================  3.6.0  ==================
 More information about this release, including any errata related to the 
 release notes, upgrade instructions, or other changes may be found online at:

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/QueryComponent.java
Mon May 14 14:38:37 2012
@@ -272,6 +272,7 @@ public class QueryComponent extends Sear
                 .setField(searcher.getSchema().getField(field))
                 .setGroupSort(groupingSpec.getGroupSort())
                 .setTopNGroups(cmd.getOffset() + cmd.getLen())
+                .setIncludeGroupCount(groupingSpec.isIncludeGroupCount())
                 .build()
             );
           }
@@ -313,7 +314,6 @@ public class QueryComponent extends Sear
                     .setMaxDocPerGroup(groupingSpec.getGroupOffset() + groupingSpec.getGroupLimit())
                     .setNeedScores(needScores)
                     .setNeedMaxScore(needScores)
-                    .setNeedGroupCount(groupingSpec.isIncludeGroupCount())
                     .build()
             );
           }

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/handler/component/ResponseBuilder.java
Mon May 14 14:38:37 2012
@@ -154,6 +154,7 @@ public class ResponseBuilder
 
   // Context fields for grouping
   public final Map<String, Collection<SearchGroup<String>>> mergedSearchGroups
= new HashMap<String, Collection<SearchGroup<String>>>();
+  public final Map<String, Integer> mergedGroupCounts = new HashMap<String, Integer>();
   public final Map<String, Map<SearchGroup<String>, Set<String>>>
searchGroupToShards = new HashMap<String, Map<SearchGroup<String>, Set<String>>>();
   public final Map<String, TopGroups<String>> mergedTopGroups = new HashMap<String,
TopGroups<String>>();
   public final Map<String, QueryCommandResult> mergedQueryCommandResults = new HashMap<String,
QueryCommandResult>();

Added: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java?rev=1338227&view=auto
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java
(added)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/Pair.java
Mon May 14 14:38:37 2012
@@ -0,0 +1,42 @@
+package org.apache.solr.search.grouping.distributed.command;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * A simple data structure to hold a pair of typed objects.
+ *
+ * @lucene.experimental
+ */
+public class Pair<A, B> {
+
+  private final A a;
+  private final B b;
+
+  public Pair(A a, B b) {
+    this.a = a;
+    this.b = b;
+  }
+
+  public A getA() {
+    return a;
+  }
+
+  public B getB() {
+    return b;
+  }
+}

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/SearchGroupsFieldCommand.java
Mon May 14 14:38:37 2012
@@ -20,26 +20,25 @@ package org.apache.solr.search.grouping.
 import org.apache.lucene.search.Collector;
 import org.apache.lucene.search.Sort;
 import org.apache.lucene.search.grouping.SearchGroup;
+import org.apache.lucene.search.grouping.TermAllGroupsCollector;
 import org.apache.lucene.search.grouping.TermFirstPassGroupingCollector;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.grouping.Command;
 
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 
 /**
- *
+ * Creates all the collectors needed for the first phase and how to handle the results.
  */
-public class SearchGroupsFieldCommand implements Command<Collection<SearchGroup<String>>>
{
+public class SearchGroupsFieldCommand implements Command<Pair<Integer, Collection<SearchGroup<String>>>>
{
 
   public static class Builder {
 
     private SchemaField field;
     private Sort groupSort;
     private Integer topNGroups;
+    private boolean includeGroupCount = false;
 
     public Builder setField(SchemaField field) {
       this.field = field;
@@ -56,12 +55,17 @@ public class SearchGroupsFieldCommand im
       return this;
     }
 
+    public Builder setIncludeGroupCount(boolean includeGroupCount) {
+      this.includeGroupCount = includeGroupCount;
+      return this;
+    }
+
     public SearchGroupsFieldCommand build() {
       if (field == null || groupSort == null || topNGroups == null) {
         throw new IllegalStateException("All fields must be set");
       }
 
-      return new SearchGroupsFieldCommand(field, groupSort, topNGroups);
+      return new SearchGroupsFieldCommand(field, groupSort, topNGroups, includeGroupCount);
     }
 
   }
@@ -69,30 +73,45 @@ public class SearchGroupsFieldCommand im
   private final SchemaField field;
   private final Sort groupSort;
   private final int topNGroups;
+  private final boolean includeGroupCount;
 
   private TermFirstPassGroupingCollector firstPassGroupingCollector;
+  private TermAllGroupsCollector allGroupsCollector;
 
-  private SearchGroupsFieldCommand(SchemaField field, Sort groupSort, int topNGroups) {
+  private SearchGroupsFieldCommand(SchemaField field, Sort groupSort, int topNGroups, boolean
includeGroupCount) {
     this.field = field;
     this.groupSort = groupSort;
     this.topNGroups = topNGroups;
+    this.includeGroupCount = includeGroupCount;
   }
 
   public List<Collector> create() throws IOException {
+    List<Collector> collectors = new ArrayList<Collector>();
     if (topNGroups > 0) {
       firstPassGroupingCollector = new TermFirstPassGroupingCollector(field.getName(), groupSort,
topNGroups);
-      return Arrays.asList((Collector) firstPassGroupingCollector);
-    } else {
-      return Collections.emptyList();
+      collectors.add(firstPassGroupingCollector);
     }
+    if (includeGroupCount) {
+      allGroupsCollector = new TermAllGroupsCollector(field.getName());
+      collectors.add(allGroupsCollector);
+    }
+    return collectors;
   }
 
-  public Collection<SearchGroup<String>> result() {
+  public Pair<Integer, Collection<SearchGroup<String>>> result() {
+    final Collection<SearchGroup<String>> topGroups;
     if (topNGroups > 0) {
-      return firstPassGroupingCollector.getTopGroups(0, true);
+      topGroups = firstPassGroupingCollector.getTopGroups(0, true);
+    } else {
+      topGroups = Collections.emptyList();
+    }
+    final Integer groupCount;
+    if (includeGroupCount) {
+      groupCount = allGroupsCollector.getGroupCount();
     } else {
-      return Collections.emptyList();
+      groupCount = null;
     }
+    return new Pair<Integer, Collection<SearchGroup<String>>>(groupCount,
topGroups);
   }
 
   public Sort getSortWithinGroup() {

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/TopGroupsFieldCommand.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/TopGroupsFieldCommand.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/TopGroupsFieldCommand.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/command/TopGroupsFieldCommand.java
Mon May 14 14:38:37 2012
@@ -30,7 +30,7 @@ import java.util.Collections;
 import java.util.List;
 
 /**
- *
+ * Defines all collectors for retrieving the second phase and how to handle the collector
result.
  */
 public class TopGroupsFieldCommand implements Command<TopGroups<String>> {
 
@@ -43,7 +43,6 @@ public class TopGroupsFieldCommand imple
     private Integer maxDocPerGroup;
     private boolean needScores = false;
     private boolean needMaxScore = false;
-    private boolean needGroupCount = false;
 
     public Builder setField(SchemaField field) {
       this.field = field;
@@ -80,18 +79,13 @@ public class TopGroupsFieldCommand imple
       return this;
     }
 
-    public Builder setNeedGroupCount(Boolean needGroupCount) {
-      this.needGroupCount = needGroupCount;
-      return this;
-    }
-
     public TopGroupsFieldCommand build() {
       if (field == null || groupSort == null ||  sortWithinGroup == null || firstPhaseGroups
== null ||
           maxDocPerGroup == null) {
         throw new IllegalStateException("All required fields must be set");
       }
 
-      return new TopGroupsFieldCommand(field, groupSort, sortWithinGroup, firstPhaseGroups,
maxDocPerGroup, needScores, needMaxScore, needGroupCount);
+      return new TopGroupsFieldCommand(field, groupSort, sortWithinGroup, firstPhaseGroups,
maxDocPerGroup, needScores, needMaxScore);
     }
 
   }
@@ -103,10 +97,7 @@ public class TopGroupsFieldCommand imple
   private final int maxDocPerGroup;
   private final boolean needScores;
   private final boolean needMaxScore;
-  private final boolean needGroupCount;
-
   private TermSecondPassGroupingCollector secondPassCollector;
-  private TermAllGroupsCollector allGroupsCollector;
 
   private TopGroupsFieldCommand(SchemaField field,
                                 Sort groupSort,
@@ -114,8 +105,7 @@ public class TopGroupsFieldCommand imple
                                 Collection<SearchGroup<String>> firstPhaseGroups,
                                 int maxDocPerGroup,
                                 boolean needScores,
-                                boolean needMaxScore,
-                                boolean needGroupCount) {
+                                boolean needMaxScore) {
     this.field = field;
     this.groupSort = groupSort;
     this.sortWithinGroup = sortWithinGroup;
@@ -123,7 +113,6 @@ public class TopGroupsFieldCommand imple
     this.maxDocPerGroup = maxDocPerGroup;
     this.needScores = needScores;
     this.needMaxScore = needMaxScore;
-    this.needGroupCount = needGroupCount;
   }
 
   public List<Collector> create() throws IOException {
@@ -136,11 +125,6 @@ public class TopGroupsFieldCommand imple
           field.getName(), firstPhaseGroups, groupSort, sortWithinGroup, maxDocPerGroup,
needScores, needMaxScore, true
     );
     collectors.add(secondPassCollector);
-    if (!needGroupCount) {
-      return collectors;
-    }
-    allGroupsCollector = new TermAllGroupsCollector(field.getName());
-    collectors.add(allGroupsCollector);
     return collectors;
   }
 
@@ -150,11 +134,7 @@ public class TopGroupsFieldCommand imple
       return new TopGroups<String>(groupSort.getSort(), sortWithinGroup.getSort(),
0, 0, new GroupDocs[0]);
     }
 
-    TopGroups<String> result = secondPassCollector.getTopGroups(0);
-    if (allGroupsCollector != null) {
-      result = new TopGroups<String>(result, allGroupsCollector.getGroupCount());
-    }
-    return result;
+    return secondPassCollector.getTopGroups(0);
   }
 
   public String getKey() {

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/responseprocessor/SearchGroupShardResponseProcessor.java
Mon May 14 14:38:37 2012
@@ -26,6 +26,7 @@ import org.apache.solr.handler.component
 import org.apache.solr.handler.component.ShardResponse;
 import org.apache.solr.search.SortSpec;
 import org.apache.solr.search.grouping.distributed.ShardResponseProcessor;
+import org.apache.solr.search.grouping.distributed.command.Pair;
 import org.apache.solr.search.grouping.distributed.shardresultserializer.SearchGroupsResultTransformer;
 
 import java.io.IOException;
@@ -62,9 +63,17 @@ public class SearchGroupShardResponsePro
         maxElapsedTime = (int) Math.max(maxElapsedTime, srsp.getSolrResponse().getElapsedTime());
         @SuppressWarnings("unchecked")
         NamedList<NamedList> firstPhaseResult = (NamedList<NamedList>) srsp.getSolrResponse().getResponse().get("firstPhase");
-        Map<String, Collection<SearchGroup<String>>> result = serializer.transformToNative(firstPhaseResult,
groupSort, null, srsp.getShard());
+        Map<String, Pair<Integer, Collection<SearchGroup<String>>>>
result = serializer.transformToNative(firstPhaseResult, groupSort, null, srsp.getShard());
         for (String field : commandSearchGroups.keySet()) {
-          Collection<SearchGroup<String>> searchGroups = result.get(field);
+          Pair<Integer, Collection<SearchGroup<String>>> firstPhaseCommandResult
= result.get(field);
+          Integer groupCount = firstPhaseCommandResult.getA();
+          if (groupCount != null) {
+            Integer existingGroupCount = rb.mergedGroupCounts.get(field);
+            // Assuming groups don't cross shard boundary...
+            rb.mergedGroupCounts.put(field, existingGroupCount != null ? existingGroupCount
+ groupCount : groupCount);
+          }
+
+          Collection<SearchGroup<String>> searchGroups = firstPhaseCommandResult.getB();
           if (searchGroups == null) {
             continue;
           }

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/SearchGroupsResultTransformer.java
Mon May 14 14:38:37 2012
@@ -25,6 +25,7 @@ import org.apache.solr.schema.FieldType;
 import org.apache.solr.schema.SchemaField;
 import org.apache.solr.search.SolrIndexSearcher;
 import org.apache.solr.search.grouping.Command;
+import org.apache.solr.search.grouping.distributed.command.Pair;
 import org.apache.solr.search.grouping.distributed.command.SearchGroupsFieldCommand;
 
 import java.io.IOException;
@@ -33,7 +34,7 @@ import java.util.*;
 /**
  * Implementation for transforming {@link SearchGroup} into a {@link NamedList} structure
and visa versa.
  */
-public class SearchGroupsResultTransformer implements ShardResultTransformer<List<Command>,
Map<String, Collection<SearchGroup<String>>>> {
+public class SearchGroupsResultTransformer implements ShardResultTransformer<List<Command>,
Map<String, Pair<Integer, Collection<SearchGroup<String>>>>> {
 
   private final SolrIndexSearcher searcher;
 
@@ -47,17 +48,20 @@ public class SearchGroupsResultTransform
   public NamedList transform(List<Command> data) throws IOException {
     NamedList<NamedList> result = new NamedList<NamedList>();
     for (Command command : data) {
-      NamedList commandResult;
+      final NamedList<Object> commandResult = new NamedList<Object>();
       if (SearchGroupsFieldCommand.class.isInstance(command)) {
         SearchGroupsFieldCommand fieldCommand = (SearchGroupsFieldCommand) command;
-        Collection<SearchGroup<String>> searchGroups = fieldCommand.result();
-        if (searchGroups == null) {
-          continue;
+        Pair<Integer, Collection<SearchGroup<String>>> pair = fieldCommand.result();
+        Integer groupedCount = pair.getA();
+        Collection<SearchGroup<String>> searchGroups = pair.getB();
+        if (searchGroups != null) {
+          commandResult.add("topGroups", serializeSearchGroup(searchGroups, fieldCommand.getGroupSort()));
+        }
+        if (groupedCount != null) {
+          commandResult.add("groupCount", groupedCount);
         }
-
-        commandResult = serializeSearchGroup(searchGroups, fieldCommand.getGroupSort());
       } else {
-        commandResult = null;
+        continue;
       }
 
       result.add(command.getKey(), commandResult);
@@ -68,20 +72,24 @@ public class SearchGroupsResultTransform
   /**
    * {@inheritDoc}
    */
-  public Map<String, Collection<SearchGroup<String>>> transformToNative(NamedList<NamedList>
shardResponse, Sort groupSort, Sort sortWithinGroup, String shard) throws IOException {
-    Map<String, Collection<SearchGroup<String>>> result = new HashMap<String,
Collection<SearchGroup<String>>>();
+  public Map<String, Pair<Integer, Collection<SearchGroup<String>>>>
transformToNative(NamedList<NamedList> shardResponse, Sort groupSort, Sort sortWithinGroup,
String shard) throws IOException {
+    Map<String, Pair<Integer, Collection<SearchGroup<String>>>> result
= new HashMap<String, Pair<Integer, Collection<SearchGroup<String>>>>();
     for (Map.Entry<String, NamedList> command : shardResponse) {
       List<SearchGroup<String>> searchGroups = new ArrayList<SearchGroup<String>>();
+      NamedList topGroupsAndGroupCount = command.getValue();
       @SuppressWarnings("unchecked")
-      NamedList<List<Comparable>> rawSearchGroups = command.getValue();
-      for (Map.Entry<String, List<Comparable>> rawSearchGroup : rawSearchGroups){
-        SearchGroup<String> searchGroup = new SearchGroup<String>();
-        searchGroup.groupValue = rawSearchGroup.getKey() != null ? rawSearchGroup.getKey()
: null;
-        searchGroup.sortValues = rawSearchGroup.getValue().toArray(new Comparable[rawSearchGroup.getValue().size()]);
-        searchGroups.add(searchGroup);
+      NamedList<List<Comparable>> rawSearchGroups = (NamedList<List<Comparable>>)
topGroupsAndGroupCount.get("topGroups");
+      if (rawSearchGroups != null) {
+        for (Map.Entry<String, List<Comparable>> rawSearchGroup : rawSearchGroups){
+          SearchGroup<String> searchGroup = new SearchGroup<String>();
+          searchGroup.groupValue = rawSearchGroup.getKey() != null ? rawSearchGroup.getKey()
: null;
+          searchGroup.sortValues = rawSearchGroup.getValue().toArray(new Comparable[rawSearchGroup.getValue().size()]);
+          searchGroups.add(searchGroup);
+        }
       }
 
-      result.put(command.getKey(), searchGroups);
+      Integer groupCount = (Integer) topGroupsAndGroupCount.get("groupCount");
+      result.put(command.getKey(), new Pair<Integer, Collection<SearchGroup<String>>>(groupCount,
searchGroups));
     }
     return result;
   }

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/distributed/shardresultserializer/TopGroupsResultTransformer.java
Mon May 14 14:38:37 2012
@@ -113,10 +113,9 @@ public class TopGroupsResultTransformer 
       }
 
       Integer totalHitCount = (Integer) commandResult.get("totalHitCount");
-      Integer totalGroupCount = (Integer) commandResult.get("totalGroupCount");
 
       List<GroupDocs<String>> groupDocs = new ArrayList<GroupDocs<String>>();
-      for (int i = totalGroupCount == null ? 2 : 3; i < commandResult.size(); i++) {
+      for (int i = 2; i < commandResult.size(); i++) {
         String groupValue = commandResult.getName(i);
         @SuppressWarnings("unchecked")
         NamedList<Object> groupResult = (NamedList<Object>) commandResult.getVal(i);
@@ -149,9 +148,6 @@ public class TopGroupsResultTransformer 
       TopGroups<String> topGroups = new TopGroups<String>(
         groupSort.getSort(), sortWithinGroup.getSort(), totalHitCount, totalGroupedHitCount,
groupDocsArr
       );
-      if (totalGroupCount != null) {
-        topGroups = new TopGroups<String>(topGroups, totalGroupCount);
-      }
 
       result.put(key, topGroups);
     }

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/java/org/apache/solr/search/grouping/endresulttransformer/GroupedEndResultTransformer.java
Mon May 14 14:38:37 2012
@@ -56,8 +56,9 @@ public class GroupedEndResultTransformer
         TopGroups<String> topGroups = (TopGroups<String>) value;
         NamedList<Object> command = new SimpleOrderedMap<Object>();
         command.add("matches", rb.totalHitCount);
-        if (topGroups.totalGroupCount != null) {
-          command.add("ngroups", topGroups.totalGroupCount);
+        Integer totalGroupCount = rb.mergedGroupCounts.get(entry.getKey());
+        if (totalGroupCount != null) {
+          command.add("ngroups", totalGroupCount);
         }
 
         List<NamedList> groups = new ArrayList<NamedList>();

Modified: lucene/dev/branches/lucene_solr_3_6/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_3_6/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java?rev=1338227&r1=1338226&r2=1338227&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_3_6/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
(original)
+++ lucene/dev/branches/lucene_solr_3_6/solr/core/src/test/org/apache/solr/TestDistributedGrouping.java
Mon May 14 14:38:37 2012
@@ -172,11 +172,16 @@ public class TestDistributedGrouping ext
     query("q", "*:*", "fq", s2 + ":a", "rows", 100, "fl", "id," + s1, "group", "true", "group.field",
s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.truncate", "true");
     query("q", "*:*", "fq", s2 + ":a", "rows", 100, "fl", "id," + s1, "group", "true", "group.field",
s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.truncate", "true", "facet", "true",
"facet.field", t1);
 
+    // SOLR-3316
     query("q", "*:*", "fq", s2 + ":a", "rows", 0, "fl", "id," + s1, "group", "true", "group.field",
s1, "group.limit", 10, "sort", s1 + " asc, id asc", "facet", "true", "facet.field", t1);
     query("q", "*:*", "fq", s2 + ":a", "rows", 0, "fl", "id," + s1, "group", "true", "group.field",
s1, "group.limit", 10, "sort", s1 + " asc, id asc", "group.truncate", "true", "facet", "true",
"facet.field", t1);
 
+    // SOLR-3436
+    query("q", "*:*", "fq", s1 + ":a", "fl", "id," + s1, "group", "true", "group.field",
s1, "sort", s1 + " asc, id asc", "group.ngroups", "true");
+    query("q", "*:*", "fq", s1 + ":a", "rows", 0, "fl", "id," + s1, "group", "true", "group.field",
s1, "sort", s1 + " asc, id asc", "group.ngroups", "true");
+
     ModifiableSolrParams params = new ModifiableSolrParams();
-    Object[] q =  {"q", "*:*", "fq", s2 + ":a", "rows", 1, "fl", "id," + s1, "group", "true",
"group.field", s1, "group.limit", 10};
+    Object[] q =  {"q", "*:*", "fq", s2 + ":a", "rows", 1, "fl", "id," + s1, "group", "true",
"group.field", s1, "group.limit", 10, "group.ngroups", "true"};
 
     for (int i = 0; i < q.length; i += 2) {
       params.add(q[i].toString(), q[i + 1].toString());
@@ -190,7 +195,9 @@ public class TestDistributedGrouping ext
     NamedList nl = (NamedList<?>) rsp.getResponse().get("grouped");
     nl = (NamedList<?>) nl.getVal(0);
     int matches = (Integer) nl.getVal(0);
+    int groupCount = (Integer) nl.get("ngroups");
     assertEquals(100 * clients.size(), matches);
+    assertEquals(clients.size(), groupCount);
 
     // We cannot validate distributed grouping with scoring as first sort. since there is
no global idf. We can check if no errors occur
     simpleQuery("q", "*:*", "rows", 100, "fl", "id," + s1, "group", "true", "group.field",
s1, "group.limit", 10, "sort", s1 + " desc", "group.sort", "score desc"); // SOLR-2955



Mime
View raw message