Apache Nutch is an extensible and scalable web crawler
NUTCH-1037 Option to deduplicate anchors prior to indexing
Markus Jelsmaa9a52d710bec
diff --git a/CHANGES.txt b/CHANGES.txtindex 6e64f9cd1..f40ce4c9f 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogRelease 2.0 - Current Development+* NUTCH-1037 Option to deduplicate anchors prior to indexing (markus)+* NUTCH-1055 upgrade package.html file in language identifier plugin (lewismc)* NUTCH-1043 Add pattern for filtering .js in default url filters (jnioche)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex e35b809f6..9147c546f 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -716,7 +716,6 @@</description></property>-<!-- moreindexingfilter plugin properties --><property>@@ -728,6 +727,16 @@</description></property>+<!-- AnchorIndexing filter plugin properties -->++<property>+ <name>anchorIndexingFilter.deduplicate</name>+ <value>false</value>+ <description>With this enabled the indexer will case-insensitive deduplicate hanchors+ 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><!-- URL normalizer properties -->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 d2d74ff42..827de0f8d 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@@ -19,6 +19,7 @@ package org.apache.nutch.indexer.anchor;import java.util.Collection;import java.util.HashSet;import java.util.Map.Entry;+import java.util.WeakHashMap;import org.apache.avro.util.Utf8;import org.slf4j.Logger;@@ -37,6 +38,7 @@ public class AnchorIndexingFilter implements IndexingFilter {public static final Logger LOG = LoggerFactory.getLogger(AnchorIndexingFilter.class);private Configuration conf;+ private boolean deduplicate = false;private static final Collection<WebPage.Field> FIELDS = new HashSet<WebPage.Field>();@@ -46,6 +48,9 @@ public class AnchorIndexingFilter implements IndexingFilter {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() {@@ -59,8 +64,25 @@ public class AnchorIndexingFilter implements IndexingFilter {public NutchDocument filter(NutchDocument doc, String url, WebPage page)throws IndexingException {+ // https://issues.apache.org/jira/browse/NUTCH-1037+ WeakHashMap<String,Integer> map = new WeakHashMap<String,Integer>();+for (Entry<Utf8, Utf8> e : page.getInlinks().entrySet()) {- doc.add("anchor", TableUtil.toString(e.getValue()));+ String anchor = TableUtil.toString(e.getValue());++ if (deduplicate) {+ String lcAnchor = anchor.toLowerCase();++ // Check if already processed the current anchor+ if (!map.containsKey(lcAnchor)) {+ doc.add("anchor", anchor);++ // Add to map+ map.put(lcAnchor, 1);+ }+ } else {+ doc.add("anchor", anchor);+ }}return doc;