You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by ab...@apache.org on 2008/01/16 17:51:22 UTC
svn commit: r612505 - in /lucene/nutch/trunk: CHANGES.txt
src/java/org/apache/nutch/crawl/Generator.java
src/java/org/apache/nutch/tools/FreeGenerator.java
Author: ab
Date: Wed Jan 16 08:51:19 2008
New Revision: 612505
URL: http://svn.apache.org/viewvc?rev=612505&view=rev
Log:
NUTCH-584 - urls missing from fetchlists.
Modified:
lucene/nutch/trunk/CHANGES.txt
lucene/nutch/trunk/src/java/org/apache/nutch/crawl/Generator.java
lucene/nutch/trunk/src/java/org/apache/nutch/tools/FreeGenerator.java
Modified: lucene/nutch/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/CHANGES.txt?rev=612505&r1=612504&r2=612505&view=diff
==============================================================================
--- lucene/nutch/trunk/CHANGES.txt (original)
+++ lucene/nutch/trunk/CHANGES.txt Wed Jan 16 08:51:19 2008
@@ -189,6 +189,8 @@
65. NUTCH-597 - NPE in Fetcher2 (Remco Verhoef via ab)
+66. NUTCH-584 - urls missing from fetchlist (Ruslan Ermilov, ab)
+
Release 0.9 - 2007-04-02
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/crawl/Generator.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/java/org/apache/nutch/crawl/Generator.java?rev=612505&r1=612504&r2=612505&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/crawl/Generator.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/crawl/Generator.java Wed Jan 16 08:51:19 2008
@@ -267,9 +267,23 @@
public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {
SelectorEntry entry = (SelectorEntry)value;
- output.collect(entry.url, entry.datum);
+ output.collect(entry.url, entry);
}
}
+
+ public static class PartitionReducer extends MapReduceBase implements Reducer {
+
+ public void reduce(WritableComparable key, Iterator values,
+ OutputCollector output, Reporter reporter) throws IOException {
+ // if using HashComparator, we get only one input key in case of hash collision
+ // so use only URLs from values
+ while (values.hasNext()) {
+ SelectorEntry entry = (SelectorEntry)values.next();
+ output.collect(entry.url, entry.datum);
+ }
+ }
+
+ }
/** Sort fetch lists by hash of URL. */
public static class HashComparator extends WritableComparator {
@@ -457,7 +471,10 @@
job.setInputFormat(SequenceFileInputFormat.class);
job.setMapperClass(SelectorInverseMapper.class);
+ job.setMapOutputKeyClass(Text.class);
+ job.setMapOutputValueClass(SelectorEntry.class);
job.setPartitionerClass(PartitionUrlByHost.class);
+ job.setReducerClass(PartitionReducer.class);
job.setNumReduceTasks(numLists);
job.setOutputPath(output);
Modified: lucene/nutch/trunk/src/java/org/apache/nutch/tools/FreeGenerator.java
URL: http://svn.apache.org/viewvc/lucene/nutch/trunk/src/java/org/apache/nutch/tools/FreeGenerator.java?rev=612505&r1=612504&r2=612505&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/tools/FreeGenerator.java (original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/tools/FreeGenerator.java Wed Jan 16 08:51:19 2008
@@ -18,7 +18,9 @@
package org.apache.nutch.tools;
import java.io.IOException;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map.Entry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -77,6 +79,8 @@
normalizers = new URLNormalizers(job, URLNormalizers.SCOPE_INJECT);
}
}
+
+ Generator.SelectorEntry entry = new Generator.SelectorEntry();
public void map(WritableComparable key, Writable value, OutputCollector output, Reporter reporter) throws IOException {
// value is a line of text
@@ -102,12 +106,22 @@
}
return;
}
- output.collect(url, datum);
+ entry.datum = datum;
+ entry.url = url;
+ output.collect(url, entry);
}
public void reduce(WritableComparable key, Iterator values, OutputCollector output, Reporter reporter) throws IOException {
- // pick just one (discard duplicates)
- output.collect(key, (Writable)values.next());
+ // pick unique urls from values - discard the reduce key due to hash collisions
+ HashMap<Text, CrawlDatum> unique = new HashMap<Text, CrawlDatum>();
+ while (values.hasNext()) {
+ Generator.SelectorEntry entry = (Generator.SelectorEntry)values.next();
+ unique.put(entry.url, entry.datum);
+ }
+ // output unique urls
+ for (Entry<Text, CrawlDatum> e : unique.entrySet()) {
+ output.collect(e.getKey(), e.getValue());
+ }
}
}
@@ -142,6 +156,8 @@
job.addInputPath(new Path(args[0]));
job.setInputFormat(TextInputFormat.class);
job.setMapperClass(FG.class);
+ job.setMapOutputKeyClass(Text.class);
+ job.setMapOutputValueClass(Generator.SelectorEntry.class);
job.setPartitionerClass(PartitionUrlByHost.class);
job.setReducerClass(FG.class);
String segName = Generator.generateSegmentName();