Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-574 - Including inlink anchor text in index can create irrelevant search results. Moved inbound anchor text indexing from index-basic to new index-anchor plugin. For backwards compatibility index-anchor will need to be added to the nutch-site.xml plugin.includes configuration variable.

Dennis Kubes702172f0e4d6
diff --git a/CHANGES.txt b/CHANGES.txt
index b7482e73c..e6eb58628 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -168,6 +168,11 @@ Unreleased changes (1.0-dev)
58. NUTCH-494 - FindBugs: CrawlDbReader and DeleteDuplicates. (dogacan)
+59. NUTCH-574 - Including inlink anchor text in index can create irrelevant
+ search results. Created index-anchor plugin, removed functionality from
+ index-basic plugin. For backwards compatibility, add index-anchor plugin to
+ nutch-site.xml plugin.includes. (kubes)
+
Release 0.9 - 2007-04-02
1. Changed log4j confiquration to log to stdout on commandline
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 7da1dff8a..49673a668 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -817,7 +817,7 @@
<property>
<name>plugin.includes</name>
- <value>protocol-http|urlfilter-regex|parse-(text|html|js)|index-basic|query-(basic|site|url)|summary-basic|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
+ <value>protocol-http|urlfilter-regex|parse-(text|html|js)|index-(basic|anchor)|query-(basic|site|url)|summary-basic|scoring-opic|urlnormalizer-(pass|regex|basic)</value>
<description>Regular expression naming plugin directory names to
include. Any plugin not matching this expression is excluded.
In any case you need at least include the nutch-extensionpoints plugin. By
diff --git a/src/plugin/build.xml b/src/plugin/build.xml
index 17ac22553..ff98d4c29 100755
--- a/src/plugin/build.xml
+++ b/src/plugin/build.xml
@@ -30,6 +30,7 @@
<ant dir="creativecommons" target="deploy"/>
<ant dir="feed" target="deploy"/>
<ant dir="index-basic" target="deploy"/>
+ <ant dir="index-anchor" target="deploy"/>
<ant dir="index-more" target="deploy"/>
<ant dir="languageidentifier" target="deploy"/>
<ant dir="lib-http" target="deploy"/>
@@ -121,6 +122,7 @@
<ant dir="creativecommons" target="clean"/>
<ant dir="feed" target="clean"/>
<ant dir="index-basic" target="clean"/>
+ <ant dir="index-anchor" target="clean"/>
<ant dir="index-more" target="clean"/>
<ant dir="languageidentifier" target="clean"/>
<ant dir="lib-commons-httpclient" target="clean"/>
diff --git a/src/plugin/index-anchor/build.xml b/src/plugin/index-anchor/build.xml
new file mode 100644
index 000000000..597b53292
--- /dev/null
+++ b/src/plugin/index-anchor/build.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<project name="index-anchor" default="jar-core">
+
+ <import file="../build-plugin.xml" />
+
+</project>
\ No newline at end of file
diff --git a/src/plugin/index-anchor/plugin.xml b/src/plugin/index-anchor/plugin.xml
new file mode 100644
index 000000000..208594bc0
--- /dev/null
+++ b/src/plugin/index-anchor/plugin.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<plugin id="index-anchor" name="Anchor Indexing Filter" version="1.0.0"
+ provider-name="nutch.org">
+
+ <runtime>
+ <library name="index-anchor.jar">
+ <export name="*" />
+ </library>
+ </runtime>
+
+ <requires>
+ <import plugin="nutch-extensionpoints" />
+ </requires>
+
+ <extension id="org.apache.nutch.indexer.anchor"
+ name="Nutch Anchor Indexing Filter"
+ point="org.apache.nutch.indexer.IndexingFilter">
+ <implementation id="AnchorIndexingFilter"
+ class="org.apache.nutch.indexer.anchor.AnchorIndexingFilter" />
+ </extension>
+
+</plugin>
\ No newline at end of file
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.java
new file mode 100644
index 000000000..7d0dba0d2
--- /dev/null
+++ b/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/AnchorIndexingFilter.java
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.nutch.indexer.anchor;
+
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.io.Text;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.nutch.crawl.CrawlDatum;
+import org.apache.nutch.crawl.Inlinks;
+import org.apache.nutch.indexer.IndexingException;
+import org.apache.nutch.indexer.IndexingFilter;
+import org.apache.nutch.parse.Parse;
+
+/**
+ * Indexing filter that indexes all inbound anchor text for a document.
+ */
+public class AnchorIndexingFilter
+ implements IndexingFilter {
+
+ public static final Log LOG = LogFactory.getLog(AnchorIndexingFilter.class);
+ private Configuration conf;
+
+ public void setConf(Configuration conf) {
+ this.conf = conf;
+ }
+
+ public Configuration getConf() {
+ return this.conf;
+ }
+
+ public Document filter(Document doc, Parse parse, Text url, CrawlDatum datum,
+ Inlinks inlinks) throws IndexingException {
+
+ try {
+ String[] anchors = (inlinks != null ? inlinks.getAnchors()
+ : new String[0]);
+ for (int i = 0; i < anchors.length; i++) {
+ doc.add(new Field("anchor", anchors[i], Field.Store.NO,
+ Field.Index.TOKENIZED));
+ }
+ } catch (IOException ioe) {
+ if (LOG.isWarnEnabled()) {
+ LOG.warn("AnchorIndexingFilter: can't get anchors for "
+ + url.toString());
+ }
+ }
+
+ return doc;
+ }
+}
diff --git a/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/package.html b/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/package.html
new file mode 100644
index 000000000..c25502953
--- /dev/null
+++ b/src/plugin/index-anchor/src/java/org/apache/nutch/indexer/anchor/package.html
@@ -0,0 +1,5 @@
+<html>
+<body>
+<p>An indexing plugin for inbound anchor text.</p><p></p>
+</body>
+</html>
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 bdb93eb58..9dd494d7f 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
@@ -34,7 +34,6 @@ import org.apache.hadoop.io.Text;
import org.apache.nutch.crawl.CrawlDatum;
import org.apache.nutch.crawl.Inlinks;
-import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.hadoop.conf.Configuration;
@@ -87,18 +86,6 @@ public class BasicIndexingFilter implements IndexingFilter {
// content is indexed, so that it's searchable, but not stored in index
doc.add(new Field("content", parse.getText(), Field.Store.NO, Field.Index.TOKENIZED));
- // anchors are indexed, so they're searchable, but not stored in index
- try {
- String[] anchors = (inlinks != null ? inlinks.getAnchors() : new String[0]);
- for (int i = 0; i < anchors.length; i++) {
- doc.add(new Field("anchor", anchors[i], Field.Store.NO, Field.Index.TOKENIZED));
- }
- } catch (IOException ioe) {
- if (LOG.isWarnEnabled()) {
- LOG.warn("BasicIndexingFilter: can't get anchors for " + url.toString());
- }
- }
-
// title
String title = parse.getData().getTitle();
if (title.length() > MAX_TITLE_LENGTH) { // truncate title if needed