Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Ported NUTCH-901 Making index-more plug-in configurable to 1.3

Markus Jelsmac4acc8e0651a
diff --git a/conf/nutch-default.xml b/conf/nutch-default.xml
index 0ff1d51d7..b7b8c9b9f 100644
--- a/conf/nutch-default.xml
+++ b/conf/nutch-default.xml
@@ -751,6 +751,17 @@
</description>
</property>
+<!-- moreindexingfilter plugin properties -->
+
+<property>
+ <name>moreIndexingFilter.indexMimeTypeParts</name>
+ <value>true</value>
+ <description>Determines whether the index-more plugin will split the mime-type
+ in sub parts, this requires the type field to be multi valued. Set to true for backward
+ compatibility. False will not split the mime-type.
+ </description>
+</property>
+
<!-- indexingfilter 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 78d9bbb85..28db35921 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
@@ -224,10 +224,13 @@ public class MoreIndexingFilter implements IndexingFilter {
doc.add("type", contentType);
- String[] parts = getParts(contentType);
+ // Check if we need to split the content type in sub parts
+ if (conf.getBoolean("moreIndexingFilter.indexMimeTypeParts", true)) {
+ String[] parts = getParts(contentType.toString());
- for(String part: parts) {
- doc.add("type", part);
+ for(String part: parts) {
+ doc.add("type", part);
+ }
}
// leave this for future improvement
diff --git a/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java b/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java
index bf10d3de7..1c3d3e1d4 100644
--- a/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java
+++ b/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java
@@ -43,7 +43,29 @@ public class TestMoreIndexingFilter extends TestCase {
public void testGetParts() {
String[] parts = MoreIndexingFilter.getParts("text/html");
assertParts(parts, 2, "text", "html");
+ }
+ /**
+ * @since NUTCH-901
+ */
+ public void testNoParts(){
+ Configuration conf = NutchConfiguration.create();
+ conf.setBoolean("moreIndexingFilter.indexMimeTypeParts", false);
+ MoreIndexingFilter filter = new MoreIndexingFilter();
+ filter.setConf(conf);
+ assertNotNull(filter);
+ NutchDocument doc = new NutchDocument();
+ try{
+ filter.filter(doc, "http://nutch.apache.org/index.html", new WebPage());
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ assertNotNull(doc);
+ assertTrue(doc.getFieldNames().contains("type"));
+ assertEquals(1, doc.getFieldValues("type").size());
+ assertEquals("text/html", doc.getFieldValue("type"));
}
private void assertParts(String[] parts, int count, String... expected) {