cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r465914 - in /cocoon/branches/BRANCH_2_1_X: src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java status.xml
Date Thu, 19 Oct 2006 22:38:43 GMT
Author: joerg
Date: Thu Oct 19 15:38:41 2006
New Revision: 465914

URL: http://svn.apache.org/viewvc?view=rev&rev=465914
Log:
fixed COCOON-1936: Add analyzer parameter to SearchGenerator as stated by the docs.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java?view=diff&rev=465914&r1=465913&r2=465914
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java
(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/lucene/java/org/apache/cocoon/generation/SearchGenerator.java
Thu Oct 19 15:38:41 2006
@@ -16,13 +16,11 @@
  */
 package org.apache.cocoon.generation;
 
-import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
 
 import org.apache.cocoon.Constants;
 import org.apache.cocoon.ProcessingException;
@@ -96,9 +94,7 @@
  * @author <a href="mailto:conal@nzetc.org">Conal Tuohy</a>
  * @version CVS $Id$
  */
-public class SearchGenerator extends ServiceableGenerator
-    implements Contextualizable, Disposable
-{
+public class SearchGenerator extends ServiceableGenerator implements Contextualizable {
 
     /**
      * The XML namespace for the output document.
@@ -130,7 +126,6 @@
      */
     protected final static String Q_RESULTS_ELEMENT = PREFIX + ":" + RESULTS_ELEMENT;
 
-
     /**
      * Attribute <code>date</code> of <code>results</code> element.
      * It contains the date a long value, indicating when a search
@@ -219,8 +214,6 @@
     /**
      * Child element <code>field</code> of the <code>hit</code> element.
      * This element contains value of the stored field of a hit.
-     *
-     * @since 2.0.4
      */
     protected final static String FIELD_ELEMENT = "field";
 
@@ -287,6 +280,16 @@
     protected final static String INDEX_PARAM_DEFAULT = "index";
 
     /**
+     * Setup parameter name of analyzer name, ie <code>analyzer</code>.
+     */
+    protected final static String ANALYZER_PARAM = "analyzer";
+
+    /**
+     * Default value of analyzer parameter <code>analyzer</code>, ie <code>org.apache.lucene.analysis.standard.StandardAnalyzer</code>.
+     */
+    protected final static String ANALYZER_PARAM_DEFAULT = "org.apache.lucene.analysis.standard.StandardAnalyzer";
+    
+    /**
      * Setup the actual query from generator parameter,
      * ie <code>query</code>.
      */
@@ -336,11 +339,6 @@
      */
     protected final static String START_INDEX_PREVIOUS_PARAM_DEFAULT = "startPreviousIndex";
 
-    /**
-     *Description of the Field
-     *
-     * @since
-     */
     protected final static int START_INDEX_DEFAULT = 0;
 
     /**
@@ -349,22 +347,10 @@
      */
     protected final static String PAGE_LENGTH_PARAM = "page-length";
 
-    /**
-     *Description of the Field
-     *
-     * @since
-     */
     protected final static String PAGE_LENGTH_PARAM_DEFAULT = "pageLength";
 
-    /**
-     *Description of the Field
-     *
-     * @since
-     */
     protected final static int PAGE_LENGTH_DEFAULT = 10;
 
-
-
     /**
      * Default home directory of index directories.
      * <p>
@@ -381,6 +367,11 @@
      * The avalon component to use for searching.
      */
     private LuceneCocoonSearcher lcs;
+    
+    /**
+     * Analyzer used for searching
+     */
+    private String analyzer = null;
 
     /**
      * Absolute filesystem directory of lucene index directory
@@ -407,21 +398,27 @@
      */
     private Integer pageLength = null;
 
-
-    // TODO: parameterize()
-
     /**
-     * Set the current <code>ServiceManager</code> instance used by this
-     * <code>Serviceable</code>.
+     * Contextualize this class.
+     *
+     * <p>
+     *   Especially retrieve the work directory.
+     *   If the index directory is specified relativly, the working directory is
+     *   used as home directory of the index directory.
+     * </p>
+     *
+     * @param  context               Context to use
+     * @exception  ContextException  If contextualizing fails.
      */
-    public void service(ServiceManager manager) throws ServiceException {
-        super.service(manager);
+    public void contextualize(Context context) throws ContextException {
+        // retrieve the working directory, assuming that the index may reside there
+        workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
     }
 
+    // TODO: parameterize()
+
     /**
      * setup all members of this generator.
-     *
-     * @since
      */
     public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
              throws ProcessingException, SAXException, IOException {
@@ -446,7 +443,13 @@
         if (!index.isAbsolute()) {
             index = new File(workDir, index.toString());
         }
-
+        
+        // try to get the analyzer from the sitemap parameter
+        this.analyzer = par.getParameter(ANALYZER_PARAM, ANALYZER_PARAM_DEFAULT);
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Analyzer is set to: " + this.analyzer);
+        }
+        
         // try getting the queryString from the generator sitemap params
 
         queryString = par.getParameter(QUERY_PARAM, "");
@@ -458,6 +461,10 @@
                 queryString = request.getParameter(param_name);
             }
         }
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Search index with query: " + queryString);
+        }
+        
         // always try lookup the start index from the request params
         // get startIndex
         startIndex = null;
@@ -486,33 +493,12 @@
         }
     }
 
-
-    /**
-     * Contextualize this class.
-     *
-     * <p>
-     *   Especially retrieve the work directory.
-     *   If the index directory is specified relativly, the working directory is
-     *   used as home directory of the index directory.
-     * </p>
-     *
-     * @param  context               Context to use
-     * @exception  ContextException  If contextualizing fails.
-     * @since
-     */
-    public void contextualize(Context context) throws ContextException {
-        // retrieve the working directory, assuming that the index may reside there
-        workDir = (File) context.get(Constants.CONTEXT_WORK_DIR);
-    }
-
     /**
      * Generate xml content describing search results.
      * Entry point of the ComposerGenerator.
      * The xml content is generated from the hits object.
      *
-     *
      * @exception  IOException       when there is a problem reading the from file system.
-     * @since
      * @throws  SAXException         when there is a problem creating the output SAX events.
      * @throws  ProcessingException  when there is a problem obtaining the hits
      */
@@ -538,7 +524,6 @@
         this.contentHandler.endDocument();
     }
 
-
     /**
      * Create an Integer.
      * <p>
@@ -547,7 +532,6 @@
      *
      * @param  s  Converting s to an Integer
      * @return    Integer converted value originating from s, or null
-     * @since
      */
     private Integer createInteger(String s) {
         Integer i = null;
@@ -562,7 +546,6 @@
         return i;
     }
 
-
     /**
      * Build and generate the search results.
      * <p>
@@ -570,12 +553,10 @@
      *  taking page index, and length into account.
      * </p>
      *
-     * @since
      * @throws  SAXException         when there is a problem creating the output SAX events.
      * @throws  ProcessingException  when there is a problem obtaining the hits
      */
-    private void generateResults() throws SAXException, ProcessingException {
-
+    private void generateResults() throws SAXException, ProcessingException, IOException
{
         // Make the hits
         LuceneCocoonPager pager = buildHits();
 
@@ -599,12 +580,10 @@
         contentHandler.endElement(NAMESPACE, RESULTS_ELEMENT, Q_RESULTS_ELEMENT);
     }
 
-
     /**
      * Generate the xml content of all hits
      *
      * @param  pager                 the LuceneContentPager with the search results
-     * @since
      * @throws  SAXException         when there is a problem creating the output SAX events.
      */
     private void generateHits(LuceneCocoonPager pager) throws SAXException {
@@ -620,12 +599,10 @@
         }
     }
 
-
     /**
      * Generate the xml content for each hit.
      *
      * @param  pager                 the LuceneCocoonPager with the search results.
-     * @since
      * @throws  SAXException         when there is a problem creating the output SAX events.
      */
     private void generateHit(LuceneCocoonPager pager) throws SAXException {
@@ -668,16 +645,13 @@
         }
     }
 
-
     /**
      * Generate the navigation element.
      *
      * @param  pager                    Description of Parameter
      * @exception  SAXException         Description of Exception
-     * @since
      */
     private void generateNavigation(LuceneCocoonPager pager) throws SAXException {
-
         if (pager != null) {
             // generate navigation element
             atts.clear();
@@ -709,28 +683,21 @@
         }
     }
 
-
     /**
      * Build hits from a query input, and setup paging object.
      *
-     * @since
      * @throws  ProcessingException  if an error occurs
      */
-    private LuceneCocoonPager buildHits() throws ProcessingException {
-
+    private LuceneCocoonPager buildHits() throws ProcessingException, IOException {
         if (queryString != null && queryString.length() != 0) {
             Hits hits = null;
 
-            try {
-                Analyzer analyzer = LuceneCocoonHelper.getAnalyzer("org.apache.lucene.analysis.standard.StandardAnalyzer");
-                lcs.setAnalyzer(analyzer);
-                // get the directory where the index resides
-                Directory directory = LuceneCocoonHelper.getDirectory(index, false);
-                lcs.setDirectory(directory);
-                hits = lcs.search(queryString, LuceneXMLIndexer.BODY_FIELD);
-            } catch (IOException ioe) {
-                throw new ProcessingException("IOException in search", ioe);
-            }
+            Analyzer analyzer = LuceneCocoonHelper.getAnalyzer(this.analyzer);
+            lcs.setAnalyzer(analyzer);
+            // get the directory where the index resides
+            Directory directory = LuceneCocoonHelper.getDirectory(index, false);
+            lcs.setDirectory(directory);
+            hits = lcs.search(queryString, LuceneXMLIndexer.BODY_FIELD);
 
             // wrap the hits by an pager help object for accessing only a range of hits
             LuceneCocoonPager pager = new LuceneCocoonPager(hits);
@@ -771,10 +738,7 @@
         this.startIndex = null;
         this.pageLength = null;
         this.index = null;
+        this.analyzer = null;
     }
 
-    public void dispose() {
-        super.dispose();
-    }
 }
-

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&rev=465914&r1=465913&r2=465914
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Thu Oct 19 15:38:41 2006
@@ -184,6 +184,10 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.10" date="TBD">
+    <action dev="JH" type="fix" fixes-bug="COCOON-1936" due-to="Jeroen Reijn" due-to-email="j.reijn@hippo.nl">
+      Lucene: Add <code>analyzer</code> parameter to <code>SearchGenerator</code>
+      as stated by the docs.
+    </action>
     <action dev="AG" type="fix" fixes-bug="COCOON-1894" due-to="Geurt Wisselink" due-to-email="gwk@home.nl">
       Databases: Added support for the SQL:XML tag in SQLTransformer.
     </action>



Mime
View raw message