Apache Nutch is an extensible and scalable web crawler
NUTCH-1106 Options to skip url's based on length - add property db.max.outlink.length to limit length of outlinks and redirects (default = 8192 characters) - add rule (not active) to regex-urlfilters.txt.template
Sebastian Nagel579a76beb17a
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex ccce56b20..d1af10afa 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -700,6 +700,21 @@</description></property>+<property>+ <name>db.max.outlink.length</name>+ <value>8192</value>+ <description>+ The maximum length in characters accepted for outlinks before+ applying URL normalizers and filters. If this value is+ nonnegative (>=0), only URLs with a length in characters less or+ equal than db.max.outlink.length are accepted and then passed to+ URL normalizers and filters. Doing the length check beforehand+ avoids that normalizers or filters hang up on overlong URLs.+ Note: this property is only used to check URLs found as outlinks+ and redirects, but not for injected URLs.+ </description>+</property>+<property><name>db.parsemeta.to.crawldb</name><value></value>diff --git a/conf/regex-urlfilter.txt.template b/conf/regex-urlfilter.txt.templateindex b060cbb7b..ea86cc9b0 100644--- a/conf/regex-urlfilter.txt.template+++ b/conf/regex-urlfilter.txt.template@@ -26,6 +26,9 @@# skip file: ftp: and mailto: urls-^(file|ftp|mailto):+# skip URLs longer than 8192 characters, see also db.max.outlink.length+#-^.{8193,}+# skip image and other suffixes we can't yet parse# for a more extensive coverage use the urlfilter-suffix plugin-(?i)\.(gif|jpg|png|ico|css|sit|eps|wmf|zip|ppt|mpg|xls|gz|rpm|tgz|mov|exe|jpeg|bmp|js)$diff --git a/src/java/org/apache/nutch/fetcher/FetcherThread.java b/src/java/org/apache/nutch/fetcher/FetcherThread.javaindex 6e86a8f59..2bd4d2280 100644--- a/src/java/org/apache/nutch/fetcher/FetcherThread.java+++ b/src/java/org/apache/nutch/fetcher/FetcherThread.java@@ -95,8 +95,8 @@ public class FetcherThread extends Thread {private String ignoreExternalLinksMode;// Used by fetcher.follow.outlinks.depth in parse- private int maxOutlinksPerPage;private final int maxOutlinks;+ private final int maxOutlinkLength;private final int interval;private int maxOutlinkDepth;private int maxOutlinkDepthNumLinks;@@ -197,9 +197,11 @@ public class FetcherThread extends Thread {Thread.currentThread().getId(), queueMode);this.maxRedirect = conf.getInt("http.redirect.max", 3);- maxOutlinksPerPage = conf.getInt("db.max.outlinks.per.page", 100);+ int maxOutlinksPerPage = conf.getInt("db.max.outlinks.per.page", 100);maxOutlinks = (maxOutlinksPerPage < 0) ? Integer.MAX_VALUE: maxOutlinksPerPage;+ int maxOutlinkL = conf.getInt("db.max.outlink.length", 8192);+ maxOutlinkLength = (maxOutlinkL < 0) ? Integer.MAX_VALUE : maxOutlinkL;interval = conf.getInt("db.fetch.interval.default", 2592000);ignoreInternalLinks = conf.getBoolean("db.ignore.internal.links", false);ignoreExternalLinks = conf.getBoolean("db.ignore.external.links", false);@@ -482,6 +484,9 @@ public class FetcherThread extends Thread {private Text handleRedirect(FetchItem fit, String newUrl,boolean temp, String redirType)throws MalformedURLException, URLFilterException, InterruptedException {+ if (newUrl.length() > maxOutlinkLength) {+ return null;+ }newUrl = normalizers.normalize(newUrl, URLNormalizers.SCOPE_FETCHER);newUrl = urlFilters.filter(newUrl);String urlString = fit.url.toString();@@ -721,6 +726,9 @@ public class FetcherThread extends Thread {for (int i = 0; i < links.length && validCount < outlinksToStore; i++) {String toUrl = links[i].getToUrl();+ if (toUrl.length() > maxOutlinkLength) {+ continue;+ }toUrl = ParseOutputFormat.filterNormalize(url.toString(), toUrl,origin, ignoreInternalLinks, ignoreExternalLinks,ignoreExternalLinksMode, urlFiltersForOutlinks,diff --git a/src/java/org/apache/nutch/parse/ParseOutputFormat.java b/src/java/org/apache/nutch/parse/ParseOutputFormat.javaindex d24f9ce4b..1efbbbcdc 100644--- a/src/java/org/apache/nutch/parse/ParseOutputFormat.java+++ b/src/java/org/apache/nutch/parse/ParseOutputFormat.java@@ -162,9 +162,12 @@ public class ParseOutputFormat extends OutputFormat<Text, Parse> {final boolean storeText = conf.getBoolean("parser.store.text", true);int maxOutlinksPerPage = conf.getInt("db.max.outlinks.per.page", 100);- final boolean isParsing = conf.getBoolean("fetcher.parse", true);final int maxOutlinks = (maxOutlinksPerPage < 0) ? Integer.MAX_VALUE: maxOutlinksPerPage;+ int maxOutlinkL = conf.getInt("db.max.outlink.length", 8192);+ final int maxOutlinkLength = (maxOutlinkL < 0) ? Integer.MAX_VALUE+ : maxOutlinkL;+ final boolean isParsing = conf.getBoolean("fetcher.parse", true);final CompressionType compType = SequenceFileOutputFormat.getOutputCompressionType(context);Path out = FileOutputFormat.getOutputPath(context);@@ -301,6 +304,9 @@ public class ParseOutputFormat extends OutputFormat<Text, Parse> {// only normalize and filter if fetcher.parse = falseif (!isParsing) {+ if (toUrl.length() > maxOutlinkLength) {+ continue;+ }toUrl = ParseOutputFormat.filterNormalize(fromUrl, toUrl, origin,ignoreInternalLinks, ignoreExternalLinks, ignoreExternalLinksMode, filters, exemptionFilters, normalizers);if (toUrl == null) {