org.apache.cocoon.components.search
Class SimpleLuceneCocoonSearcherImpl

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.components.search.SimpleLuceneCocoonSearcherImpl
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, Configurable, LogEnabled, Serviceable, LuceneCocoonSearcher

public class SimpleLuceneCocoonSearcherImpl
extends AbstractLogEnabled
implements LuceneCocoonSearcher, Configurable, Serviceable, Disposable, Recyclable

This class provides searching via lucene.

In order to do searching you need a lucene Directory where the lucene generated index resides. Moreover you must know the lucene Analyzer which has been used for indexing, and which will be used for searching.

Knowing this you can may start searching having a query which is parsable by an QueryParser, and having the name of the default field to use in searching.

This class returns an Hit object as its search result.

Version:
CVS $Id: SimpleLuceneCocoonSearcherImpl.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Bernhard Huber

Field Summary
protected static String ANALYZER_CLASSNAME_CONFIG
          Configuration element name of lucene's Analyzer class.
protected static String ANALYZER_CLASSNAME_DEFAULT
          Configuration element default value of lucene's Analyzer class.
protected static String DEFAULT_QUERY_CONFIG
          Configuration element name of default-query.
protected static String DEFAULT_QUERY_DEFAULT
          Configuration element default value of default-query.
protected static String DEFAULT_SEARCH_FIELD_CONFIG
          Configuration element name of default search field.
protected static String DEFAULT_SEARCH_FIELD_DEFAULT
          Configuration element default value of lucene's default search field.
protected static String DIRECTORY_CONFIG
          Configuration element name of lucene's default filesystem default directory.
protected static String DIRECTORY_DEFAULT
          Configuration element default value of filesystem default directory.
protected  ServiceManager manager
          The service manager instance
protected static String QUERYPARSER_CLASSNAME_CONFIG
          Configuration element name of query parser class name.
protected static String QUERYPARSER_CLASSNAME_DEFAULT
          Configuration element default value of queryparser-classname.
 
Fields inherited from interface org.apache.cocoon.components.search.LuceneCocoonSearcher
ROLE
 
Constructor Summary
SimpleLuceneCocoonSearcherImpl()
           
 
Method Summary
 void configure(Configuration conf)
          configure this component
 void dispose()
          Dispose this component, releasing IndexSearcher, and IndexReaderCache.
 org.apache.lucene.analysis.Analyzer getAnalyzer()
          get the analyzer.
 org.apache.lucene.index.IndexReader getReader()
          Get an IndexReader.
 void recycle()
          Recycle this component, releasing IndexSearcher, and IndexReaderCache.
 org.apache.lucene.search.Hits search(org.apache.lucene.search.Query query)
          Search lucene index.
 org.apache.lucene.search.Hits search(String query_string, String default_field)
          Search lucene index.
 void service(ServiceManager manager)
          Set the current ServiceManager instance used by this Serviceable.
 void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
          set an analyzer, overriding the analyzerClassnameDefault.
 void setDirectory(org.apache.lucene.store.Directory directory)
          Sets the directory attribute of the SimpleLuceneCocoonSearcherImpl object
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANALYZER_CLASSNAME_CONFIG

protected static final String ANALYZER_CLASSNAME_CONFIG
Configuration element name of lucene's Analyzer class.

Its value is analyzer-classname.

See Also:
Constant Field Values

ANALYZER_CLASSNAME_DEFAULT

protected static final String ANALYZER_CLASSNAME_DEFAULT
Configuration element default value of lucene's Analyzer class.

Its value is, org.apache.lucene.analysis.standard.StandardAnalyzer.

See Also:
Constant Field Values

DEFAULT_SEARCH_FIELD_CONFIG

protected static final String DEFAULT_SEARCH_FIELD_CONFIG
Configuration element name of default search field.

Its value is default-seach-field.

See Also:
Constant Field Values

DEFAULT_SEARCH_FIELD_DEFAULT

protected static final String DEFAULT_SEARCH_FIELD_DEFAULT
Configuration element default value of lucene's default search field.

Its value is body.

See Also:
Constant Field Values

DEFAULT_QUERY_CONFIG

protected static final String DEFAULT_QUERY_CONFIG
Configuration element name of default-query.

Its value is default-query.

See Also:
Constant Field Values

DEFAULT_QUERY_DEFAULT

protected static final String DEFAULT_QUERY_DEFAULT
Configuration element default value of default-query.

Its value is null.


QUERYPARSER_CLASSNAME_CONFIG

protected static final String QUERYPARSER_CLASSNAME_CONFIG
Configuration element name of query parser class name.

Its value is queryparser-classname.

See Also:
Constant Field Values

QUERYPARSER_CLASSNAME_DEFAULT

protected static final String QUERYPARSER_CLASSNAME_DEFAULT
Configuration element default value of queryparser-classname.

Its value is org.apache.lucene.queryParser.QueryParser.

See Also:
Constant Field Values

DIRECTORY_CONFIG

protected static final String DIRECTORY_CONFIG
Configuration element name of lucene's default filesystem default directory.

Its value is directory.

See Also:
Constant Field Values

DIRECTORY_DEFAULT

protected static final String DIRECTORY_DEFAULT
Configuration element default value of filesystem default directory.

Its value is null.


manager

protected ServiceManager manager
The service manager instance

Constructor Detail

SimpleLuceneCocoonSearcherImpl

public SimpleLuceneCocoonSearcherImpl()
Method Detail

setAnalyzer

public void setAnalyzer(org.apache.lucene.analysis.Analyzer analyzer)
set an analyzer, overriding the analyzerClassnameDefault.

Specified by:
setAnalyzer in interface LuceneCocoonSearcher
Parameters:
analyzer - The new analyzer value

getAnalyzer

public org.apache.lucene.analysis.Analyzer getAnalyzer()
get the analyzer.

Specified by:
getAnalyzer in interface LuceneCocoonSearcher

setDirectory

public void setDirectory(org.apache.lucene.store.Directory directory)
Sets the directory attribute of the SimpleLuceneCocoonSearcherImpl object

Specified by:
setDirectory in interface LuceneCocoonSearcher
Parameters:
directory - The new directory value

getReader

public org.apache.lucene.index.IndexReader getReader()
                                              throws IOException
Get an IndexReader.

As an IndexReader might be cached, it is check if the indexReader is still valid.

Returns:
IndexReader an up to date indexReader
Throws:
IOException - is thrown iff it's impossible to create an IndexReader

configure

public void configure(Configuration conf)
               throws ConfigurationException
configure this component

Specified by:
configure in interface Configurable
Parameters:
conf - of this component
Throws:
ConfigurationException - is thrown iff configuration of this component fails

service

public void service(ServiceManager manager)
             throws ServiceException
Set the current ServiceManager instance used by this Serviceable.

Specified by:
service in interface Serviceable
Parameters:
manager - manager of this component
Throws:
ServiceException - is never thrown

dispose

public void dispose()
Dispose this component, releasing IndexSearcher, and IndexReaderCache.

Specified by:
dispose in interface Disposable

recycle

public void recycle()
Recycle this component, releasing IndexSearcher, and IndexReaderCache.

Specified by:
recycle in interface Recyclable

search

public org.apache.lucene.search.Hits search(String query_string,
                                            String default_field)
                                     throws ProcessingException
Search lucene index.

Specified by:
search in interface LuceneCocoonSearcher
Parameters:
query_string - is lucene's query string
default_field - the lucene field to run the query
Returns:
lucene Hits
Throws:
ProcessingException - iff its not possible do run the query

search

public org.apache.lucene.search.Hits search(org.apache.lucene.search.Query query)
                                     throws ProcessingException
Search lucene index. This method is designed to be used by other components, or Flowscripts

Specified by:
search in interface LuceneCocoonSearcher
Parameters:
query - the lucene Query
Returns:
lucene Hits
Throws:
ProcessingException - if its not possible do run the query


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.