SOLR-413: cap lastDocRequested at maxDoc()

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@596359 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2007-11-19 16:38:50 +00:00
parent 5e9219e490
commit 91c7b66ecf
3 changed files with 27 additions and 7 deletions

View File

@ -211,6 +211,9 @@ Bug Fixes
12. 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 Changes
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
build scripts to make two jars: apache-solr-1.3.jar and

View File

@ -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;

View File

@ -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']"
);