Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fix NegativeArraySizeException.

Douglass Cuttingd4778aa03495
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index d23f3115c..1ab6d0031 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -661,10 +661,11 @@
<property>
<name>searcher.max.hits</name>
- <value>2147483647</value>
- <description>Search stops after this many hits are found. Setting
- this to smaller values can make searches much faster. With a sorted
- index, the quality of the hits suffers little.</description>
+ <value>-1</value>
+ <description>If positive, search stops after this many hits are
+ found. Setting this to small, positive values (e.g., 1000) can make
+ searches much faster. With a sorted index, the quality of the hits
+ suffers little.</description>
</property>
<!-- URL normalizer properties -->
diff --git a/src/java/org/apache/nutch/searcher/LuceneQueryOptimizer.java b/src/java/org/apache/nutch/searcher/LuceneQueryOptimizer.java
index fe1b08b92..35c9277ef 100644
--- a/src/java/org/apache/nutch/searcher/LuceneQueryOptimizer.java
+++ b/src/java/org/apache/nutch/searcher/LuceneQueryOptimizer.java
@@ -37,8 +37,7 @@ import java.io.IOException;
* which do not affect ranking but might otherwise slow search considerably. */
class LuceneQueryOptimizer {
- private static int MAX_HITS =
- NutchConf.get().getInt("searcher.max.hits", Integer.MAX_VALUE);
+ private static int MAX_HITS = NutchConf.get().getInt("searcher.max.hits",-1);
private static class LimitExceeded extends RuntimeException {
private int maxDoc;
@@ -150,6 +149,13 @@ class LuceneQueryOptimizer {
}
}
if (sortField == null && !reverse) {
+
+ // no hit limit
+ if (MAX_HITS <= 0) {
+ return searcher.search(query, filter, numHits);
+ }
+
+ // hits limited -- use a LimitedCollector
LimitedCollector collector = new LimitedCollector(numHits, MAX_HITS);
LimitExceeded exceeded = null;
try {