(UrlWithScore key, Iterable<NutchWritable> values,
Context context)
| 79 | } |
| 80 | |
| 81 | @Override |
| 82 | protected void reduce(UrlWithScore key, Iterable<NutchWritable> values, |
| 83 | Context context) throws IOException, InterruptedException { |
| 84 | String keyUrl = key.getUrl().toString(); |
| 85 | |
| 86 | WebPage page = null; |
| 87 | //initialize old_page for checking if the outlink is already in the datastore |
| 88 | WebPage old_page = null; |
| 89 | inlinkedScoreData.clear(); |
| 90 | |
| 91 | for (NutchWritable nutchWritable : values) { |
| 92 | Writable val = nutchWritable.get(); |
| 93 | if (val instanceof WebPageWritable) { |
| 94 | page = ((WebPageWritable) val).getWebPage(); |
| 95 | } else { |
| 96 | inlinkedScoreData.add((ScoreDatum) val); |
| 97 | if (inlinkedScoreData.size() >= maxLinks) { |
| 98 | LOG.info("Limit reached, skipping further inlinks for " + keyUrl); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | String url; |
| 104 | try { |
| 105 | url = TableUtil.unreverseUrl(keyUrl); |
| 106 | } catch (Exception e) { |
| 107 | // this can happen because a newly discovered malformed link |
| 108 | // may slip by url filters |
| 109 | // TODO: Find a better solution |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | //check if page is already in the db |
| 114 | if(page == null && (old_page = datastore.get(keyUrl)) != null) { |
| 115 | //if we return here inlinks will not be updated |
| 116 | page=old_page; |
| 117 | } |
| 118 | else if (page == null) { //new row |
| 119 | if (!additionsAllowed) { |
| 120 | return; |
| 121 | } |
| 122 | page = WebPage.newBuilder().build(); |
| 123 | schedule.initializeSchedule(url, page); |
| 124 | page.setStatus((int) CrawlStatus.STATUS_UNFETCHED); |
| 125 | try { |
| 126 | scoringFilters.initialScore(url, page); |
| 127 | } catch (ScoringFilterException e) { |
| 128 | page.setScore(0.0f); |
| 129 | } |
| 130 | } else { |
| 131 | byte status = page.getStatus().byteValue(); |
| 132 | switch (status) { |
| 133 | case CrawlStatus.STATUS_FETCHED: // succesful fetch |
| 134 | case CrawlStatus.STATUS_REDIR_TEMP: // successful fetch, redirected |
| 135 | case CrawlStatus.STATUS_REDIR_PERM: |
| 136 | case CrawlStatus.STATUS_NOTMODIFIED: // successful fetch, notmodified |
| 137 | int modified = FetchSchedule.STATUS_UNKNOWN; |
| 138 | if (status == CrawlStatus.STATUS_NOTMODIFIED) { |
nothing calls this directly
no test coverage detected