Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

applied NUTCH-716 to 1.3

Julien Niochef93d56476021
diff --git a/CHANGES.txt b/CHANGES.txt
index a826d2cc7..0be9e7541 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Release 1.3 - Current Development
+* NUTCH-716 Make subcollection index filed multivalued (Dmitry Lihachev via jnioche)
+
* NUTCH-905 Configurable file protocol parent directory crawling (Thorsten Scherler, mattmann, ab)
* NUTCH-787 ScoringFilters should not override the injected score (jnioche)
diff --git a/conf/schema.xml b/conf/schema.xml
index 2fb636afa..27159efe4 100644
--- a/conf/schema.xml
+++ b/conf/schema.xml
@@ -91,7 +91,7 @@
<!-- fields for subcollection plugin -->
<field name="subcollection" type="string" stored="true"
- indexed="true"/>
+ indexed="true" multiValued="true"/>
<!-- fields for feed plugin -->
<field name="author" type="string" stored="true" indexed="true"/>
diff --git a/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java b/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java
index 52ba2733a..3fc170a4d 100644
--- a/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java
+++ b/src/plugin/subcollection/src/java/org/apache/nutch/collection/CollectionManager.java
@@ -22,9 +22,12 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
@@ -89,7 +92,7 @@ public class CollectionManager extends Configured {
.getElementsByTagName(Subcollection.TAG_COLLECTION);
if (LOG.isInfoEnabled()) {
- LOG.info("file has" + nodeList.getLength() + " elements");
+ LOG.info("file has " + nodeList.getLength() + " elements");
}
for (int i = 0; i < nodeList.getLength(); i++) {
@@ -115,7 +118,7 @@ public class CollectionManager extends Configured {
impl=new CollectionManager(conf);
objectCache.setObject(key,impl);
} catch (Exception e) {
- throw new RuntimeException("Couldn't create CollectionManager",e);
+ throw new RuntimeException("Couldn't create CollectionManager", e);
}
}
return impl;
@@ -169,22 +172,21 @@ public class CollectionManager extends Configured {
* The url to test against Collections
* @return Space delimited string of collection names url is part of
*/
- public String getSubCollections(final String url) {
- StringBuilder collections = new StringBuilder();
+ public List<String> getSubCollections(final String url) {
+ List<String> collections = new ArrayList<String>();
final Iterator iterator = collectionMap.values().iterator();
while (iterator.hasNext()) {
final Subcollection subCol = (Subcollection) iterator.next();
if (subCol.filter(url) != null) {
- if (collections.length() > 0) {
- collections.append(' ');
- }
- collections.append(subCol.name);
+ collections.add(subCol.name);
}
}
- if (LOG.isTraceEnabled()) { LOG.trace("subcollections:" + collections); }
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("subcollections:" + Arrays.toString(collections.toArray()));
+ }
- return collections.toString();
+ return collections;
}
/**
diff --git a/src/plugin/subcollection/src/java/org/apache/nutch/indexer/subcollection/SubcollectionIndexingFilter.java b/src/plugin/subcollection/src/java/org/apache/nutch/indexer/subcollection/SubcollectionIndexingFilter.java
index db635c03e..6651206a6 100644
--- a/src/plugin/subcollection/src/java/org/apache/nutch/indexer/subcollection/SubcollectionIndexingFilter.java
+++ b/src/plugin/subcollection/src/java/org/apache/nutch/indexer/subcollection/SubcollectionIndexingFilter.java
@@ -62,8 +62,9 @@ public class SubcollectionIndexingFilter extends Configured implements IndexingF
* @param url
*/
private void addSubCollectionField(NutchDocument doc, String url) {
- String collname = CollectionManager.getCollectionManager(getConf()).getSubCollections(url);
- doc.add(FIELD_NAME, collname);
+ for (String collname: CollectionManager.getCollectionManager(getConf()).getSubCollections(url)) {
+ doc.add(FIELD_NAME, collname);
+ }
}
public NutchDocument filter(NutchDocument doc, Parse parse, Text url, CrawlDatum datum, Inlinks inlinks) throws IndexingException {