Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Fix a deficiency in the scoring API (NUTCH-321).

Andrzej Bialeckid3f42a810fce
diff --git a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java b/src/java/org/apache/nutch/crawl/CrawlDbReducer.java
index 0e2411ca8..e6c0da27d 100644
--- a/src/java/org/apache/nutch/crawl/CrawlDbReducer.java
+++ b/src/java/org/apache/nutch/crawl/CrawlDbReducer.java
@@ -149,7 +149,7 @@ public class CrawlDbReducer implements Reducer {
}
try {
- scfilters.updateDbScore((UTF8)key, result, linked);
+ scfilters.updateDbScore((UTF8)key, old, result, linked);
} catch (Exception e) {
if (LOG.isWarnEnabled()) {
LOG.warn("Couldn't update score, key=" + key + ": " + e);
diff --git a/src/java/org/apache/nutch/scoring/ScoringFilter.java b/src/java/org/apache/nutch/scoring/ScoringFilter.java
index 606bce79d..d308d29c7 100644
--- a/src/java/org/apache/nutch/scoring/ScoringFilter.java
+++ b/src/java/org/apache/nutch/scoring/ScoringFilter.java
@@ -111,12 +111,18 @@ public interface ScoringFilter extends Configurable, Pluggable {
* initial value of the original CrawlDatum, and also score values contributed by
* inlinked pages.
* @param url url of the page
- * @param datum original datum, with original score. Filters will update it in-place.
+ * @param old original datum, with original score. May be null if this is a newly
+ * discovered page. If not null, filters should use score values from this parameter
+ * as the starting values - the {@param datum} parameter may contain values that are
+ * no longer valid, if other updates occured between generation and this update.
+ * @param datum the new datum, with the original score saved at the time when
+ * fetchlist was generated. Filters should update this in-place, and it will be saved in
+ * the crawldb.
* @param inlinked (partial) list of CrawlDatum-s (with their scores) from
* links pointing to this page, found in the current update batch.
* @throws ScoringFilterException
*/
- public void updateDbScore(UTF8 url, CrawlDatum datum, List inlinked) throws ScoringFilterException;
+ public void updateDbScore(UTF8 url, CrawlDatum old, CrawlDatum datum, List inlinked) throws ScoringFilterException;
/**
* This method calculates a Lucene document boost.
diff --git a/src/java/org/apache/nutch/scoring/ScoringFilters.java b/src/java/org/apache/nutch/scoring/ScoringFilters.java
index 682fc024e..1892e0905 100644
--- a/src/java/org/apache/nutch/scoring/ScoringFilters.java
+++ b/src/java/org/apache/nutch/scoring/ScoringFilters.java
@@ -100,9 +100,9 @@ public class ScoringFilters extends Configured implements ScoringFilter {
}
/** Calculate updated page score during CrawlDb.update(). */
- public void updateDbScore(UTF8 url, CrawlDatum datum, List inlinked) throws ScoringFilterException {
+ public void updateDbScore(UTF8 url, CrawlDatum old, CrawlDatum datum, List inlinked) throws ScoringFilterException {
for (int i = 0; i < this.filters.length; i++) {
- this.filters[i].updateDbScore(url, datum, inlinked);
+ this.filters[i].updateDbScore(url, old, datum, inlinked);
}
}
diff --git a/src/plugin/scoring-opic/src/java/org/apache/nutch/scoring/opic/OPICScoringFilter.java b/src/plugin/scoring-opic/src/java/org/apache/nutch/scoring/opic/OPICScoringFilter.java
index 72ed75a6c..127920c62 100644
--- a/src/plugin/scoring-opic/src/java/org/apache/nutch/scoring/opic/OPICScoringFilter.java
+++ b/src/plugin/scoring-opic/src/java/org/apache/nutch/scoring/opic/OPICScoringFilter.java
@@ -77,13 +77,13 @@ public class OPICScoringFilter implements ScoringFilter {
}
/** Increase the score by a sum of inlinked scores. */
- public void updateDbScore(UTF8 url, CrawlDatum datum, List inlinked) throws ScoringFilterException {
+ public void updateDbScore(UTF8 url, CrawlDatum old, CrawlDatum datum, List inlinked) throws ScoringFilterException {
float adjust = 0.0f;
for (int i = 0; i < inlinked.size(); i++) {
CrawlDatum linked = (CrawlDatum)inlinked.get(i);
adjust += linked.getScore();
}
- datum.setScore(datum.getScore() + adjust);
+ datum.setScore(old.getScore() + adjust);
}
/** Store a float value of CrawlDatum.getScore() under Fetcher.SCORE_KEY. */