Apache Nutch is an extensible and scalable web crawler
NUTCH-1242 Allow disabling of URL Filters in ParseSegment
Markus Jelsma53dd30241819
diff --git a/CHANGES.txt b/CHANGES.txtindex 06d4987a6..c0b9f5b21 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -1,5 +1,7 @@Nutch Change Log+* NUTCH-1242 Allow disabling of URL Filters in ParseSegment (Edward Drapkin via markus)+* NUTCH-1256 WebGraph to dump host + score (markus)* NUTCH-1260 Fetcher should log fetching of redirects (Sebastian Nagel via markus)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 65cab57d6..67e0497eb 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -1050,6 +1050,18 @@</description></property>+<property>+ <name>parse.filter.urls</name>+ <value>true</value>+ <description>Whether the parser will filter URLs (with the configured URL filters).</description>+</property>++<property>+ <name>parse.normalize.urls</name>+ <value>true</value>+ <description>Whether the parser will normalize URLs (with the configured URL normalizers).</description>+</property>+<!-- urlfilter plugin properties --><property>diff --git a/src/java/org/apache/nutch/parse/ParseOutputFormat.java b/src/java/org/apache/nutch/parse/ParseOutputFormat.javaindex e90472a79..2038999d2 100644--- a/src/java/org/apache/nutch/parse/ParseOutputFormat.java+++ b/src/java/org/apache/nutch/parse/ParseOutputFormat.java@@ -92,8 +92,13 @@ public class ParseOutputFormat implements OutputFormat<Text, Parse> {public RecordWriter<Text, Parse> getRecordWriter(FileSystem fs, JobConf job,String name, Progressable progress) throws IOException {- filters = new URLFilters(job);- normalizers = new URLNormalizers(job, URLNormalizers.SCOPE_OUTLINK);+ if(job.getBoolean("parse.filter.urls", true)) {+ filters = new URLFilters(job);+ }++ if(job.getBoolean("parse.normalize.urls", true)) {+ normalizers = new URLNormalizers(job, URLNormalizers.SCOPE_OUTLINK);+ }this.scfilters = new ScoringFilters(job);final int interval = job.getInt("db.fetch.interval.default", 2592000);@@ -166,13 +171,20 @@ public class ParseOutputFormat implements OutputFormat<Text, Parse> {pstatus.getMinorCode() == ParseStatus.SUCCESS_REDIRECT) {String newUrl = pstatus.getMessage();int refreshTime = Integer.valueOf(pstatus.getArgs()[1]);+try {- newUrl = normalizers.normalize(newUrl,- URLNormalizers.SCOPE_FETCHER);+ if(normalizers != null) {+ newUrl = normalizers.normalize(newUrl,+ URLNormalizers.SCOPE_FETCHER);+ }} catch (MalformedURLException mfue) {newUrl = null;}- if (newUrl != null) newUrl = filters.filter(newUrl);++ if (filters != null) {+ if (newUrl != null) newUrl = filters.filter(newUrl);+ }+String url = key.toString();if (newUrl != null && !newUrl.equals(url)) {String reprUrl =@@ -295,9 +307,13 @@ public class ParseOutputFormat implements OutputFormat<Text, Parse> {}}try {- toUrl = normalizers.normalize(toUrl,+ if(normalizers != null) {+ toUrl = normalizers.normalize(toUrl,URLNormalizers.SCOPE_OUTLINK); // normalize the url- toUrl = filters.filter(toUrl); // filter the url+ }+ if (filters != null) {+ toUrl = filters.filter(toUrl); // filter the url+ }if (toUrl == null) {return null;}diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.javaindex 8c702f8d3..513acb8f1 100644--- a/src/java/org/apache/nutch/parse/ParseSegment.java+++ b/src/java/org/apache/nutch/parse/ParseSegment.java@@ -172,12 +172,25 @@ public class ParseSegment extends Configured implements Tool,public int run(String[] args) throws Exception {Path segment;- String usage = "Usage: ParseSegment segment";+ String usage = "Usage: ParseSegment segment [-noFilter] [-noNormalize]";if (args.length == 0) {System.err.println(usage);System.exit(-1);- }+ }++ if(args.length > 1) {+ for(int i = 1; i < args.length; i++) {+ String param = args[i];++ if("-noilter".equalsIgnoreCase(param)) {+ getConf().setBoolean("parse.filter.urls", false);+ } else if ("-nonormalize".equalsIgnoreCase(param)) {+ getConf().setBoolean("parse.normalize.urls", false);+ }+ }+ }+segment = new Path(args[0]);parse(segment);return 0;