generate.max.count

对generate.max.count参数的处理在org.apache.nutch.crawl.Generator内部类Selector中java

org.apache.nutch.crawl.Generator中相关变量声明状况apache

private HashMap<String, int[]> hostCounts = new HashMap<String, int[]>();
private int maxCount;


内部类Selector的config方法中数组

maxCount = job.getInt(GENERATOR_MAX_COUNT, -1);


reduce方法中的处理dom

/***
一、获取 某一主机下的int[] ,若是为null,声明一个数组,放入map中,int数组第2个值+1;

*/

//1
int[] hostCount = hostCounts.get(hostordomain);
if (hostCount == null) {
	hostCount = new int[] { 1, 0 };
	hostCounts.put(hostordomain, hostCount);
}
hostCount[1]++;// increment hostCount

//二、检查是否到了topN的数量,若是hostCount的第一个值大于limit
// check if topN reached, select next segment if it is
while (segCounts[hostCount[0] - 1] >= limit//segCounts :
		&& 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) {
	if (hostCount[0] < maxNumSegments) {
		hostCount[0]++;
		hostCount[1] = 0;
	} else {
		if (hostCount[1] == maxCount + 1
				&& LOG.isInfoEnabled()) {
			LOG.info("Host or domain "
					+ hostordomain
					+ " has more than "
					+ maxCount
					+ " URLs for all "
					+ maxNumSegments
					+ " segments. Additional URLs won't be included in the fetchlist.");
		}
		// skip this entry
		continue;
	}
}
entry.segnum = new IntWritable(hostCount[0]);
segCounts[hostCount[0] - 1]++;
相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多信息