Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

Moved clusterer initialization to start method, restored the configuration option for number of hits to cluster

Sami Siren3a8dbaeaabf7
diff --git a/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java b/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java
index 60ed0e89b..57c2cfd9c 100644
--- a/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java
+++ b/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java
@@ -28,9 +28,11 @@ public class ClusteringPresearchExtension implements PreSearchExtensionPoint {
public void doPreSearch(SearchContext context) {
int orig=context.getSearch().getHitsRequired();
- //TODO set this configurable
- if(orig < 100){
- context.getSearch().setHitsRequired(100);
+ int hitsToCluster = context.getConfigiration().getInt(
+ "extension.clustering.hits-to-cluster", 100);
+
+ if(orig < hitsToCluster){
+ context.getSearch().setHitsRequired(hitsToCluster);
}
}
}
diff --git a/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java b/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java
index 3506c1807..8a40827eb 100644
--- a/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java
+++ b/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java
@@ -30,21 +30,21 @@ import org.apache.nutch.plugin.PluginRuntimeException;
import org.apache.nutch.searcher.HitDetails;
import org.apache.nutch.searcher.Summary;
import org.apache.nutch.webapp.common.ServiceLocator;
+import org.apache.nutch.webapp.common.Startable;
import org.apache.struts.tiles.ComponentContext;
-public class ClusteringController extends NutchController {
+public class ClusteringController extends NutchController implements Startable {
public static final String REQ_ATTR_CLUSTERS = "clusters";
+ static OnlineClusterer clusterer=null;
+
public void nutchPerform(ComponentContext tileContext,
HttpServletRequest request, HttpServletResponse response,
ServletContext servletContext) throws ServletException, IOException {
ServiceLocator locator = getServiceLocator(request);
- int HITS_TO_CLUSTER = locator.getConfiguration().getInt(
- "extension.clustering.hits-to-cluster", 100);
-
// display top N clusters and top Q documents inside them.
// TODO move these to configuration
int N = locator.getConfiguration().getInt(
@@ -53,15 +53,6 @@ public class ClusteringController extends NutchController {
"extension.clustering.cluster-top-documents-count", 3);
int maxLabels = 2;
- OnlineClusterer clusterer = null;
- try {
- clusterer = new OnlineClustererFactory(locator.getConfiguration())
- .getOnlineClusterer();
- } catch (PluginRuntimeException e) {
- LOG.info("Could not ionitialize Clusterer, is the plugin enabled?");
- return;
- }
-
HitDetails[] details = locator.getSearch().getDetails();
Summary[] summaries = locator.getSearch().getSummaries();
@@ -87,4 +78,15 @@ public class ClusteringController extends NutchController {
Clusters clusterResult = new Clusters(clusters, N, Q, maxLabels);
request.setAttribute(REQ_ATTR_CLUSTERS, clusterResult);
}
+
+ public void start(ServletContext servletContext) {
+ ServiceLocator locator = getServiceLocator(servletContext);
+ try {
+ clusterer = new OnlineClustererFactory(locator.getConfiguration())
+ .getOnlineClusterer();
+ } catch (PluginRuntimeException e) {
+ LOG.info("Could not ionitialize Clusterer, is the plugin enabled?");
+ return;
+ }
+ }
}