Author: siren
Date: Sun Jun 18 10:25:46 2006
New Revision: 415158
URL: http://svn.apache.org/viewvc?rev=415158&view=rev
Log:
initial import of web-subcollecton plugin (simple ui extension to limit
searches to defined subcollections)
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/build.xml
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/lib/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/plugin.xml
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/conf/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/conf/tiles-defs.xml
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/controller/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/controller/SubcollectionSelectController.java
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/subcollection/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/subcollection/SubcollectionPreSearchExtension.java
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/resources/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/test/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/web/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/web/web-subcollection/
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/web/web-subcollection/select.jsp
Modified:
lucene/nutch/trunk/contrib/web2/plugins/build.xml
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java
lucene/nutch/trunk/contrib/web2/src/main/resources/org/nutch/jsp/resources.properties
Modified: lucene/nutch/trunk/contrib/web2/plugins/build.xml
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/build.xml?rev=415158&r1=415157&r2=415158&view=diff
==============================================================================
--- lucene/nutch/trunk/contrib/web2/plugins/build.xml (original)
+++ lucene/nutch/trunk/contrib/web2/plugins/build.xml Sun Jun 18 10:25:46 2006
@@ -18,6 +18,7 @@
<ant dir="web-keymatch" target="deploy"/>
<ant dir="web-query-propose-ontology" target="deploy"/>
<ant dir="web-query-propose-spellcheck" target="deploy"/>
+ <ant dir="web-subcollection" target="deploy"/>
</target>
<!-- ====================================================== -->
@@ -41,6 +42,7 @@
<ant dir="web-clustering" target="clean"/>
<ant dir="web-query-propose-ontology" target="clean"/>
<ant dir="web-query-propose-spellcheck" target="clean"/>
+ <ant dir="web-subcollection" target="clean"/>
</target>
</project>
Added: lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/build.xml
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/build.xml?rev=415158&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/build.xml (added)
+++ lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/build.xml Sun Jun
18 10:25:46 2006
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+
+<project name="web-subcollection" default="jar-core">
+
+ <import file="../build-plugin.xml"/>
+ <property name="nutch.root" location="${root}/../../../../"/>
+
+ <!-- Add compilation dependencies to classpath -->
+ <path id="plugin.deps">
+ <fileset dir="${nutch.root}/build">
+ <include name="**/subcollection/*.jar" />
+ </fileset>
+ </path>
+
+ <target name="init-plugin">
+ <echo>Copying resources templates</echo>
+ <copy todir="${build.classes}/resources">
+ <fileset dir="${resources.dir}" includes="**/*" />
+ </copy>
+ <echo>Copying UI configuration</echo>
+ <copy todir="${build.classes}">
+ <fileset dir="src/conf" includes="**/*" />
+ </copy>
+ <echo>Copying UI templates</echo>
+ <copy todir="${deploy.dir}/web">
+ <fileset dir="src/web" includes="**/*" />
+ </copy>
+ </target>
+
+</project>
Added: lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/plugin.xml
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/plugin.xml?rev=415158&view=auto
==============================================================================
--- lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/plugin.xml (added)
+++ lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/plugin.xml Sun
Jun 18 10:25:46 2006
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin id="web-subcollection" name="subcollection ui enhancements"
+ version="1.0.0" provider-name="apache.org">
+ <runtime>
+ <library name="web-subcollection.jar">
+ <export name="*" />
+ </library>
+ </runtime>
+ <requires>
+ <import plugin="nutch-extensionpoints" />
+ <import plugin="subcollection" />
+ </requires>
+ <extension id="org.apache.nutch.webapp.extension.UIExtensionPoint"
+ name="Nutch ui extension point"
+ point="org.apache.nutch.webapp.extension.UIExtensionPoint">
+ <implementation id="web-subcollection"
+ class="org.apache.nutch.webapp.extension.UIExtension.VoidImplementation" />
+ </extension>
+ <extension
+ id="org.apache.nutch.webapp.extension.PreSearchExtensionPoint"
+ name="Clustering extension for Web UI"
+ point="org.apache.nutch.webapp.extension.PreSearchExtensionPoint">
+ <implementation id="web-subcollection-presearch"
+
class="org.apache.nutch.webapp.subcollection.SubcollectionPreSearchExtension" />
+ </extension>
+</plugin>
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/conf/tiles-defs.xml
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/conf/tiles-defs.xml?rev=415158&view=auto
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/conf/tiles-defs.xml
(added)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/conf/tiles-defs.xml
Sun Jun 18 10:25:46 2006
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles
Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
+<tiles-definitions>
+<!--
+Tile to select subcollection
+ -->
+ <definition name="subcollection-select"
+ path="/plugin/web-subcollection/select.jsp"
+
controllerClass="org.apache.nutch.webapp.controller.SubcollectionSelectController">
+ </definition>
+</tiles-definitions>
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/controller/SubcollectionSelectController.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/controller/SubcollectionSelectController.java?rev=415158&view=auto
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/controller/SubcollectionSelectController.java
(added)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/controller/SubcollectionSelectController.java
Sun Jun 18 10:25:46 2006
@@ -0,0 +1,92 @@
+package org.apache.nutch.webapp.controller;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.nutch.collection.CollectionManager;
+import org.apache.nutch.collection.Subcollection;
+import org.apache.nutch.indexer.subcollection.SubcollectionIndexingFilter;
+import org.apache.nutch.webapp.common.ServiceLocator;
+import org.apache.nutch.webapp.common.Startable;
+import org.apache.nutch.webapp.controller.NutchController;
+import org.apache.struts.tiles.ComponentContext;
+
+/**
+ * This controller is responsible for providing Collection of
+ * subcollections for displaying.
+ */
+public class SubcollectionSelectController extends NutchController implements
Startable {
+
+ public class SubcollectionWrapper {
+ Subcollection col;
+ boolean checked;
+
+ /**
+ * UI Wrapper for subcollection
+ * @param col Subcollection
+ * @param checked is the subcollection "checked" / active
+ */
+ public SubcollectionWrapper(Subcollection col, boolean checked){
+ this.col=col;
+ this.checked=checked;
+ }
+
+ public String getId(){
+ return col.getId();
+ }
+
+ public String getName(){
+ return col.getName();
+ }
+
+ public boolean getChecked(){
+ return checked;
+ }
+}
+
+ public static final String REQ_ATTR_SUBCOLLECTIONS="subcollections";
+ public static final String
REQ_ATTR_COLLECTION_SELECTED="iscollectionlimited";
+
+ private CollectionManager collectionManager;
+
+ public void nutchPerform(ComponentContext tileContext,
+ HttpServletRequest request, HttpServletResponse response,
+ ServletContext servletContext) throws ServletException, IOException {
+
+ boolean hasSelectedCollection=false;
+ ServiceLocator serviceLocator = getServiceLocator(request);
+ Collection collections=collectionManager.getAll();
+
+ ArrayList wrapped=new ArrayList();
+ Iterator i=collections.iterator();
+
+ String
value=serviceLocator.getSearchForm().getValueString(SubcollectionIndexingFilter.FIELD_NAME);
+
+ while(i.hasNext()){
+ Subcollection collection=(Subcollection)i.next();
+ boolean checked=(value!=null && value.equals(collection.getId()));
+ wrapped.add(new SubcollectionWrapper(collection,checked));
+ if(checked){
+ hasSelectedCollection=true;
+ }
+ }
+
+ request.setAttribute(REQ_ATTR_SUBCOLLECTIONS, wrapped);
+ if(hasSelectedCollection){
+ LOG.info("collection was selected");
+ request.setAttribute(REQ_ATTR_COLLECTION_SELECTED,"1");
+ }
+ }
+
+ public void start(ServletContext servletContext) {
+ ServiceLocator serviceLocator=getServiceLocator(servletContext);
+
collectionManager=CollectionManager.getCollectionManager(serviceLocator.getConfiguration());
+ }
+
+}
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/subcollection/SubcollectionPreSearchExtension.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/subcollection/SubcollectionPreSearchExtension.java?rev=415158&view=auto
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/subcollection/SubcollectionPreSearchExtension.java
(added)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/java/org/apache/nutch/webapp/subcollection/SubcollectionPreSearchExtension.java
Sun Jun 18 10:25:46 2006
@@ -0,0 +1,29 @@
+package org.apache.nutch.webapp.subcollection;
+
+import org.apache.nutch.indexer.subcollection.SubcollectionIndexingFilter;
+import org.apache.nutch.searcher.Query;
+import org.apache.nutch.webapp.common.ServiceLocator;
+import org.apache.nutch.webapp.extension.PreSearchExtensionPoint;
+
+/**
+ * This class is responsible for limiting search to certain subcollection.
+ * Subcollection to be searched is defined with queryparameter named
+ * "subcollection".
+ */
+public class SubcollectionPreSearchExtension implements
PreSearchExtensionPoint {
+
+ public void doPreSearch(ServiceLocator locator) {
+ Query original=locator.getSearch().getQuery();
+ Query modified=(Query)original.clone();
+ try{
+ String
value=locator.getSearchForm().getValueString(SubcollectionIndexingFilter.FIELD_NAME);
+ if(value!=null && value.trim().length()>0) {
+ modified.addRequiredTerm(value,
SubcollectionIndexingFilter.FIELD_NAME);
+ }
+ } catch (Exception e){
+
+ }
+ locator.getSearch().setQuery(modified);
+ }
+
+}
Added:
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/web/web-subcollection/select.jsp
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/web/web-subcollection/select.jsp?rev=415158&view=auto
==============================================================================
---
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/web/web-subcollection/select.jsp
(added)
+++
lucene/nutch/trunk/contrib/web2/plugins/web-subcollection/src/web/web-subcollection/select.jsp
Sun Jun 18 10:25:46 2006
@@ -0,0 +1,25 @@
+<%@ page session="false"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
+<div id="subcollection-select"><fmt:message key="subcollection.info" />
+<c:forEach var="subcollection" items="${subcollections}">
+<c:choose>
+<c:when test="${subcollection.checked}">
+<input id="<c:out value="${subcollection.id}"/>"
+type="radio" name="subcollection" checked="checked"
+ value="<c:out value="${subcollection.id}"/>" />
+</c:when>
+<c:otherwise>
+<input id="<c:out value="${subcollection.id}"/>"
+type="radio" name="subcollection"
+ value="<c:out value="${subcollection.id}"/>" />
+</c:otherwise>
+</c:choose>
+<label id="<c:out value="${subcollection.id}"/>"><c:out
value="${subcollection.name}" /></label>
+</c:forEach>
+<c:if test="${iscollectionlimited!=null}">
+<input id="none"
+type="radio" name="subcollection"
+ value="" /><label id="none"><fmt:message key="subcollection.none" /></label>
+</c:if>
+</div>
Modified:
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java?rev=415158&r1=415157&r2=415158&view=diff
==============================================================================
---
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java
(original)
+++
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/BaseSearch.java
Sun Jun 18 10:25:46 2006
@@ -113,6 +113,7 @@
* Call plugins participating PreSearch activities
*/
void callPreSearch(ServiceLocator locator) {
+ LOG.info("presearch");
for (int i = 0; i < presearch.length; i++) {
presearch[i].doPreSearch(serviceLocator);
}
@@ -131,6 +132,7 @@
* Call plugins participating postSearch activities
*/
void callPostSearch(ServiceLocator locator) {
+ LOG.info("postsearch");
for (int i = 0; i < postsearch.length; i++) {
postsearch[i].doPostSearch(serviceLocator);
}
Modified:
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java?rev=415158&r1=415157&r2=415158&view=diff
==============================================================================
---
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java
(original)
+++
lucene/nutch/trunk/contrib/web2/src/main/java/org/apache/nutch/webapp/common/Search.java
Sun Jun 18 10:25:46 2006
@@ -232,7 +232,7 @@
* @param query
* The query to set.
*/
- protected void setQuery(Query query) {
+ public void setQuery(Query query) {
this.query = query;
}
Modified:
lucene/nutch/trunk/contrib/web2/src/main/resources/org/nutch/jsp/resources.properties
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/contrib/web2/src/main/resources/org/nutch/jsp/resources.properties?rev=415158&r1=415157&r2=415158&view=diff
==============================================================================
---
lucene/nutch/trunk/contrib/web2/src/main/resources/org/nutch/jsp/resources.properties
(original)
+++
lucene/nutch/trunk/contrib/web2/src/main/resources/org/nutch/jsp/resources.properties
Sun Jun 18 10:25:46 2006
@@ -96,4 +96,8 @@
preferences.numResults.info=
#text on save button
-preferences.submit=Save and return to search
\ No newline at end of file
+preferences.submit=Save and return to search
+
+#subcollection
+subcollection.info=Limit your search to:
+subcollection.none=Do not limit
\ No newline at end of file