mirror of https://github.com/apache/lucene.git
LUCENE-2119: behave better if you pass Integer.MAX_VALUE as nDcos to search methods
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@887670 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f011f59fe2
commit
ae72952fa4
|
@ -32,6 +32,10 @@ Bug fixes
|
|||
one of the threads before all changes are actually committed.
|
||||
(Sanne Grinovero via Mike McCandless)
|
||||
|
||||
* LUCENE-2119: Don't throw NegativeArraySizeException if you pass
|
||||
Integer.MAX_VALUE as nDocs to IndexSearcher search methods. (Paul
|
||||
Taylor via Mike McCandless)
|
||||
|
||||
New features
|
||||
|
||||
* LUCENE-2069: Added Unicode 4 support to CharArraySet. Due to the switch
|
||||
|
|
|
@ -158,12 +158,14 @@ public class IndexSearcher extends Searcher {
|
|||
|
||||
// inherit javadoc
|
||||
@Override
|
||||
public TopDocs search(Weight weight, Filter filter, final int nDocs) throws IOException {
|
||||
public TopDocs search(Weight weight, Filter filter, int nDocs) throws IOException {
|
||||
|
||||
if (nDocs <= 0) {
|
||||
throw new IllegalArgumentException("nDocs must be > 0");
|
||||
}
|
||||
|
||||
nDocs = Math.min(nDocs, reader.maxDoc());
|
||||
|
||||
TopScoreDocCollector collector = TopScoreDocCollector.create(nDocs, !weight.scoresDocsOutOfOrder());
|
||||
search(weight, filter, collector);
|
||||
return collector.topDocs();
|
||||
|
@ -186,9 +188,12 @@ public class IndexSearcher extends Searcher {
|
|||
* then pass that to {@link #search(Weight, Filter,
|
||||
* Collector)}.</p>
|
||||
*/
|
||||
public TopFieldDocs search(Weight weight, Filter filter, final int nDocs,
|
||||
public TopFieldDocs search(Weight weight, Filter filter, int nDocs,
|
||||
Sort sort, boolean fillFields)
|
||||
throws IOException {
|
||||
|
||||
nDocs = Math.min(nDocs, reader.maxDoc());
|
||||
|
||||
TopFieldCollector collector = TopFieldCollector.create(sort, nDocs,
|
||||
fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.scoresDocsOutOfOrder());
|
||||
search(weight, filter, collector);
|
||||
|
|
|
@ -85,8 +85,18 @@ public abstract class PriorityQueue<T> {
|
|||
if (0 == maxSize)
|
||||
// We allocate 1 extra to avoid if statement in top()
|
||||
heapSize = 2;
|
||||
else
|
||||
heapSize = maxSize + 1;
|
||||
else {
|
||||
if (maxSize == Integer.MAX_VALUE) {
|
||||
// Don't wrap heapSize to -1, in this case, which
|
||||
// causes a confusing NegativeArraySizeException.
|
||||
// Note that very likely this will simply then hit
|
||||
// an OOME, but at least that's more indicative to
|
||||
// caller that this values is too big:
|
||||
heapSize = Integer.MAX_VALUE;
|
||||
} else {
|
||||
heapSize = maxSize + 1;
|
||||
}
|
||||
}
|
||||
heap = (T[]) new Object[heapSize]; // T is unbounded type, so this unchecked cast works always
|
||||
this.maxSize = maxSize;
|
||||
|
||||
|
|
Loading…
Reference in New Issue