Apache Nutch is an extensible and scalable web crawler
When computing multiple summaries, do each in a separate thread to take advantage of segments stored on different disks and/or multiple CPUs.
Douglass Cutting6ff9d92d044c
diff --git a/src/java/org/apache/nutch/searcher/FetchedSegments.java b/src/java/org/apache/nutch/searcher/FetchedSegments.javaindex e139b3a80..26426d524 100644--- a/src/java/org/apache/nutch/searcher/FetchedSegments.java+++ b/src/java/org/apache/nutch/searcher/FetchedSegments.java@@ -146,11 +146,51 @@ public class FetchedSegments implements HitSummarizer, HitContent {return new Summarizer().getSummary(text, query).toString();}+ private class SummaryThread extends Thread {+ private HitDetails details;+ private Query query;++ private String summary;+ private Throwable throwable;++ public SummaryThread(HitDetails details, Query query) {+ this.details = details;+ this.query = query;+ }++ public void run() {+ try {+ this.summary = getSummary(details, query);+ } catch (Throwable throwable) {+ this.throwable = throwable;+ }+ }++ }++public String[] getSummary(HitDetails[] details, Query query)throws IOException {+ SummaryThread[] threads = new SummaryThread[details.length];+ for (int i = 0; i < threads.length; i++) {+ threads[i] = new SummaryThread(details[i], query);+ threads[i].start();+ }+String[] results = new String[details.length];- for (int i = 0; i < details.length; i++)- results[i] = getSummary(details[i], query);+ for (int i = 0; i < threads.length; i++) {+ try {+ threads[i].join();+ } catch (InterruptedException e) {+ throw new RuntimeException(e);+ }+ if (threads[i].throwable instanceof IOException) {+ throw (IOException)threads[i].throwable;+ } else if (threads[i].throwable != null) {+ throw new RuntimeException(threads[i].throwable);+ }+ results[i] = threads[i].summary;+ }return results;}