Apache Nutch is an extensible and scalable web crawler
NUTCH-244, db.max.outlinks.per.page can now be negative for no limit of handled outlinks per page
Jerome Charronb0c8b61b4043
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 80be0973c..d1b1493fb 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -255,6 +255,8 @@<name>db.max.outlinks.per.page</name><value>100</value><description>The maximum number of outlinks that we'll process for a page.+ If this value is nonnegative (>=0), at most db.max.outlinks.per.page outlinks+ will be processed for a page; otherwise, all outlinks will be processed.</description></property>diff --git a/src/java/org/apache/nutch/parse/ParseData.java b/src/java/org/apache/nutch/parse/ParseData.javaindex 38b33ab43..c4b76e83d 100644--- a/src/java/org/apache/nutch/parse/ParseData.java+++ b/src/java/org/apache/nutch/parse/ParseData.java@@ -119,12 +119,15 @@ public final class ParseData extends VersionedWritable implements Configurable {int totalOutlinks = in.readInt(); // read outlinksint maxOutlinksPerPage = this.conf.getInt("db.max.outlinks.per.page", 100);- int outlinksToRead = Math.min(maxOutlinksPerPage, totalOutlinks);+ int outlinksToRead = totalOutlinks;+ if (maxOutlinksPerPage >= 0) {+ outlinksToRead = Math.min(maxOutlinksPerPage, totalOutlinks);+ }outlinks = new Outlink[outlinksToRead];for (int i = 0; i < outlinksToRead; i++) {outlinks[i] = Outlink.read(in);}- for (int i = maxOutlinksPerPage; i < totalOutlinks; i++) {+ for (int i = outlinksToRead; i < totalOutlinks; i++) {Outlink.skip(in);}diff --git a/src/test/org/apache/nutch/parse/TestParseData.java b/src/test/org/apache/nutch/parse/TestParseData.javaindex 3e9a8010b..880b404ca 100644--- a/src/test/org/apache/nutch/parse/TestParseData.java+++ b/src/test/org/apache/nutch/parse/TestParseData.java@@ -51,4 +51,31 @@ public class TestParseData extends TestCase {WritableTestUtils.testWritable(r, conf);}+ public void testMaxOutlinks() throws Exception {+ Outlink[] outlinks = new Outlink[128];+ for (int i=0; i<outlinks.length; i++) {+ outlinks[i] = new Outlink("http://outlink.com/" + i, "Outlink" + i, conf);+ }+ ParseData original = new ParseData(ParseStatus.STATUS_SUCCESS,+ "Max Outlinks Title",+ outlinks,+ new Metadata());+ Configuration conf = NutchConfiguration.create();+ // No Outlinks+ conf.setInt("db.max.outlinks.per.page", 0);+ ParseData data = (ParseData) WritableTestUtils.writeRead(original, conf);+ assertEquals(0, data.getOutlinks().length);+ // Only 100 Outlinks+ conf.setInt("db.max.outlinks.per.page", 100);+ data = (ParseData) WritableTestUtils.writeRead(original, conf);+ assertEquals(100, data.getOutlinks().length);+ // 256 Outlinks+ conf.setInt("db.max.outlinks.per.page", 256);+ data = (ParseData) WritableTestUtils.writeRead(original, conf);+ assertEquals(outlinks.length, data.getOutlinks().length);+ // All Outlinks+ conf.setInt("db.max.outlinks.per.page", -1);+ data = (ParseData) WritableTestUtils.writeRead(original, conf);+ assertEquals(outlinks.length, data.getOutlinks().length);+ }}diff --git a/src/test/org/apache/nutch/util/WritableTestUtils.java b/src/test/org/apache/nutch/util/WritableTestUtils.javaindex 6b440b0ce..3ca425278 100644--- a/src/test/org/apache/nutch/util/WritableTestUtils.java+++ b/src/test/org/apache/nutch/util/WritableTestUtils.java@@ -31,6 +31,14 @@ public class WritableTestUtils {/** Utility method for testing writables. */public static void testWritable(Writable before, Configuration conf)throws Exception {+ TestCase.assertEquals(before, writeRead(before, conf));+ }+++ /** Utility method for testing writables. */+ public static Writable writeRead(Writable before, Configuration conf)+ throws Exception {+DataOutputBuffer dob = new DataOutputBuffer();before.write(dob);@@ -42,8 +50,7 @@ public class WritableTestUtils {((Configurable)after).setConf(conf);}after.readFields(dib);-- TestCase.assertEquals(before, after);+ return after;}-+}