Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

applied NUTCH-905 to 1.3

Julien Niochedbdd0723ed79
diff --git a/CHANGES.txt b/CHANGES.txt
index 32d9cd860..a826d2cc7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Release 1.3 - Current Development
+* NUTCH-905 Configurable file protocol parent directory crawling (Thorsten Scherler, mattmann, ab)
+
* NUTCH-787 ScoringFilters should not override the injected score (jnioche)
* NUTCH-949 Conflicting ANT jars in classpath (jnioche)
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 3c5129bc7..8e72b9d1e 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -33,6 +33,15 @@
confuse this setting with the http.content.limit setting.
</description>
</property>
+
+<property>
+ <name>file.crawl.parent</name>
+ <value>true</value>
+ <description>The crawler is not restricted to the directories that you specified in the
+ Urls file but it is jumping into the parent directories as well. For your own crawlings you can
+ change this bahavior (set to false) the way that only directories beneath the directories that you specify get
+ crawled.</description>
+</property>
<property>
<name>file.content.ignored</name>
diff --git a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.java b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.java
index f4390c85b..510a37d14 100644
--- a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.java
+++ b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/File.java
@@ -53,6 +53,7 @@ public class File implements Protocol {
static final int MAX_REDIRECTS = 5;
int maxContentLength;
+ boolean crawlParents;
private Configuration conf;
@@ -156,6 +157,7 @@ public class File implements Protocol {
public void setConf(Configuration conf) {
this.conf = conf;
this.maxContentLength = conf.getInt("file.content.limit", 64 * 1024);
+ this.crawlParents = conf.getBoolean("file.crawl.parent", true);
}
public Configuration getConf() {
diff --git a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java
index d07ee8114..c7ef9754f 100644
--- a/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java
+++ b/src/plugin/protocol-file/src/java/org/apache/nutch/protocol/file/FileResponse.java
@@ -222,7 +222,10 @@ public class FileResponse {
throws IOException {
String path = f.toString();
- this.content = list2html(f.listFiles(), path, "/".equals(path) ? false : true);
+ if (this.file.crawlParents)
+ this.content = list2html(f.listFiles(), path, "/".equals(path) ? false : true);
+ else
+ this.content = list2html(f.listFiles(), path, false);
// set headers
headers.set(Response.CONTENT_LENGTH,