Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1346 Follow outlinks to ignore external

Markus Jelsmaf94f5725f56c
diff --git a/CHANGES.txt b/CHANGES.txt
index f1d46dfd3..739d07bcb 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
(trunk) Current Development:
+* NUTCH-1346 Follow outlinks to ignore external (markus)
+
* NUTCH-1320 IndexChecker and ParseChecker choke on IDN's (markus)
* NUTCH-1351 DomainStatistics to aggregate by TLD (markus)
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 01ebf60da..1367fffcb 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -801,6 +801,14 @@
</description>
</property>
+<property>
+ <name>fetcher.follow.outlinks.ignore.external</name>
+ <value>true</value>
+ <description>Whether to ignore or follow external links. Set db.ignore.external.links to false and this to true to store outlinks
+ in the output but not follow them. If db.ignore.external.links is true this directive is ignored.
+ </description>
+</property>
+
<!-- moreindexingfilter plugin properties -->
<property>
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index f380bc598..edb4613e8 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -588,6 +588,8 @@ public class Fetcher extends Configured implements Tool,
private final int interval;
private int maxOutlinkDepth;
private int maxOutlinkDepthNumLinks;
+ private boolean outlinksIgnoreExternal;
+
private int outlinksDepthDivisor;
private boolean skipTruncated;
@@ -619,6 +621,7 @@ public class Fetcher extends Configured implements Tool,
interval = conf.getInt("db.fetch.interval.default", 2592000);
ignoreExternalLinks = conf.getBoolean("db.ignore.external.links", false);
maxOutlinkDepth = conf.getInt("fetcher.follow.outlinks.depth", -1);
+ outlinksIgnoreExternal = conf.getBoolean("fetcher.follow.outlinks.ignore.external", false);
maxOutlinkDepthNumLinks = conf.getInt("fetcher.follow.outlinks.num.links", 4);
outlinksDepthDivisor = conf.getInt("fetcher.follow.outlinks.depth.divisor", 2);
}
@@ -1051,13 +1054,24 @@ public class Fetcher extends Configured implements Tool,
// Calculate variable number of outlinks by depth using the divisor (outlinks = Math.floor(divisor / depth * num.links))
int maxOutlinksByDepth = (int)Math.floor(outlinksDepthDivisor / (outlinkDepth + 1) * maxOutlinkDepthNumLinks);
+ String followUrl;
+
// Walk over the outlinks and add as new FetchItem to the queues
Iterator<String> iter = outlinks.iterator();
while(iter.hasNext() && outlinkCounter < maxOutlinkDepthNumLinks) {
+ followUrl = iter.next();
+
+ // Check whether we'll follow external outlinks
+ if (outlinksIgnoreExternal) {
+ if (!URLUtil.getHost(url.toString()).equals(URLUtil.getHost(followUrl))) {
+ continue;
+ }
+ }
+
reporter.incrCounter("FetcherOutlinks", "outlinks_following", 1);
// Create new FetchItem with depth incremented
- FetchItem fit = FetchItem.create(new Text(iter.next()), new CrawlDatum(CrawlDatum.STATUS_LINKED, interval), queueMode, outlinkDepth + 1);
+ FetchItem fit = FetchItem.create(new Text(followUrl), new CrawlDatum(CrawlDatum.STATUS_LINKED, interval), queueMode, outlinkDepth + 1);
fetchQueues.addFetchItem(fit);
outlinkCounter++;