Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

integrate NUTCH-965 Skip parsing for truncated documents (commit 3)

Ferdy Galema6893fd2477e9
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index 9b841952d..800582ca4 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -589,7 +589,7 @@ public class Fetcher extends Configured implements Tool,
private int maxOutlinkDepth;
private int maxOutlinkDepthNumLinks;
private int outlinksDepthDivisor;
- private boolean checkTruncated;
+ private boolean skipTruncated;
public FetcherThread(Configuration conf) {
this.setDaemon(true); // don't hang JVM on exit
@@ -598,7 +598,7 @@ public class Fetcher extends Configured implements Tool,
this.urlFilters = new URLFilters(conf);
this.scfilters = new ScoringFilters(conf);
this.parseUtil = new ParseUtil(conf);
- this.checkTruncated = conf.getBoolean(ParseSegment.SKIP_TRUNCATED, true);
+ this.skipTruncated = conf.getBoolean(ParseSegment.SKIP_TRUNCATED, true);
this.protocolFactory = new ProtocolFactory(conf);
this.normalizers = new URLNormalizers(conf, URLNormalizers.SCOPE_FETCHER);
this.maxCrawlDelay = conf.getInt("fetcher.max.crawl.delay", 30) * 1000;
@@ -947,7 +947,7 @@ public class Fetcher extends Configured implements Tool,
/* Note: Fetcher will only follow meta-redirects coming from the
* original URL. */
if (parsing && status == CrawlDatum.STATUS_FETCH_SUCCESS) {
- if (!checkTruncated || (checkTruncated && !ParseSegment.isTruncated(content))) {
+ if (!skipTruncated || (skipTruncated && !ParseSegment.isTruncated(content))) {
try {
parseResult = this.parseUtil.parse(content);
} catch (Exception e) {
diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.java
index 0855f3116..6b7c361f6 100644
--- a/src/java/org/apache/nutch/parse/ParseSegment.java
+++ b/src/java/org/apache/nutch/parse/ParseSegment.java
@@ -104,7 +104,7 @@ public class ParseSegment extends Configured implements Tool,
return;
}
- if (isTruncated(content)) {
+ if (skipTruncated && isTruncated(content)) {
return;
}
@@ -173,18 +173,23 @@ public class ParseSegment extends Configured implements Tool,
if (StringUtil.isEmpty(lengthStr)) {
return false;
}
- int contentLength;
+ int inHeaderSize;
+ String url = content.getUrl();
try {
- contentLength = Integer.parseInt(lengthStr);
+ inHeaderSize = Integer.parseInt(lengthStr);
} catch (NumberFormatException e) {
- LOG.warn("Wrong contentlength format for " + content.getUrl(), e);
+ LOG.warn("Wrong contentlength format for " + url, e);
return false;
}
- if (contentLength > contentBytes.length) {
- LOG.info(content.getUrl() + " skipped. Content of size " + contentLength
- + " was truncated to " + contentBytes.length);
+ int actualSize = contentBytes.length;
+ if (inHeaderSize > actualSize) {
+ LOG.info(url + " skipped. Content of size " + inHeaderSize
+ + " was truncated to " + actualSize);
return true;
}
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(url + " actualSize=" + actualSize + " inHeaderSize=" + inHeaderSize);
+ }
return false;
}