Apache Nutch is an extensible and scalable web crawler
NUTCH-1037 Option to deduplicate anchors prior to indexing
Markus Jelsma4d7851378e92
diff --git a/CHANGES.txt b/CHANGES.txtindex cb29800c8..f52dd1baa 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,10 @@ Nutch Change LogRelease 1.4 - Current development+* NUTCH-1037 Option to deduplicate anchors prior to indexing (markus)++* NUTCH-1050 Add segmentDir option to WebGraph (markus)+* NUTCH-1055 upgrade package.html file in language identifier plugin (lewismc)* NUTCH-1059 Remove convdb command from /bin/nutch (lewismc)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 0c47a983e..4339ef15a 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -697,6 +697,17 @@</description></property>+<!-- AnchorIndexing filter plugin properties -->++<property>+ <name>anchorIndexingFilter.deduplicate</name>+ <value>false</value>+ <description>With this enabled the indexer will case-insensitive deduplicate anchors+ before indexing. This prevents possible hundreds or thousands of identical anchors for+ a given page to be indexed but will affect the search scoring (i.e. tf=1.0f).+ </description>+</property>+<!-- indexingfilter plugin properties --><property>diff --git a/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/AnchorIndexingFilter.java b/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/AnchorIndexingFilter.javaindex b8c057f0e..adff19a52 100644--- a/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/AnchorIndexingFilter.java+++ b/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/AnchorIndexingFilter.java@@ -16,6 +16,8 @@*/package org.apache.nutch.indexer.anchor;+import java.util.WeakHashMap;+import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.hadoop.conf.Configuration;@@ -35,9 +37,13 @@ public class AnchorIndexingFilterpublic static final Log LOG = LogFactory.getLog(AnchorIndexingFilter.class);private Configuration conf;+ private boolean deduplicate = false;public void setConf(Configuration conf) {this.conf = conf;++ deduplicate = conf.getBoolean("anchorIndexingFilter.deduplicate", false);+ LOG.info("Anchor deduplication is: " + (deduplicate ? "on" : "off"));}public Configuration getConf() {@@ -49,8 +55,24 @@ public class AnchorIndexingFilterString[] anchors = (inlinks != null ? inlinks.getAnchors(): new String[0]);++ // https://issues.apache.org/jira/browse/NUTCH-1037+ WeakHashMap<String,Integer> map = new WeakHashMap<String,Integer>();+for (int i = 0; i < anchors.length; i++) {- doc.add("anchor", anchors[i]);+ if (deduplicate) {+ String lcAnchor = anchors[i].toLowerCase();++ // Check if already processed the current anchor+ if (!map.containsKey(lcAnchor)) {+ doc.add("anchor", anchors[i]);++ // Add to map+ map.put(lcAnchor, 1);+ }+ } else {+ doc.add("anchor", anchors[i]);+ }}return doc;