Author: siren
Date: Sat Jun 10 07:30:01 2006
New Revision: 413308
URL: http://svn.apache.org/viewvc?rev=413308&view=rev
Log:
added checkbox tile to control activity of clustering
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringCheckboxController.java
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster-checkbox.jsp
Modified:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/conf/tiles-defs.xml
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster.jsp
Modified:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/conf/tiles-defs.xml
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/conf/tiles-defs.xml?rev=413308&r1=413307&r2=413308&view=diff
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/conf/tiles-defs.xml
(original)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/conf/tiles-defs.xml
Sat Jun 10 07:30:01 2006
@@ -5,4 +5,7 @@
<definition name="cluster"
path="/plugin/web-clustering/cluster.jsp"
controllerClass="org.apache.nutch.webapp.controller.ClusteringController"
/>
+ <definition name="cluster-checkbox"
+ path="/plugin/web-clustering/cluster-checkbox.jsp"
+
controllerClass="org.apache.nutch.webapp.controller.ClusteringCheckboxController"
/>
</tiles-definitions>
Modified:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java?rev=413308&r1=413307&r2=413308&view=diff
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java
(original)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/clustering/ClusteringPresearchExtension.java
Sat Jun 10 07:30:01 2006
@@ -15,24 +15,50 @@
*/
package org.apache.nutch.clustering;
-import org.apache.nutch.webapp.common.SearchContext;
+import org.apache.nutch.webapp.common.ServiceLocator;
import org.apache.nutch.webapp.extension.PreSearchExtensionPoint;
+/**
+ * This class is responsible for interpreting request parameters
+ * and reacting if named parameter is defined.
+ *
+ * If clustering is available the result window is checked
+ * and expanded to 100 hits if required.
+ */
public class ClusteringPresearchExtension implements PreSearchExtensionPoint {
- /**
+
+ /**
+ * Check wether clustering is active or not
+ * @param locator
+ * @return true if clustering is active
+ */
+ public static boolean isClusteringActive(ServiceLocator locator){
+ return
locator.getSearchForm().getValueString(REQ_PARAM_CLUSTERING_ENABLED)!=null;
+ }
+
+ /**
+ * The parameter name to be searched from request
+ */
+ public static final String REQ_PARAM_CLUSTERING_ENABLED="clustering";
+
+ /*
* This hook is executed before actual search
* so we have a change to expand the result window
- * for clusterer
+ * for clusterer if clustering is active for the request
*/
- public void doPreSearch(SearchContext context) {
- int orig=context.getSearch().getHitsRequired();
+ public void doPreSearch(ServiceLocator locator) {
+
+ if(isClusteringActive(locator)) {
+
+ int orig=locator.getSearch().getHitsRequired();
- int hitsToCluster = context.getConfigiration().getInt(
+ int hitsToCluster = locator.getConfiguration().getInt(
"extension.clustering.hits-to-cluster", 100);
- if(orig < hitsToCluster){
- context.getSearch().setHitsRequired(hitsToCluster);
+ if(orig < hitsToCluster){
+ locator.getSearch().setHitsRequired(hitsToCluster);
+ }
}
}
}
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringCheckboxController.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringCheckboxController.java?rev=413308&view=auto
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringCheckboxController.java
(added)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringCheckboxController.java
Sat Jun 10 07:30:01 2006
@@ -0,0 +1,32 @@
+package org.apache.nutch.webapp.controller;
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.nutch.clustering.ClusteringPresearchExtension;
+import org.apache.nutch.webapp.common.ServiceLocator;
+import org.apache.nutch.webapp.controller.NutchController;
+import org.apache.struts.tiles.ComponentContext;
+
+/**
+ * Controller logic to decide wether clustering checkbox
+ * is checked or not.
+ */
+public class ClusteringCheckboxController extends NutchController {
+
+ public static final String REQ_ATTR_CLUSTERING_ENABLED="clusteringEnabled";
+
+ public void nutchPerform(ComponentContext tileContext,
+ HttpServletRequest request, HttpServletResponse response,
+ ServletContext servletContext) throws ServletException, IOException {
+
+ ServiceLocator locator=getServiceLocator(request);
+
+ if(ClusteringPresearchExtension.isClusteringActive(locator)) {
+ request.setAttribute(REQ_ATTR_CLUSTERING_ENABLED, "1");
+ }
+ }
+}
Modified:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java?rev=413308&r1=413307&r2=413308&view=diff
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java
(original)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/java/org/apache/nutch/webapp/controller/ClusteringController.java
Sat Jun 10 07:30:01 2006
@@ -22,6 +22,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.nutch.clustering.ClusteringPresearchExtension;
import org.apache.nutch.clustering.Clusters;
import org.apache.nutch.clustering.HitsCluster;
import org.apache.nutch.clustering.OnlineClusterer;
@@ -33,49 +34,53 @@
import org.apache.nutch.webapp.common.Startable;
import org.apache.struts.tiles.ComponentContext;
-public class ClusteringController extends NutchController implements Startable
{
+public class ClusteringController extends NutchController implements Startable
{
public static final String REQ_ATTR_CLUSTERS = "clusters";
- static OnlineClusterer clusterer=null;
-
+ static OnlineClusterer clusterer = null;
+
public void nutchPerform(ComponentContext tileContext,
HttpServletRequest request, HttpServletResponse response,
ServletContext servletContext) throws ServletException, IOException {
ServiceLocator locator = getServiceLocator(request);
- // display top N clusters and top Q documents inside them.
- int N = locator.getConfiguration().getInt(
- "extension.clustering.cluster-count", 10);
- int Q = locator.getConfiguration().getInt(
- "extension.clustering.cluster-top-documents-count", 3);
- int maxLabels = 2;
-
- HitDetails[] details = locator.getSearch().getDetails();
- Summary[] summaries = locator.getSearch().getSummaries();
-
- HitsCluster[] clusters = null;
- if (clusterer != null) {
- final long clusteringStart = System.currentTimeMillis();
- try {
- clusters = clusterer.clusterHits(details,
Summary.toStrings(summaries));
- final long clusteringDuration = System.currentTimeMillis()
- - clusteringStart;
- LOG.info("Clustering took: " + clusteringDuration + " milliseconds.");
-
- } catch (Exception e) {
- LOG.info("Could not do clustering???" + e);
- return;
+ if (ClusteringPresearchExtension.isClusteringActive(locator)) {
+
+ // display top N clusters and top Q documents inside them.
+ int N = locator.getConfiguration().getInt(
+ "extension.clustering.cluster-count", 10);
+ int Q = locator.getConfiguration().getInt(
+ "extension.clustering.cluster-top-documents-count", 3);
+ int maxLabels = 2;
+
+ HitDetails[] details = locator.getSearch().getDetails();
+ Summary[] summaries = locator.getSearch().getSummaries();
+
+ HitsCluster[] clusters = null;
+ if (clusterer != null) {
+ final long clusteringStart = System.currentTimeMillis();
+ try {
+ clusters = clusterer.clusterHits(details, Summary
+ .toStrings(summaries));
+ final long clusteringDuration = System.currentTimeMillis()
+ - clusteringStart;
+ LOG.info("Clustering took: " + clusteringDuration + "
milliseconds.");
+
+ } catch (Exception e) {
+ LOG.info("Could not do clustering???" + e);
+ return;
+ }
}
- }
- // set new limit if fever than N results
- N = Math.min(N, clusters.length);
+ // set new limit if fever than N results
+ N = Math.min(N, clusters.length);
- //set to request
- Clusters clusterResult = new Clusters(clusters, N, Q, maxLabels);
- request.setAttribute(REQ_ATTR_CLUSTERS, clusterResult);
+ // set to request
+ Clusters clusterResult = new Clusters(clusters, N, Q, maxLabels);
+ request.setAttribute(REQ_ATTR_CLUSTERS, clusterResult);
+ }
}
public void start(ServletContext servletContext) {
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster-checkbox.jsp
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster-checkbox.jsp?rev=413308&view=auto
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster-checkbox.jsp
(added)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster-checkbox.jsp
Sat Jun 10 07:30:01 2006
@@ -0,0 +1,11 @@
+<%@ page session="false"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
+<c:choose>
+ <c:when test="${clusteringEnabled != null}">
+ <input type="checkbox" name="clustering" value="on" checked="checked"/>
+ </c:when>
+ <c:otherwise>
+ <input id="clustbox" type="checkbox" name="clustering" /><label
for="clustbox"><fmt:message key="search.clustering"/></label>
+ </c:otherwise>
+</c:choose>
Modified:
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster.jsp
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster.jsp?rev=413308&r1=413307&r2=413308&view=diff
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster.jsp
(original)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-clustering/src/web/web-clustering/cluster.jsp
Sat Jun 10 07:30:01 2006
@@ -43,9 +43,5 @@
</c:choose>
</c:when>
- <c:otherwise>
- <!-- todo: i18n -->
-Unable to do clustering.
-</c:otherwise>
</c:choose>
</div>