Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

- fix for NUTCH-905 Configurable file protocol parent directory crawling

Chris Mattmann9a2253c251e8
diff --git a/CHANGES.txt b/CHANGES.txt
index 07900e0bd..11c2a945d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Release 2.0 - Current Development
+* NUTCH-905 Configurable file protocol parent directory crawling (Thorsten Scherler, mattmann, ab)
+
* NUTCH-716 Make subcollection index filed multivalued (Dmitry Lihachev via jnioche)
* NUTCH-884 FetcherJob should run more reduce tasks than default (ab)
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 28ee6e407..4ebf58972 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -45,6 +45,17 @@
</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 crawling you can
+ change this behavior (set to false) the way that only directories beneath the directories that you specify get
+ crawled.
+ </description>
+</property>
+
+
<!-- HTTP properties -->
<property>
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 59778d44f..748b011c2 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
@@ -59,6 +59,8 @@ public class File implements Protocol {
static final int MAX_REDIRECTS = 5;
int maxContentLength;
+
+ boolean crawlParents;
private Configuration conf;
@@ -173,6 +175,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 6f152e1c9..1616d2631 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
@@ -215,7 +215,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,