Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1266 Subcollection to optionally write to configured fields

Markus Jelsma8a336cc89f3c
diff --git a/CHANGES.txt b/CHANGES.txt
index 0439204e8..9efa91888 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,5 +1,7 @@
Nutch Change Log
+* NUTCH-1266 Subcollection to optionally write to configured fields (markus)
+
* NUTCH-1005 Parse headings plugin (markus)
* NUTCH-1264 Configurable indexing plugin index-metadata (jnioche)
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 605dbf042..dd7df206b 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
@@ -165,25 +165,25 @@ public class CollectionManager extends Configured {
/**
* Return names of collections url is part of
- *
+ *
* @param url
* The url to test against Collections
- * @return Space delimited string of collection names url is part of
+ * @return Subcollections
*/
- public List<String> getSubCollections(final String url) {
- List<String> collections = new ArrayList<String>();
+ public List<Subcollection> getSubCollections(final String url) {
+ List<Subcollection> collections = new ArrayList<Subcollection>();
final Iterator iterator = collectionMap.values().iterator();
while (iterator.hasNext()) {
final Subcollection subCol = (Subcollection) iterator.next();
if (subCol.filter(url) != null) {
- collections.add(subCol.name);
+ collections.add(subCol);
}
}
- if (LOG.isTraceEnabled()) {
- LOG.trace("subcollections:" + Arrays.toString(collections.toArray()));
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("subcollections:" + Arrays.toString(collections.toArray()));
}
-
+
return collections;
}
diff --git a/src/plugin/subcollection/src/java/org/apache/nutch/collection/Subcollection.java b/src/plugin/subcollection/src/java/org/apache/nutch/collection/Subcollection.java
index f3ebd4136..7aca870f9 100644
--- a/src/plugin/subcollection/src/java/org/apache/nutch/collection/Subcollection.java
+++ b/src/plugin/subcollection/src/java/org/apache/nutch/collection/Subcollection.java
@@ -38,6 +38,7 @@ public class Subcollection extends Configured implements URLFilter{
public static final String TAG_WHITELIST="whitelist";
public static final String TAG_BLACKLIST="blacklist";
public static final String TAG_NAME="name";
+ public static final String TAG_KEY="key";
public static final String TAG_ID="id";
ArrayList blackList = new ArrayList();
@@ -49,6 +50,11 @@ public class Subcollection extends Configured implements URLFilter{
*/
String id;
+ /**
+ * SubCollection key
+ */
+ String key;
+
/**
* SubCollection name
*/
@@ -70,8 +76,18 @@ public class Subcollection extends Configured implements URLFilter{
* @param name name of SubCollection
*/
public Subcollection(String id, String name, Configuration conf) {
+ this(id, name, null, conf);
+ }
+
+ /** public Constructor
+ *
+ * @param id id of SubCollection
+ * @param name name of SubCollection
+ */
+ public Subcollection(String id, String name, String key, Configuration conf) {
this(conf);
this.id=id;
+ this.key = key;
this.name = name;
}
@@ -86,6 +102,13 @@ public class Subcollection extends Configured implements URLFilter{
return name;
}
+ /**
+ * @return Returns the key
+ */
+ public String getKey() {
+ return key;
+ }
+
/**
* @return Returns the id
*/
@@ -180,6 +203,12 @@ public class Subcollection extends Configured implements URLFilter{
this.blString = DOMUtil.getChildText(nodeList.item(0)).trim();
parseList(this.blackList, blString);
}
+
+ // Check if there's a key element or set default name
+ nodeList = collection.getElementsByTagName(TAG_KEY);
+ if (nodeList.getLength() == 1) {
+ this.key = DOMUtil.getChildText(nodeList.item(0)).trim();
+ }
}
/**
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 bf1df0010..ed302e90a 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
@@ -31,6 +31,7 @@ import org.apache.nutch.indexer.IndexingException;
import org.apache.nutch.indexer.NutchDocument;
import org.apache.nutch.collection.CollectionManager;
+import org.apache.nutch.collection.Subcollection;
import org.apache.nutch.crawl.CrawlDatum;
import org.apache.nutch.crawl.Inlinks;
@@ -62,8 +63,12 @@ public class SubcollectionIndexingFilter extends Configured implements IndexingF
* @param url
*/
private void addSubCollectionField(NutchDocument doc, String url) {
- for (String collname: CollectionManager.getCollectionManager(getConf()).getSubCollections(url)) {
- doc.add(FIELD_NAME, collname);
+ for (Subcollection coll : CollectionManager.getCollectionManager(getConf()).getSubCollections(url)) {
+ if (coll.getKey() == null) {
+ doc.add(FIELD_NAME, coll.getName());
+ } else {
+ doc.add(coll.getKey(), coll.getName());
+ }
}
}