Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

fix NUTCH-631 - thanks to Stefan Will

Sami Siren55a38c3e14fa
diff --git a/CHANGES.txt b/CHANGES.txt
index 3fc8e5c1c..c75d43ea5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -339,6 +339,9 @@ Unreleased changes (1.0-dev)
(Curtis d'Entremont, ab)
127. NUTCH-683 - NUTCH-676 broke CrawlDbMerger. (dogacan)
+
+128. NUTCH-631 - MoreIndexingFilter fails with NoSuchElementException
+ (Stefan Will, siren)
Release 0.9 - 2007-04-02
diff --git a/src/plugin/build.xml b/src/plugin/build.xml
index 84ccdf805..66fd363eb 100755
--- a/src/plugin/build.xml
+++ b/src/plugin/build.xml
@@ -93,6 +93,7 @@
<target name="test">
<parallel threadCount="2">
<ant dir="creativecommons" target="test"/>
+ <ant dir="index-more" target="test"/>
<ant dir="languageidentifier" target="test"/>
<ant dir="lib-http" target="test"/>
<ant dir="ontology" target="test"/>
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 d61be1a99..1dfad50ad 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
@@ -175,12 +175,31 @@ public class MoreIndexingFilter implements IndexingFilter {
return doc;
}
- // Add Content-Type and its primaryType and subType
+ /**
+ * <p>
+ * Add Content-Type and its primaryType and subType add contentType,
+ * primaryType and subType to field "type" as un-stored, indexed and
+ * un-tokenized, so that search results can be confined by contentType or its
+ * primaryType or its subType.
+ * </p>
+ * <p>
+ * For example, if contentType is application/vnd.ms-powerpoint, search can be
+ * done with one of the following qualifiers
+ * type:application/vnd.ms-powerpoint type:application type:vnd.ms-powerpoint
+ * all case insensitive. The query filter is implemented in
+ * {@link TypeQueryFilter}.
+ * </p>
+ *
+ * @param doc
+ * @param data
+ * @param url
+ * @return
+ */
private NutchDocument addType(NutchDocument doc, ParseData data, String url) {
MimeType mimeType = null;
String contentType = data.getMeta(Response.CONTENT_TYPE);
if (contentType == null) {
- // Note by Jerome Charron on 20050415:
+ // Note by Jerome Charron on 20050415:
// Content Type not solved by a previous plugin
// Or unable to solve it... Trying to find it
// Should be better to use the doc content too
@@ -202,32 +221,31 @@ public class MoreIndexingFilter implements IndexingFilter {
}
contentType = mimeType.getName();
- String primaryType = mimeType.getSuperType().getName();
- String subType = mimeType.getSubTypes().first().getName();
- // leave this for future improvement
- //MimeTypeParameterList parameterList = mimeType.getParameters()
-
- // add contentType, primaryType and subType to field "type"
- // as un-stored, indexed and un-tokenized, so that search results
- // can be confined by contentType or its primaryType or its subType.
- // For example, if contentType is application/vnd.ms-powerpoint,
- // search can be done with one of the following qualifiers
- // type:application/vnd.ms-powerpoint
- // type:application
- // type:vnd.ms-powerpoint
- // all case insensitive.
- // The query filter is implemented in TypeQueryFilter.java
+
doc.add("type", contentType);
- doc.add("type", primaryType);
- doc.add("type", subType);
- // add its primaryType and subType to respective fields
- doc.add("primaryType", primaryType);
- doc.add("subType", subType);
+ String[] parts = getParts(contentType);
+
+ for(String part: parts) {
+ doc.add("type", part);
+ }
+
+ // leave this for future improvement
+ //MimeTypeParameterList parameterList = mimeType.getParameters()
return doc;
}
+
+ /**
+ * Utility method for splitting mime type into type and subtype.
+ * @param mimeType
+ * @return
+ */
+ static String[] getParts(String mimeType) {
+ return mimeType.split("/");
+ }
+
// Reset title if we see non-standard HTTP header "Content-Disposition".
// It's a good indication that content provider wants filename therein
// be used as the title of this url.
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
new file mode 100644
index 000000000..1fcd136d9
--- /dev/null
+++ b/src/plugin/index-more/src/test/org/apache/nutch/indexer/more/TestMoreIndexingFilter.java
@@ -0,0 +1,35 @@
+/*
+ * 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.more;
+
+import junit.framework.TestCase;
+
+public class TestMoreIndexingFilter extends TestCase {
+
+ public void testGetParts() {
+ String[] parts = MoreIndexingFilter.getParts("text/html");
+ assertParts(parts, 2, "text", "html");
+
+ }
+
+ private void assertParts(String[] parts, int count, String... expected) {
+ assertEquals(count, parts.length);
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals(expected[i], parts[i]);
+ }
+ }
+}