Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1074 topN is ignored with maxNumSegments and generate.max.count

Markus Jelsmacaa378ba58a9
diff --git a/CHANGES.txt b/CHANGES.txt
index 12b54ac02..c24b5ccac 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -2,6 +2,8 @@ Nutch Change Log
Release 1.4 - Current development
+* NUTCH-1074 topN is ignored with maxNumSegments and generate.max.count (Robert Thomson via markus)
+
* NUTCH-1078 Upgrade all instances of commons logging to slf4j (with log4j backend) (lewismc)
* NUTCH-1115 Option to disable fixing embedded URL parameters in DomContentUtils (markus)
diff --git a/src/java/org/apache/nutch/crawl/Generator.java b/src/java/org/apache/nutch/crawl/Generator.java
index 1286baeac..b7617734c 100644
--- a/src/java/org/apache/nutch/crawl/Generator.java
+++ b/src/java/org/apache/nutch/crawl/Generator.java
@@ -115,6 +115,7 @@ public class Generator extends Configured implements Tool {
private long limit;
private long count;
private HashMap<String,int[]> hostCounts = new HashMap<String,int[]>();
+ private int segCounts[];
private int maxCount;
private boolean byDomain = false;
private Partitioner<Text,Writable> partitioner = new URLPartitioner();
@@ -155,6 +156,7 @@ public class Generator extends Configured implements Tool {
schedule = FetchScheduleFactory.getFetchSchedule(job);
scoreThreshold = job.getFloat(GENERATOR_MIN_SCORE, Float.NaN);
maxNumSegments = job.getInt(GENERATOR_MAX_NUM_SEGMENTS, 1);
+ segCounts = new int[maxNumSegments];
}
public void close() {}
@@ -269,6 +271,12 @@ public class Generator extends Configured implements Tool {
// increment hostCount
hostCount[1]++;
+ // check if topN reached, select next segment if it is
+ while (segCounts[hostCount[0]-1] >= limit && hostCount[0] < maxNumSegments) {
+ hostCount[0]++;
+ hostCount[1] = 0;
+ }
+
// reached the limit of allowed URLs per host / domain
// see if we can put it in the next segment?
if (hostCount[1] > maxCount) {
@@ -285,7 +293,11 @@ public class Generator extends Configured implements Tool {
}
}
entry.segnum = new IntWritable(hostCount[0]);
- } else entry.segnum = new IntWritable(currentsegmentnum);
+ segCounts[hostCount[0]-1]++;
+ } else {
+ entry.segnum = new IntWritable(currentsegmentnum);
+ segCounts[currentsegmentnum-1]++;
+ }
output.collect(key, entry);