Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1407 BasicIndexingFilter to optionally add domain field

Markus Jelsmacb68fbf62239
diff --git a/CHANGES.txt b/CHANGES.txt
index 2832a6951..933cea261 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
(trunk) Current Development:
+* NUTCH-1407 BasicIndexingFilter to optionally add domain field (markus)
+
* NUTCH-1408 RobotRulesParser main doesn't take URL's (markus)
* NUTCH-1400 Remove developer -core option for bin/nutch (jnioche)
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 9e4a97bb6..878b62e1f 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -899,6 +899,12 @@
</description>
</property>
+<property>
+ <name>indexer.add.domain</name>
+ <value>false</value>
+ <description>Whether to add the domain field to a NutchDocument.</description>
+</property>
+
<property>
<name>indexer.skip.notmodified</name>
<value>false</value>
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.java
index 28e3140f8..d5a85fc45 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
@@ -26,6 +26,7 @@ import org.apache.nutch.parse.Parse;
import org.apache.nutch.indexer.IndexingFilter;
import org.apache.nutch.indexer.IndexingException;
import org.apache.nutch.indexer.NutchDocument;
+import org.apache.nutch.util.URLUtil;
import org.apache.hadoop.io.Text;
import org.apache.nutch.crawl.CrawlDatum;
@@ -43,6 +44,7 @@ public class BasicIndexingFilter implements IndexingFilter {
private int MAX_TITLE_LENGTH;
private int MAX_CONTENT_LENGTH;
+ private boolean addDomain = false;
private Configuration conf;
public NutchDocument filter(NutchDocument doc, Parse parse, Text url, CrawlDatum datum, Inlinks inlinks)
@@ -60,6 +62,11 @@ public class BasicIndexingFilter implements IndexingFilter {
} else {
u = new URL(urlString);
}
+
+ if (addDomain) {
+ doc.add("domain", URLUtil.getDomainName(u));
+ }
+
host = u.getHost();
} catch (MalformedURLException e) {
throw new IndexingException(e);
@@ -104,6 +111,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.addDomain = conf.getBoolean("indexer.add.domain", false);
this.MAX_CONTENT_LENGTH = conf.getInt("indexer.max.content.length", -1);
}