org.opencms.search
Class CmsSearchManager

java.lang.Object
  extended byorg.opencms.search.CmsSearchManager
All Implemented Interfaces:
I_CmsEventListener, I_CmsScheduledJob

public class CmsSearchManager
extends Object
implements I_CmsScheduledJob, I_CmsEventListener

Implements the general management and configuration of the search and indexing facilities in OpenCms.

Since:
6.0.0
Version:
$Revision: 1.49 $
Author:
Carsten Weinholz, Thomas Weckert

Field Summary
 
Fields inherited from interface org.opencms.main.I_CmsEventListener
EVENT_CLEAR_CACHES, EVENT_CLEAR_OFFLINE_CACHES, EVENT_CLEAR_ONLINE_CACHES, EVENT_FLEX_CACHE_CLEAR, EVENT_FLEX_PURGE_JSP_REPOSITORY, EVENT_LOGIN_USER, EVENT_PROJECT_MODIFIED, EVENT_PROPERTY_DEFINITION_CREATED, EVENT_PROPERTY_DEFINITION_MODIFIED, EVENT_PROPERTY_MODIFIED, EVENT_PUBLISH_PROJECT, EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, EVENT_RESOURCE_COPIED, EVENT_RESOURCE_CREATED, EVENT_RESOURCE_DELETED, EVENT_RESOURCE_LIST_MODIFIED, EVENT_RESOURCE_MODIFIED, EVENT_RESOURCES_AND_PROPERTIES_MODIFIED, EVENT_RESOURCES_MODIFIED, EVENT_UPDATE_EXPORTS, KEY_CMSOBJECT, KEY_DBCONTEXT, KEY_PROJECTID, KEY_PUBLISHID, KEY_REPORT, LISTENERS_FOR_ALL_EVENTS
 
Constructor Summary
CmsSearchManager()
          Default constructer when called as cron job.
 
Method Summary
 void addAnalyzer(CmsSearchAnalyzer analyzer)
          Adds an analyzer.
 void addDocumentTypeConfig(CmsSearchDocumentType documentType)
          Adds a document type.
 void addSearchIndex(CmsSearchIndex searchIndex)
          Adds a search index configuration.
 void addSearchIndexSource(CmsSearchIndexSource searchIndexSource)
          Adds a search index source configuration.
 void cmsEvent(CmsEvent event)
          Implements the event listener of this class.
protected  Analyzer getAnalyzer(String locale)
          Returns an analyzer for the given language.
 Map getAnalyzers()
          Returns an unmodifiable view (read-only) of the Analyzers Map.
 CmsSearchAnalyzer getCmsSearchAnalyzer(String locale)
          Returns the CmsSearchAnalyzer Object.
 String getDirectory()
          Returns the name of the directory below WEB-INF/ where the search indexes are stored.
protected  I_CmsDocumentFactory getDocumentFactory(A_CmsIndexResource resource)
          Returns a lucene document factory for given resource.
 CmsSearchDocumentType getDocumentTypeConfig(String name)
          Returns a document type config.
 Map getDocumentTypeConfigs()
          Returns an unmodifiable view (read-only) of the DocumentTypeConfigs Map.
protected  List getDocumentTypes()
          Returns the set of names of all configured documenttypes.
 I_CmsTermHighlighter getHighlighter()
          Returns the highlighter.
 CmsSearchIndex getIndex(String indexName)
          Returns the index belonging to the passed name.
 List getIndexNames()
          Returns the names of all configured indexes.
 CmsSearchIndexSource getIndexSource(String sourceName)
          Returns a search index source for a specified source name.
 int getMaxExcerptLength()
          Returns the max.
protected  Map getResultCache()
          Returns the common cache for buffering search results.
 String getResultCacheSize()
          Returns the result cache size.
 List getSearchIndexs()
          Returns an unmodifiable list of all configured indexes.
 Map getSearchIndexSources()
          Returns an unmodifiable view (read-only) of the SearchIndexSources Map.
 String getTimeout()
          Returns the timeout to abandon threads indexing a resource.
protected  void initAvailableDocumentTypes()
          Initializes the available Cms resource types to be indexed.
 void initialize(CmsObject cms)
          Initializes the search manager.
protected  void initSearchIndexes()
          Initializes the configured search indexes.
 String launch(CmsObject cms, Map parameters)
          Method for automatically rebuilding indexes configured with auto.
 void setDirectory(String value)
          Sets the name of the directory below WEB-INF/ where the search indexes are stored.
 void setHighlighter(String highlighter)
          Sets the highlighter.
 void setMaxExcerptLength(String maxExcerptLength)
          Sets the max.
 void setResultCacheSize(String value)
          Sets the result cache size.
 void setTimeout(String value)
          Sets the timeout to abandon threads indexing a resource.
 void updateIndex(I_CmsReport report)
          Updates all configured indexes.
 void updateIndex(I_CmsReport report, boolean wait)
          Updates all configured indexes..
 void updateIndex(String indexName)
          Updates (if required creates) the index with the given name.
 void updateIndex(String indexName, I_CmsReport report)
          Updates (if required creates) the index with the given name.
 void updateIndex(String indexName, I_CmsReport report, boolean wait)
          Updates (if required creates) the index with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsSearchManager

public CmsSearchManager()
Default constructer when called as cron job.

Method Detail

addAnalyzer

public void addAnalyzer(CmsSearchAnalyzer analyzer)
Adds an analyzer.

Parameters:
analyzer - an analyzer

addDocumentTypeConfig

public void addDocumentTypeConfig(CmsSearchDocumentType documentType)
Adds a document type.

Parameters:
documentType - a document type

addSearchIndex

public void addSearchIndex(CmsSearchIndex searchIndex)
Adds a search index configuration.

Parameters:
searchIndex - a search index configuration

addSearchIndexSource

public void addSearchIndexSource(CmsSearchIndexSource searchIndexSource)
Adds a search index source configuration.

Parameters:
searchIndexSource - a search index source configuration

cmsEvent

public void cmsEvent(CmsEvent event)
Implements the event listener of this class.

Specified by:
cmsEvent in interface I_CmsEventListener
Parameters:
event - CmsEvent that has occurred
See Also:
I_CmsEventListener.cmsEvent(org.opencms.main.CmsEvent)

getAnalyzers

public Map getAnalyzers()
Returns an unmodifiable view (read-only) of the Analyzers Map.

Returns:
an unmodifiable view (read-only) of the Analyzers Map

getCmsSearchAnalyzer

public CmsSearchAnalyzer getCmsSearchAnalyzer(String locale)
Returns the CmsSearchAnalyzer Object.

Parameters:
locale - unique locale key to specify the CmsSearchAnalyzer in HashMap
Returns:
the CmsSearchAnalyzer Object

getDirectory

public String getDirectory()
Returns the name of the directory below WEB-INF/ where the search indexes are stored.

Returns:
the name of the directory below WEB-INF/ where the search indexes are stored

getDocumentTypeConfig

public CmsSearchDocumentType getDocumentTypeConfig(String name)
Returns a document type config.

Parameters:
name - the name of the document type config
Returns:
the document type config.

getDocumentTypeConfigs

public Map getDocumentTypeConfigs()
Returns an unmodifiable view (read-only) of the DocumentTypeConfigs Map.

Returns:
an unmodifiable view (read-only) of the DocumentTypeConfigs Map

getHighlighter

public I_CmsTermHighlighter getHighlighter()
Returns the highlighter.

Returns:
the highlighter

getIndex

public CmsSearchIndex getIndex(String indexName)
Returns the index belonging to the passed name.

The index must exist already.

Parameters:
indexName - then name of the index
Returns:
an object representing the desired index

getIndexNames

public List getIndexNames()
Returns the names of all configured indexes.

Returns:
list of names

getIndexSource

public CmsSearchIndexSource getIndexSource(String sourceName)
Returns a search index source for a specified source name.

Parameters:
sourceName - the name of the index source
Returns:
a search index source

getMaxExcerptLength

public int getMaxExcerptLength()
Returns the max. excerpt length.

Returns:
the max excerpt length

getResultCacheSize

public String getResultCacheSize()
Returns the result cache size.

Returns:
the result cache size

getSearchIndexs

public List getSearchIndexs()
Returns an unmodifiable list of all configured indexes.

Returns:
unmodifiable list of configured indexes

getSearchIndexSources

public Map getSearchIndexSources()
Returns an unmodifiable view (read-only) of the SearchIndexSources Map.

Returns:
an unmodifiable view (read-only) of the SearchIndexSources Map

getTimeout

public String getTimeout()
Returns the timeout to abandon threads indexing a resource.

Returns:
the timeout to abandon threads indexing a resource

initialize

public void initialize(CmsObject cms)
Initializes the search manager.

Parameters:
cms - the cms object

launch

public final String launch(CmsObject cms,
                           Map parameters)
                    throws Exception
Method for automatically rebuilding indexes configured with auto.

Specified by:
launch in interface I_CmsScheduledJob
Parameters:
cms - the cms object
parameters - the parameters for the scheduled job
Returns:
the finish message
Throws:
Exception - if something goes wrong
See Also:
CmsScheduledJobInfo, CmsScheduledJobInfo.setReuseInstance(boolean)

setDirectory

public void setDirectory(String value)
Sets the name of the directory below WEB-INF/ where the search indexes are stored.

Parameters:
value - the name of the directory below WEB-INF/ where the search indexes are stored

setHighlighter

public void setHighlighter(String highlighter)
Sets the highlighter.

A highlighter is a class implementing org.opencms.search.documents.I_TermHighlighter.

Parameters:
highlighter - the package/class name of the highlighter

setMaxExcerptLength

public void setMaxExcerptLength(String maxExcerptLength)
Sets the max. excerpt length.

Parameters:
maxExcerptLength - the max. excerpt length to set

setResultCacheSize

public void setResultCacheSize(String value)
Sets the result cache size.

Parameters:
value - the result cache size

setTimeout

public void setTimeout(String value)
Sets the timeout to abandon threads indexing a resource.

Parameters:
value - the timeout in milliseconds

updateIndex

public void updateIndex(I_CmsReport report)
                 throws CmsException
Updates all configured indexes.

An index will be updated only if rebuild mode is set to auto.

Parameters:
report - the report object to write messages or null
Throws:
CmsException - if something goes wrong

updateIndex

public void updateIndex(I_CmsReport report,
                        boolean wait)
                 throws CmsException
Updates all configured indexes..

An index will be updated only if rebuild mode is set to auto.

Parameters:
report - the report object to write messages or null
wait - flag signals to wait until the indexing threads are finished
Throws:
CmsException - if something goes wrong

updateIndex

public void updateIndex(String indexName)
                 throws CmsException
Updates (if required creates) the index with the given name.

Parameters:
indexName - the name of the index to update
Throws:
CmsException - if something goes wrong

updateIndex

public void updateIndex(String indexName,
                        I_CmsReport report)
                 throws CmsException
Updates (if required creates) the index with the given name.

Parameters:
indexName - the name of the index to update
report - the report object to write messages or null
Throws:
CmsException - if something goes wrong

updateIndex

public void updateIndex(String indexName,
                        I_CmsReport report,
                        boolean wait)
                 throws CmsException
Updates (if required creates) the index with the given name.

Parameters:
indexName - the name of the index to update
report - the report object to write messages or null
wait - flag signals to wait until the indexing threads are finished or not
Throws:
CmsException - is something goes wrong

getAnalyzer

protected Analyzer getAnalyzer(String locale)
                        throws CmsIndexException
Returns an analyzer for the given language.

The analyzer is selected according to the analyzer configuration.

Parameters:
locale - a language id, i.e. de, en, it
Returns:
the appropriate lucene analyzer
Throws:
CmsIndexException - if something goes wrong

getDocumentFactory

protected I_CmsDocumentFactory getDocumentFactory(A_CmsIndexResource resource)
Returns a lucene document factory for given resource.

The type of the document factory is selected by the type of the resource and the mimetype of the resource content according to the documenttype configuration.

Parameters:
resource - a cms resource
Returns:
a lucene document factory or null

getDocumentTypes

protected List getDocumentTypes()
Returns the set of names of all configured documenttypes.

Returns:
the set of names of all configured documenttypes

getResultCache

protected Map getResultCache()
Returns the common cache for buffering search results.

Returns:
the cache

initAvailableDocumentTypes

protected void initAvailableDocumentTypes()
Initializes the available Cms resource types to be indexed.

A map stores document factories keyed by a string representing a colon separated list of Cms resource types and/or mimetypes.

The keys of this map are used to trigger a document factory to convert a Cms resource into a Lucene index document.

A document factory is a class implementing the interface I_CmsDocumentFactory.


initSearchIndexes

protected void initSearchIndexes()
Initializes the configured search indexes.

This initializes also the list of Cms resources types to be indexed by an index source.