Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Make sure we always have the segment name and score values in ParseData.metadata. Sometimes plugins would fail to copy them through, or a parsing error would produce empty ParseData.metadata.

Andrzej Bialecki8199e747522a
diff --git a/src/java/org/apache/nutch/fetcher/Fetcher.java b/src/java/org/apache/nutch/fetcher/Fetcher.java
index 2e17876c8..9c4e52f10 100644
--- a/src/java/org/apache/nutch/fetcher/Fetcher.java
+++ b/src/java/org/apache/nutch/fetcher/Fetcher.java
@@ -223,6 +223,9 @@ public class Fetcher extends NutchConfigured implements MapRunnable {
parse.getData().getMetadata().setProperty(SIGNATURE_KEY, StringUtil.toHexString(signature));
datum.setSignature(signature);
}
+ // add segment name and score to parseData metadata
+ parse.getData().getMetadata().setProperty(SEGMENT_NAME_KEY, segmentName);
+ parse.getData().getMetadata().setProperty(SCORE_KEY, Float.toString(datum.getScore()));
try {
output.collect
diff --git a/src/java/org/apache/nutch/parse/ParseSegment.java b/src/java/org/apache/nutch/parse/ParseSegment.java
index 2b54cb904..cceb538f8 100644
--- a/src/java/org/apache/nutch/parse/ParseSegment.java
+++ b/src/java/org/apache/nutch/parse/ParseSegment.java
@@ -58,9 +58,16 @@ public class ParseSegment extends NutchConfigured implements Mapper, Reducer {
status = new ParseStatus(e);
}
+ ContentProperties metadata = parse.getData().getMetadata();
// compute the new signature
byte[] signature = SignatureFactory.getSignature(getConf()).calculate(content, parse);
- parse.getData().getMetadata().setProperty(Fetcher.SIGNATURE_KEY, StringUtil.toHexString(signature));
+ metadata.setProperty(Fetcher.SIGNATURE_KEY, StringUtil.toHexString(signature));
+ // copy segment name and score
+ String segmentName = content.getMetadata().getProperty(Fetcher.SEGMENT_NAME_KEY);
+ String score = content.getMetadata().getProperty(Fetcher.SCORE_KEY);
+ metadata.setProperty(Fetcher.SEGMENT_NAME_KEY, segmentName);
+ metadata.setProperty(Fetcher.SCORE_KEY, score);
+
if (status.isSuccess()) {
output.collect(key, new ParseImpl(parse.getText(), parse.getData()));
} else {