SOLR-3454: Exception when using result grouping with main=true and using wt=javabin

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1340080 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Martijn van Groningen 2012-05-18 12:28:21 +00:00
parent 6248459183
commit 0b1d814c94
3 changed files with 93 additions and 51 deletions

View File

@ -425,6 +425,9 @@ Bug Fixes
* SOLR-3436: Group count incorrect when not all shards are queried in the second
pass. (Francois Perron, Martijn van Groningen)
* SOLR-3454: Exception when using result grouping with main=true and using
wt=javabin. (Ludovic Boutros, Martijn van Groningen)
Other Changes
----------------------

View File

@ -651,7 +651,7 @@ public class Grouping {
}
}
int len = docsGathered - offset;
int len = docsGathered > offset ? docsGathered - offset : 0;
int[] docs = ArrayUtils.toPrimitive(ids.toArray(new Integer[ids.size()]));
float[] docScores = ArrayUtils.toPrimitive(scores.toArray(new Float[scores.size()]));
DocSlice docSlice = new DocSlice(offset, len, docs, docScores, getMatches(), maxScore);

View File

@ -20,13 +20,21 @@ package org.apache.solr;
import org.apache.lucene.search.FieldCache;
import org.apache.noggit.JSONUtil;
import org.apache.noggit.ObjectBuilder;
import org.apache.solr.client.solrj.impl.BinaryResponseParser;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.GroupParams;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.request.SolrRequestInfo;
import org.apache.solr.response.BinaryResponseWriter;
import org.apache.solr.response.ResultContext;
import org.apache.solr.response.SolrQueryResponse;
import org.apache.solr.schema.IndexSchema;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.*;
public class TestGroupingSearch extends SolrTestCaseJ4 {
@ -214,6 +222,37 @@ public class TestGroupingSearch extends SolrTestCaseJ4 {
);
}
@Test
public void testGroupingSimpleFormatArrayIndexOutOfBoundsExceptionWithJavaBin() throws Exception {
assertU(add(doc("id", "1", "nullfirst", "1")));
assertU(add(doc("id", "2", "nullfirst", "1")));
assertU(add(doc("id", "3", "nullfirst", "2")));
assertU(add(doc("id", "4", "nullfirst", "2")));
assertU(add(doc("id", "5", "nullfirst", "2")));
assertU(add(doc("id", "6", "nullfirst", "3")));
assertU(commit());
SolrQueryRequest request =
req("q", "*:*","group", "true", "group.field", "nullfirst", "group.main", "true", "wt", "javabin", "start", "4", "rows", "10");
SolrQueryResponse response = new SolrQueryResponse();
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
SolrRequestInfo.setRequestInfo(new SolrRequestInfo(request, response));
String handlerName = request.getParams().get(CommonParams.QT);
h.getCore().execute(h.getCore().getRequestHandler(handlerName), request, response);
BinaryResponseWriter responseWriter = new BinaryResponseWriter();
responseWriter.write(out, request, response);
} finally {
request.close();
SolrRequestInfo.clearRequestInfo();
}
assertEquals(6, ((ResultContext) response.getValues().get("response")).docs.matches());
new BinaryResponseParser().processResponse(new ByteArrayInputStream(out.toByteArray()), "");
out.close();
}
@Test
public void testGroupingWithTimeAllowed() throws Exception {
assertU(add(doc("id", "1")));