Apache Nutch is an extensible and scalable web crawler
NUTCH-1105 Max content length option for index-basic
Markus Jelsmafef914ad42b1
diff --git a/CHANGES.txt b/CHANGES.txtindex a1bc92990..c765159de 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogRelease 1.4 - Current development+* NUTCH-1105 Max content length option for index-basic (markus)+* NUTCH-940 static field plugin (Claudio Martella via lewismc)* NUTCH-914 Implement Apache Project Branding Requirements (lewismc)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex b0bdc6f8c..e055cdc16 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -762,6 +762,14 @@</description></property>+<property>+ <name>indexer.max.content.length</name>+ <value>-1</value>+ <description>The maximum number of characters of a content that are indexed.+ Content beyond the limit is truncated. A value of -1 disables this check.+ </description>+</property>+<!-- URL normalizer properties --><property>diff --git a/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java b/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.javaindex 3fded7155..cd5cd3b32 100644--- a/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java+++ b/src/plugin/index-basic/src/java/org/apache/nutch/indexer/basic/BasicIndexingFilter.java@@ -42,6 +42,7 @@ public class BasicIndexingFilter implements IndexingFilter {public static final Log LOG = LogFactory.getLog(BasicIndexingFilter.class);private int MAX_TITLE_LENGTH;+ private int MAX_CONTENT_LENGTH;private Configuration conf;public NutchDocument filter(NutchDocument doc, Parse parse, Text url, CrawlDatum datum, Inlinks inlinks)@@ -70,8 +71,14 @@ public class BasicIndexingFilter implements IndexingFilter {}doc.add("url", reprUrlString == null ? urlString : reprUrlString);- doc.add("content", parse.getText());-++ // content+ String content = parse.getText();+ if (MAX_CONTENT_LENGTH > -1 && content.length() > MAX_CONTENT_LENGTH) {+ content = content.substring(0, MAX_CONTENT_LENGTH);+ }+ doc.add("content", content);+// titleString title = parse.getData().getTitle();if (title.length() > MAX_TITLE_LENGTH) { // truncate title if needed@@ -88,7 +95,7 @@ public class BasicIndexingFilter implements IndexingFilter {if (caching != null && !caching.equals(Nutch.CACHING_FORBIDDEN_NONE)) {doc.add("cache", caching);}-+// add timestamp when fetched, for deduplicationdoc.add("tstamp", new Date(datum.getFetchTime()));@@ -98,6 +105,7 @@ public class BasicIndexingFilter implements IndexingFilter {public void setConf(Configuration conf) {this.conf = conf;this.MAX_TITLE_LENGTH = conf.getInt("indexer.max.title.length", 100);+ this.MAX_CONTENT_LENGTH = conf.getInt("indexer.max.content.length", -1);}public Configuration getConf() {