MCPcopy Create free account
hub / github.com/apache/nutch / reduce

Method reduce

src/java/org/apache/nutch/crawl/GeneratorReducer.java:51–88  ·  view source on GitHub ↗
(SelectorEntry key, Iterable<WebPage> values,
      Context context)

Source from the content-addressed store, hash-verified

49 private Utf8 batchId;
50
51 @Override
52 protected void reduce(SelectorEntry key, Iterable<WebPage> values,
53 Context context) throws IOException, InterruptedException {
54 for (WebPage page : values) {
55 if (count >= limit) {
56 return;
57 }
58 if (maxCount > 0) {
59 String hostordomain;
60 if (byDomain) {
61 hostordomain = URLUtil.getDomainName(key.url);
62 } else {
63 hostordomain = URLUtil.getHost(key.url);
64 }
65
66 Integer hostCount = hostCountMap.get(hostordomain);
67 if (hostCount == null) {
68 hostCountMap.put(hostordomain, 0);
69 hostCount = 0;
70 }
71 if (hostCount >= maxCount) {
72 return;
73 }
74 hostCountMap.put(hostordomain, hostCount + 1);
75 }
76
77 Mark.GENERATE_MARK.putMark(page, batchId);
78 page.setBatchId(batchId);
79 try {
80 context.write(TableUtil.reverseUrl(key.url), page);
81 } catch (MalformedURLException e) {
82 context.getCounter("Generator", "MALFORMED_URL").increment(1);
83 continue;
84 }
85 context.getCounter("Generator", "GENERATE_MARK").increment(1);
86 count++;
87 }
88 }
89
90 @Override
91 protected void setup(Context context) throws IOException,

Callers

nothing calls this directly

Calls 8

getDomainNameMethod · 0.95
getHostMethod · 0.95
reverseUrlMethod · 0.95
putMarkMethod · 0.80
getMethod · 0.65
writeMethod · 0.65
putMethod · 0.45
setBatchIdMethod · 0.45

Tested by

no test coverage detected