Apache Nutch is an extensible and scalable web crawler
NUTCH-167 - Observation of robots "noarchive" directive.
Andrzej Bialecki19bd520ef825
diff --git a/CHANGES.txt b/CHANGES.txtindex 59aaa23de..5c4acbd2e 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -151,7 +151,9 @@ Unreleased changes (0.9-dev)50. NUTCH-432 - Fix a bug where platform name with spaces would break thebin/nutch script. (Brian Whitman via ab)-51. Upgrade to Hadoop 0.11.2 and Lucene 2.1.0 release.+51. Upgrade to Hadoop 0.11.2 and Lucene 2.1.0 release. (ab)++52. NUTCH-167 - Observation of robots "noarchive" directive. (ab)Release 0.8 - 2006-07-25diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 5aef173b1..01cec209f 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -772,6 +772,17 @@is available</description></property>+<property>+ <name>parser.caching.forbidden.policy</name>+ <value>content</value>+ <description>If a site (or a page) requests through its robot metatags+ that it should not be shown as cached content, apply this policy. Currently+ three keywords are recognized: "none" ignores any "noarchive" directives.+ "content" doesn't show the content, but shows summaries (snippets).+ "all" doesn't show either content or summaries.</description>+</property>++<property><name>parser.html.impl</name><value>neko</value>diff --git a/src/java/org/apache/nutch/metadata/Nutch.java b/src/java/org/apache/nutch/metadata/Nutch.javaindex 5121ddbc9..d04f56df5 100644--- a/src/java/org/apache/nutch/metadata/Nutch.java+++ b/src/java/org/apache/nutch/metadata/Nutch.java@@ -47,4 +47,16 @@ public interface Nutch {public static final Text WRITABLE_PROTO_STATUS_KEY = new Text(PROTO_STATUS_KEY);+ /** Sites may request that search engines don't provide access to cached documents. */+ public static final String CACHING_FORBIDDEN_KEY = "caching.forbidden";++ /** Show both original forbidden content and summaries (default). */+ public static final String CACHING_FORBIDDEN_NONE = "none";++ /** Don't show either original forbidden content or summaries. */+ public static final String CACHING_FORBIDDEN_ALL = "all";++ /** Don't show original forbidden content, but show summaries. */+ public static final String CACHING_FORBIDDEN_CONTENT = "content";+}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 b8952d169..35f1ee387 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@@ -24,6 +24,7 @@ import org.apache.lucene.document.DateTools;import org.apache.lucene.document.Document;import org.apache.lucene.document.Field;+import org.apache.nutch.metadata.Nutch;import org.apache.nutch.parse.Parse;import org.apache.nutch.indexer.IndexingFilter;@@ -89,6 +90,11 @@ public class BasicIndexingFilter implements IndexingFilter {}// add title indexed and stored so that it can be displayeddoc.add(new Field("title", title, Field.Store.YES, Field.Index.TOKENIZED));+ // add cached content/summary display policy, if available+ String caching = parse.getData().getMeta(Nutch.CACHING_FORBIDDEN_KEY);+ if (caching != null && !caching.equals(Nutch.CACHING_FORBIDDEN_NONE)) {+ doc.add(new Field("cache", caching, Field.Store.YES, Field.Index.NO));+ }// add timestamp when fetched, for deduplicationdoc.add(new Field("tstamp",diff --git a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.java b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.javaindex 2c7b02966..c57038d66 100644--- a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.java+++ b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HTMLMetaProcessor.java@@ -105,6 +105,11 @@ public class HTMLMetaProcessor {if (index >= 0) {metaTags.setNoFollow();}++ index = directives.indexOf("noarchive");+ if (index >= 0) {+ metaTags.setNoCache();+ }}} // end if (name == robots)diff --git a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.javaindex b366a9eb3..c27f44a39 100644--- a/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java+++ b/src/plugin/parse-html/src/java/org/apache/nutch/parse/html/HtmlParser.java@@ -33,6 +33,7 @@ import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.nutch.metadata.Metadata;+import org.apache.nutch.metadata.Nutch;import org.apache.nutch.net.protocols.Response;import org.apache.nutch.protocol.Content;import org.apache.hadoop.conf.*;@@ -100,7 +101,9 @@ public class HtmlParser implements Parser {private DOMContentUtils utils;private HtmlParseFilters htmlParseFilters;-++ private String cachingPolicy;+public Parse getParse(Content content) {HTMLMetaTags metaTags = new HTMLMetaTags();@@ -202,10 +205,6 @@ public class HtmlParser implements Parser {}}- if (!metaTags.getNoCache()) { // okay to cache- // ??? FIXME ???- }-ParseStatus status = new ParseStatus(ParseStatus.SUCCESS);if (metaTags.getRefresh()) {status.setMinorCode(ParseStatus.SUCCESS_REDIRECT);@@ -217,7 +216,11 @@ public class HtmlParser implements Parser {Parse parse = new ParseImpl(text, parseData);// run filters on parse- return this.htmlParseFilters.filter(content, parse, metaTags, root);+ parse = this.htmlParseFilters.filter(content, parse, metaTags, root);+ if (metaTags.getNoCache()) { // not okay to cache+ parse.getData().getParseMeta().set(Nutch.CACHING_FORBIDDEN_KEY, cachingPolicy);+ }+ return parse;}private DocumentFragment parse(InputSource input) throws Exception {@@ -302,6 +305,8 @@ public class HtmlParser implements Parser {this.defaultCharEncoding = getConf().get("parser.character.encoding.default", "windows-1252");this.utils = new DOMContentUtils(conf);+ this.cachingPolicy = getConf().get("parser.caching.forbidden.policy",+ Nutch.CACHING_FORBIDDEN_CONTENT);}public Configuration getConf() {diff --git a/src/web/jsp/cached.jsp b/src/web/jsp/cached.jspindex 5a755ad8a..3c25e95c7 100644--- a/src/web/jsp/cached.jsp+++ b/src/web/jsp/cached.jsp@@ -23,6 +23,7 @@import="org.apache.nutch.searcher.*"import="org.apache.nutch.parse.ParseData"import="org.apache.nutch.metadata.Metadata"+ import="org.apache.nutch.metadata.Nutch"import="org.apache.hadoop.conf.Configuration"import="org.apache.nutch.util.NutchConfiguration"%><%@@ -82,6 +83,17 @@FIXME: have to sanitize 'content' : e.g. removing unncessary partof head elememt-->+<%+ String caching = details.getValue("cache");+ String url = details.getValue("url");+ if (caching != null && !caching.equals(Nutch.CACHING_FORBIDDEN_NONE)) {+%>+Display of this content was administratively prohibited by the webmaster.+You may visit the original page instead: <a href="<%=url%>"><%=url%></a>.+<%+ return;+ }+%><% if (contentType.startsWith("text/html")) {%><% if (content != null && !content.equals("")) {%>diff --git a/src/web/jsp/search.jsp b/src/web/jsp/search.jspindex 6122118f4..b4f25829f 100644--- a/src/web/jsp/search.jsp+++ b/src/web/jsp/search.jsp@@ -24,6 +24,7 @@import="java.net.*"import="org.apache.nutch.html.Entities"+ import="org.apache.nutch.metadata.Nutch"import="org.apache.nutch.searcher.*"import="org.apache.nutch.plugin.*"import="org.apache.nutch.clustering.*"@@ -194,7 +195,6 @@ function queryfocus() { document.search.query.focus(); }Hit[] show = hits.getHits(start, realEnd-start);HitDetails[] details = bean.getDetails(show);Summary[] summaries = bean.getSummary(details, query);-bean.LOG.info("total hits: " + hits.getTotal());%>@@ -228,6 +228,13 @@ out.flush();String url = detail.getValue("url");String id = "idx=" + hit.getIndexNo() + "&id=" + hit.getIndexDocNo();String summary = summaries[i].toHtml(true);+ String caching = detail.getValue("cache");+ boolean showSummary = true;+ boolean showCached = true;+ if (caching != null) {+ showSummary = !caching.equals(Nutch.CACHING_FORBIDDEN_ALL);+ showCached = !caching.equals(Nutch.CACHING_FORBIDDEN_NONE);+ }if (title == null || title.equals("")) { // use url for docs w/o titletitle = url;@@ -235,12 +242,16 @@ out.flush();%><b><a href="<%=url%>"><%=Entities.encode(title)%></a></b><%@ include file="more.jsp" %>- <% if (!"".equals(summary)) { %>+ <% if (!"".equals(summary) && showSummary) { %><br><%=summary%><% } %><br><span class="url"><%=Entities.encode(url)%></span>- (<a href="../cached.jsp?<%=id%>"><i18n:message key="cached"/></a>)+ <%+ if (showCached) {+ %>(<a href="../cached.jsp?<%=id%>"><i18n:message key="cached"/></a>) <%+ }+ %>(<a href="../explain.jsp?<%=id%>&query=<%=URLEncoder.encode(queryString, "UTF-8")%>&lang=<%=queryLang%>"><i18n:message key="explain"/></a>)(<a href="../anchors.jsp?<%=id%>"><i18n:message key="anchors"/></a>)<% if (hit.moreFromDupExcluded()) {