Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2232 DeduplicationJob should decode URL's before length is compared

Markus Jelsmaaf49ac4d2ee9
diff --git a/CHANGES.txt b/CHANGES.txt
index f7a22eeb5..62bf670f9 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -10,6 +10,8 @@ in the release announcement and keep it on top in this CHANGES.txt for the Nutch
Nutch Change Log
+* NUTCH-2232 DeduplicationJob should decode URL's before length is compared (Ron van der Vegt via markus)
+
* NUTCH-2229 Allow Jexl expressions on CrawlDatum's fixed attributes (markus)
* NUTCH-2227 RegexParseFilter (markus)
diff --git a/src/java/org/apache/nutch/crawl/DeduplicationJob.java b/src/java/org/apache/nutch/crawl/DeduplicationJob.java
index 2454f76d9..c4395707e 100644
--- a/src/java/org/apache/nutch/crawl/DeduplicationJob.java
+++ b/src/java/org/apache/nutch/crawl/DeduplicationJob.java
@@ -17,6 +17,8 @@
package org.apache.nutch.crawl;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Iterator;
@@ -193,8 +195,15 @@ public class DeduplicationJob extends NutchTool implements Tool {
break;
case "urlLength":
// same time? keep the one which has the shortest URL
- String urlExisting = existingDoc.getMetaData().get(urlKey).toString();
- String urlnewDoc = newDoc.getMetaData().get(urlKey).toString();
+ String urlExisting;
+ String urlnewDoc;
+ try {
+ urlExisting = URLDecoder.decode(existingDoc.getMetaData().get(urlKey).toString(), "UTF8");
+ urlnewDoc = URLDecoder.decode(newDoc.getMetaData().get(urlKey).toString(), "UTF8");
+ } catch (UnsupportedEncodingException e) {
+ LOG.error("Error decoding: " + urlKey);
+ throw new IOException("UnsupportedEncodingException for " + urlKey);
+ }
if (urlExisting.length() < urlnewDoc.length()) {
// mark new one as duplicate
writeOutAsDuplicate(newDoc, output, reporter);