Apache Nutch is an extensible and scalable web crawler
NUTCH-1264 Index-metadata
Julien Niochea56db08ecca7
diff --git a/CHANGES.txt b/CHANGES.txtindex c0b9f5b21..92641a560 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -1,5 +1,7 @@Nutch Change Log+* NUTCH-1264 Configurable indexing plugin index-metadata (jnioche)+* NUTCH-1242 Allow disabling of URL Filters in ParseSegment (Edward Drapkin via markus)* NUTCH-1256 WebGraph to dump host + score (markus)diff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 67e0497eb..dc12272e0 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -1179,6 +1179,35 @@</description></property>+<!-- index-metadata plugin properties -->++<property>+ <name>index.parse.md</name>+ <value></value>+ <description>+ Comma-separated list of keys to be taken from the parse metadata to generate fields.+ Can be used e.g. for 'description' or 'keywords' provided that these values are generated+ by a parser.+ </description>+</property>++<property>+ <name>index.content.md</name>+ <value></value>+ <description>+ Comma-separated list of keys to be taken from the content metadata to generate fields.+ </description>+</property>++<property>+ <name>index.db.md</name>+ <value></value>+ <description>+ Comma-separated list of keys to be taken from the crawldb metadata to generate fields.+ Can be used to index values propagated from the seeds with the plugin urlmeta+ </description>+</property>+<!-- Temporary Hadoop 0.17.x workaround. --><property>diff --git a/src/plugin/build.xml b/src/plugin/build.xmlindex bda01cc60..5f310b84d 100755--- a/src/plugin/build.xml+++ b/src/plugin/build.xml@@ -32,6 +32,7 @@<ant dir="index-anchor" target="deploy"/><ant dir="index-more" target="deploy"/><ant dir="index-static" target="deploy"/>+ <ant dir="index-metadata" target="deploy"/><ant dir="language-identifier" target="deploy"/><ant dir="lib-http" target="deploy"/><ant dir="lib-nekohtml" target="deploy"/>@@ -103,6 +104,7 @@<ant dir="index-anchor" target="clean"/><ant dir="index-more" target="clean"/><ant dir="index-static" target="clean"/>+ <ant dir="index-metadata" target="clean"/><ant dir="language-identifier" target="clean"/><ant dir="lib-commons-httpclient" target="clean"/><ant dir="lib-http" target="clean"/>diff --git a/src/plugin/index-metadata/build.xml b/src/plugin/index-metadata/build.xmlnew file mode 100644index 000000000..ad96d11c6--- /dev/null+++ b/src/plugin/index-metadata/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-metadata" default="jar-core">++ <import file="../build-plugin.xml"/>++</project>diff --git a/src/plugin/index-metadata/ivy.xml b/src/plugin/index-metadata/ivy.xmlnew file mode 100644index 000000000..24d76063d--- /dev/null+++ b/src/plugin/index-metadata/ivy.xml@@ -0,0 +1,41 @@+<?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.+-->++<ivy-module version="1.0">+ <info organisation="org.apache.nutch" module="${ant.project.name}">+ <license name="Apache 2.0"/>+ <ivyauthor name="Apache Nutch Team" url="http://nutch.apache.org"/>+ <description>+ Apache Nutch+ </description>+ </info>++ <configurations>+ <include file="../../../ivy/ivy-configurations.xml"/>+ </configurations>++ <publications>+ <!--get the artifact from our module name-->+ <artifact conf="master"/>+ </publications>++ <dependencies>+ </dependencies>++</ivy-module>diff --git a/src/plugin/index-metadata/plugin.xml b/src/plugin/index-metadata/plugin.xmlnew file mode 100644index 000000000..4d4c9a737--- /dev/null+++ b/src/plugin/index-metadata/plugin.xml@@ -0,0 +1,42 @@+<?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-metadata"+ name="Index Metadata"+ version="1.0.0"+ provider-name="nutch.org">++ <runtime>+ <library name="index-metadata.jar">+ <export name="*"/>+ </library>+ </runtime>++ <requires>+ <import plugin="nutch-extensionpoints"/>+ </requires>+++ <extension id="org.apache.nutch.indexer.metadata"+ name="Nutch metadata indexer"+ point="org.apache.nutch.indexer.IndexingFilter">+ <implementation id="MetadataIndexer"+ class="org.apache.nutch.indexer.metadata.MetadataIndexer"/>+ </extension>++</plugin>diff --git a/src/plugin/index-metadata/src/java/org/apache/nutch/indexer/metadata/MetadataIndexer.java b/src/plugin/index-metadata/src/java/org/apache/nutch/indexer/metadata/MetadataIndexer.javanew file mode 100644index 000000000..21cf58ba7--- /dev/null+++ b/src/plugin/index-metadata/src/java/org/apache/nutch/indexer/metadata/MetadataIndexer.java@@ -0,0 +1,100 @@+/**+ * 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.metadata;++import java.util.HashMap;+import java.util.Map.Entry;++import org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.io.Text;+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.indexer.NutchDocument;+import org.apache.nutch.parse.Parse;++/**+ * Indexer which can be configured to extract metadata from the crawldb, parse metadata or content metadata.+ * You can specify the properties "index.db", "index.parse" or "index.content" who's values are+ * comma-delimited <value>key1, key2, key3</value>.+ */++public class MetadataIndexer implements IndexingFilter {+ private Configuration conf;+ private HashMap<String, String[]> staticfields;+ private static String[] dbFieldnames;+ private static String[] parseFieldnames;+ private static String[] contentFieldnames;+ private static final String db_CONF_PROPERTY = "index.db.md";+ private static final String parse_CONF_PROPERTY = "index.parse.md";+ private static final String content_CONF_PROPERTY = "index.content.md";++ public NutchDocument filter(NutchDocument doc, Parse parse, Text url,+ CrawlDatum datum, Inlinks inlinks) throws IndexingException {++ // just in case+ if (doc == null)+ return doc;++ // add the fields from crawldb+ if (dbFieldnames != null) {+ for (String metatag : dbFieldnames) {+ Text metadata = (Text) datum.getMetaData().get(+ new Text(metatag));+ if (metadata != null)+ doc.add(metatag, metadata.toString());+ }+ }++ // add the fields from parsemd+ if (parseFieldnames != null) {+ for (String metatag : parseFieldnames) {+ String value = parse.getData().getParseMeta().get(metatag);+ if (value != null)+ doc.add(metatag, value);+ }+ }++ // add the fields from contentmd+ if (contentFieldnames != null) {+ for (String metatag : contentFieldnames) {+ String value = parse.getData().getContentMeta().get(metatag);+ if (value != null)+ doc.add(metatag, value);+ }+ }++ return doc;+ }++ public void setConf(Configuration conf) {+ this.conf = conf;+ dbFieldnames = conf.getStrings(db_CONF_PROPERTY);+ parseFieldnames = conf.getStrings(parse_CONF_PROPERTY);+ contentFieldnames = conf.getStrings(content_CONF_PROPERTY);++ // TODO check conflict between field names e.g. could have same label+ // from different sources++ }++ public Configuration getConf() {+ return this.conf;+ }+}