Apache Solr open-source search software
SOLR-413: cap lastDocRequested at maxDoc()
Yonik Seeley91c7b66ecfd2
diff --git a/CHANGES.txt b/CHANGES.txtindex 3004b94591d..174f6554031 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -211,6 +211,9 @@ Bug Fixes12. SOLR-393: Removed duplicate contentType from raw-schema.jsp. (bill)+13. SOLR-413: Requesting a large numbers of documents to be returned (limit)+ can result in an out-of-memory exception, even for a small index. (yonik)+Other Changes1. SOLR-135: Moved common classes to org.apache.solr.common and altered thebuild scripts to make two jars: apache-solr-1.3.jar anddiff --git a/src/java/org/apache/solr/search/SolrIndexSearcher.java b/src/java/org/apache/solr/search/SolrIndexSearcher.javaindex 64f74ee1e48..ceaf849d86c 100644--- a/src/java/org/apache/solr/search/SolrIndexSearcher.java+++ b/src/java/org/apache/solr/search/SolrIndexSearcher.java@@ -37,7 +37,6 @@ import java.net.URL;import java.util.*;import java.util.logging.Level;import java.util.logging.Logger;-import org.apache.solr.core.SolrInfoMBean.Category;/**@@ -707,8 +706,10 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean {*/private void getDocListC(DocListAndSet out, Query query, List<Query> filterList, DocSet filter, Sort lsort, int offset, int len, int flags) throws IOException {QueryResultKey key=null;- int maxDoc = offset + len;- int supersetMaxDoc=maxDoc;+ int maxDocRequested = offset + len;+ // check for overflow, and check for # docs in index+ if (maxDocRequested < 0 || maxDocRequested > maxDoc()) maxDocRequested = maxDoc();+ int supersetMaxDoc= maxDocRequested;DocList superset;@@ -752,10 +753,11 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean {// next resultWindowSize for better caching.// handle 0 special case as well as avoid idiv in the common case.- if (maxDoc < queryResultWindowSize) {+ if (maxDocRequested < queryResultWindowSize) {supersetMaxDoc=queryResultWindowSize;} else {- supersetMaxDoc = ((maxDoc-1)/queryResultWindowSize + 1)*queryResultWindowSize;+ supersetMaxDoc = ((maxDocRequested -1)/queryResultWindowSize + 1)*queryResultWindowSize;+ if (supersetMaxDoc < 0) supersetMaxDoc=maxDocRequested;}}@@ -819,7 +821,9 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean {private DocList getDocListNC(Query query, DocSet filter, Sort lsort, int offset, int len, int flags) throws IOException {- final int lastDocRequested = offset+len;+ int last = offset+len;+ if (last < 0 || last > maxDoc()) last=maxDoc();+ final int lastDocRequested = last;int nDocsReturned;int totalHits;float maxScore;@@ -977,7 +981,9 @@ public class SolrIndexSearcher extends Searcher implements SolrInfoMBean {// the DocSet returned is for the query only, without any filtering... that way it may// be cached if desired.private DocSet getDocListAndSetNC(DocListAndSet out, Query query, DocSet filter, Sort lsort, int offset, int len, int flags) throws IOException {- final int lastDocRequested = offset+len;+ int last = offset+len;+ if (last < 0 || last > maxDoc()) last=maxDoc();+ final int lastDocRequested = last;int nDocsReturned;int totalHits;float maxScore;diff --git a/src/test/org/apache/solr/BasicFunctionalityTest.java b/src/test/org/apache/solr/BasicFunctionalityTest.javaindex fb629a5a9c6..6822dc21e2a 100644--- a/src/test/org/apache/solr/BasicFunctionalityTest.java+++ b/src/test/org/apache/solr/BasicFunctionalityTest.java@@ -145,6 +145,17 @@ public class BasicFunctionalityTest extends AbstractSolrTestCase {assertU(a, a);}assertU(commit());++ // test maxint+ assertQ(req("q","id:[100 TO 110]", "rows","2147483647")+ ,"//*[@numFound='4']"+ );++ // test big limit+ assertQ(req("q","id:[100 TO 111]", "rows","1147483647")+ ,"//*[@numFound='4']"+ );+assertQ(req("id:[100 TO 110]"),"//*[@numFound='4']");