Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

fixes for NUTCH-2686: New property: "moreIndexingFilter.mapMimeTypes.field", indicating the name of the field where the mapped mime type must be written.

r0ann3l6e8c2c382e50
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 00cb845f1..aa771f905 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -1207,6 +1207,15 @@
</description>
</property>
+<property>
+ <name>moreIndexingFilter.mapMimeTypes.field</name>
+ <value></value>
+ <description>It's used if moreIndexingFilter.mapMimeTypes is true. Indicates the field
+ where the mapped MIME-type must be written. If it's null, the field "type"
+ will be replaced by the mapped MIME-type.
+ </description>
+</property>
+
<!-- AnchorIndexing filter plugin properties -->
<property>
diff --git a/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java b/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
index c16d23361..81fbb225f 100644
--- a/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
+++ b/src/plugin/index-more/src/java/org/apache/nutch/indexer/more/MoreIndexingFilter.java
@@ -81,6 +81,7 @@ public class MoreIndexingFilter implements IndexingFilter {
/** Map for mime-type substitution */
private HashMap<String, String> mimeMap = null;
private boolean mapMimes = false;
+ private String mapFieldName;
public NutchDocument filter(NutchDocument doc, Parse parse, Text url,
CrawlDatum datum, Inlinks inlinks) throws IndexingException {
@@ -226,8 +227,11 @@ public class MoreIndexingFilter implements IndexingFilter {
if (mapMimes) {
// Check if the current mime is mapped
if (mimeMap.containsKey(mimeType)) {
- // It's mapped, let's replace it
- mimeType = mimeMap.get(mimeType);
+ if (mapFieldName != null) {
+ doc.add(mapFieldName, mimeMap.get(mimeType));
+ } else {
+ mimeType = mimeMap.get(mimeType);
+ }
}
}
@@ -300,9 +304,11 @@ public class MoreIndexingFilter implements IndexingFilter {
this.conf = conf;
MIME = new MimeUtil(conf);
- if (conf.getBoolean("moreIndexingFilter.mapMimeTypes", false) == true) {
+ if (conf.getBoolean("moreIndexingFilter.mapMimeTypes", false)) {
mapMimes = true;
+ mapFieldName = conf.get("moreIndexingFilter.mapMimeTypes.field");
+
// Load the mapping
try {
readConfiguration();