You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by je...@apache.org on 2004/06/21 11:43:22 UTC

cvs commit: cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search LuceneCocoonSearcher.java SimpleLuceneCocoonSearcherImpl.java

jeremy      2004/06/21 02:43:22

  Modified:    src/blocks/lucene/java/org/apache/cocoon/components/search
                        LuceneCocoonSearcher.java
                        SimpleLuceneCocoonSearcherImpl.java
  Log:
  adding to the interface to suppory Query Bean
  
  Revision  Changes    Path
  1.4       +31 -1     cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search/LuceneCocoonSearcher.java
  
  Index: LuceneCocoonSearcher.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search/LuceneCocoonSearcher.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- LuceneCocoonSearcher.java	5 Mar 2004 13:01:59 -0000	1.3
  +++ LuceneCocoonSearcher.java	21 Jun 2004 09:43:22 -0000	1.4
  @@ -19,8 +19,10 @@
   import org.apache.cocoon.ProcessingException;
   import org.apache.lucene.analysis.Analyzer;
   import org.apache.lucene.search.Hits;
  +import org.apache.lucene.search.Query;
   import org.apache.lucene.store.Directory;
   
  +
   /**
    * The avalon behavioural component interface of a searcher.
    * <p>
  @@ -64,6 +66,21 @@
   
   
       /**
  +     * Gets the analyzer attribute of the LuceneCocoonSearcher object
  +     * <p>
  +     *   The analyzer determines the tokenization of the query,
  +     *   and strategy of matching.
  +     * </p>
  +     * <p>
  +     *   The analyzer class defined here should be equivalent to the analyzer
  +     *   class used when creating the index used for searching.
  +     * </p>
  +     *
  +     * @since 2.1.6
  +     */
  +    Analyzer getAnalyzer();
  +
  +    /**
        * Sets the directory attribute of the LuceneCocoonSearcher object
        * <p>
        *   The directory specifies the directory used for looking up the
  @@ -89,5 +106,18 @@
        * @since
        */
       Hits search(String query_string, String default_field) throws ProcessingException;
  +
  +    /**
  +     * Search using a Lucene Query object, returning zero, or more hits.
  +     * <p>
  +     * </p>
  +     *
  +     * @param  query                    A lucene query
  +     * @return                          Hits zero or more hits matching the query string
  +     * @exception  ProcessingException  throwing due to processing errors while
  +     *   looking up the index directory, parsing the query string, generating the hits.
  +     * @since 2.1.6
  +     */
  +    Hits search(Query query) throws ProcessingException;
   }
   
  
  
  
  1.7       +31 -1     cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java
  
  Index: SimpleLuceneCocoonSearcherImpl.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/lucene/java/org/apache/cocoon/components/search/SimpleLuceneCocoonSearcherImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- SimpleLuceneCocoonSearcherImpl.java	5 Mar 2004 13:01:59 -0000	1.6
  +++ SimpleLuceneCocoonSearcherImpl.java	21 Jun 2004 09:43:22 -0000	1.7
  @@ -195,6 +195,13 @@
           this.analyzer = analyzer;
       }
   
  +    /**
  +     * get the analyzer.
  +     *
  +     */
  +    public Analyzer getAnalyzer() {
  +        return this.analyzer;
  +    }
   
       /**
        *Sets the directory attribute of the SimpleLuceneCocoonSearcherImpl object
  @@ -361,6 +368,29 @@
           return hits;
       }
   
  +    /**
  +     * Search lucene index.
  +     * This method is designed to be used by other components, or Flowscripts
  +     *
  +     * @param  query                    the lucene Query
  +     * @return                          lucene Hits
  +     * @exception  ProcessingException  if its not possible do run the query
  +     */
  +    public Hits search(Query query) throws ProcessingException {
  +        Hits hits = null;
  +        try {
  +            // release index searcher for each new search
  +            releaseIndexSearcher();
  +
  +            IndexSearcher indexSearcher = new IndexSearcher(getReader());
  +            hits = indexSearcher.search(query);
  +            // do not close indexSearcher now, as using hits needs an
  +            // opened indexSearcher indexSearcher.close();
  +        } catch (IOException ioe) {
  +            throw new ProcessingException("Cannot access hits", ioe);
  +        }
  +        return hits;
  +    }
   
       /**
        * Release the index searcher.