Package org.opencms.search
Class A_CmsSearchIndex
java.lang.Object
org.opencms.search.A_CmsSearchIndex
- All Implemented Interfaces:
Serializable
,I_CmsConfigurationParameterHandler
,I_CmsSearchIndex
- Direct Known Subclasses:
CmsSearchIndex
Abstract base class for search indexes. It provides default implementations that should fit most use
cases when adding own index implementations.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Special value for the search.exclude property.static final String
Special value for the search.exclude property.static final String
The use all locale.Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD
Fields inherited from interface org.opencms.search.I_CmsSearchIndex
REBUILD_MODE_AUTO, REBUILD_MODE_MANUAL, REBUILD_MODE_NEVER, REBUILD_MODE_OFFLINE
-
Constructor Summary
ConstructorDescriptionDefault constructor only intended to be used by the XML configuration.A_CmsSearchIndex
(String name) Creates a new CmsSearchIndex with the given name. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addConfigurationParameter
(String key, String value) Adds a configuration parameter to this parameter configurable class instance.void
addSourceName
(String sourceName) Adds am index source to this search index.boolean
Checks is this index has been configured correctly.protected abstract I_CmsIndexWriter
createIndexWriter
(boolean create, I_CmsReport report) Creates a new index writer.boolean
boolean
excludeFromIndex
(CmsObject cms, CmsResource resource) Checks if the provided resource should be excluded from this search index.Returns the empty configuration.getContentIfUnchanged
(CmsResource resource) We always assume we have no unchanged copy of the content, since it depends on the concrete index.Returns the document type factory used for the given resource in this index, ornull
in case the resource is not indexed by this index.Returns the search field configuration of this index.Returns the name of the field configuration used for this index.getIndexWriter
(I_CmsReport report, boolean create) Returns a new index writer for this index.Returns the language locale of this index.getLocaleForResource
(CmsObject cms, CmsResource resource, List<Locale> availableLocales) Returns the language locale for the given resource in this index.getName()
Gets the name of this index.getPath()
Returns the path where this index stores it's data in the "real" file system.Gets the project of this index.Get the rebuild mode of this index.Returns all configured sources names of this search index.Returns all configured index sources of this search index.int
hashCode()
void
Initializes a configuration after all parameters have been added.void
Initializes the search index.boolean
Returnstrue
if this index is currently disabled.boolean
Returnstrue
if full text is extracted by this index.protected boolean
isIndexing
(CmsResource res) Checks if the given resource should be indexed by this index or not.boolean
Returns a flag, indicating if the search index is successfully initialized.boolean
Returns the languageDetection.boolean
Returnstrue
in case this index is updated incremental.void
onIndexChanged
(boolean force) Method called by the search manager if the index has changed.void
removeSourceName
(String sourceName) Removes an index source from this search index.void
setEnabled
(boolean enabled) Can be used to enable / disable this index.protected void
setExtractContent
(boolean extract) Sets a flag, indicating if the index should extract content.void
setFieldConfiguration
(I_CmsSearchFieldConfiguration fieldConfiguration) Sets the field configuration used for this index.void
setFieldConfigurationName
(String fieldConfigurationName) Sets the name of the field configuration used for this index.protected void
setIndexWriter
(I_CmsIndexWriter writer) Sets the index writer.void
setLanguageDetection
(boolean languageDetection) Sets the languageDetection.void
Sets the locale to index resources.void
setLocaleString
(String locale) Sets the locale to index resources as a String.void
Sets the logical key/name of this search index.void
Set the path to the index/core.void
setProject
(String project) Sets the name of the project used to index resources.void
setRebuildMode
(String rebuildMode) Sets the rebuild mode of this search index.void
shutDown()
Shuts down the search index.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.opencms.search.I_CmsSearchIndex
createEmptyDocument
-
Field Details
-
PROPERTY_SEARCH_EXCLUDE_VALUE_ALL
Special value for the search.exclude property.- See Also:
-
PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY
Special value for the search.exclude property.- See Also:
-
USE_ALL_LOCALE
The use all locale.- See Also:
-
-
Constructor Details
-
A_CmsSearchIndex
public A_CmsSearchIndex()Default constructor only intended to be used by the XML configuration.It is recommended to use the constructor
as it enforces the mandatory name argument.A_CmsSearchIndex(String)
-
A_CmsSearchIndex
Creates a new CmsSearchIndex with the given name.- Parameters:
name
- the system-wide unique name for the search index- Throws:
CmsIllegalArgumentException
- if the given name is null, empty or already taken by another search index
-
-
Method Details
-
addConfigurationParameter
Description copied from interface:I_CmsConfigurationParameterHandler
Adds a configuration parameter to this parameter configurable class instance.- Specified by:
addConfigurationParameter
in interfaceI_CmsConfigurationParameterHandler
- Parameters:
key
- the name of the parametervalue
- the value for the parameter- See Also:
-
addSourceName
Adds am index source to this search index.- Specified by:
addSourceName
in interfaceI_CmsSearchIndex
- Parameters:
sourceName
- the index source name to add
-
checkConfiguration
Description copied from interface:I_CmsSearchIndex
Checks is this index has been configured correctly.In case the check fails, the
enabled
property is set tofalse
- Specified by:
checkConfiguration
in interfaceI_CmsSearchIndex
- Parameters:
cms
- a OpenCms user context to perform the checks with (should have "Administrator" permissions)- Returns:
true
in case the index is correctly configured and enabled after the check- See Also:
-
equals
-
excludeFromIndex
Checks if the provided resource should be excluded from this search index.- Specified by:
excludeFromIndex
in interfaceI_CmsSearchIndex
- Parameters:
cms
- the OpenCms context used for building the search indexresource
- the resource to index- Returns:
- true if the resource should be excluded, false if it should be included in this index
-
getConfiguration
Returns the empty configuration. Override the method if your index is configurable.- Specified by:
getConfiguration
in interfaceI_CmsConfigurationParameterHandler
- Returns:
- the parameters of this configurable class instance,
or
null
if the class does not need any parameters - See Also:
-
getContentIfUnchanged
We always assume we have no unchanged copy of the content, since it depends on the concrete index. Override the method to enhance indexing performance if you know where to grap the content from your index. See the implementationCmsSearchIndex.getContentIfUnchanged(CmsResource)
for an example.- Specified by:
getContentIfUnchanged
in interfaceI_CmsSearchIndex
- Parameters:
resource
- the resource the content should be provided for.- Returns:
- the up-to-date extraction result as gained from the index - if possible, or
null
, if no up-to-date extraction result can be obtained from the index. - See Also:
-
getDocumentFactory
Returns the document type factory used for the given resource in this index, ornull
in case the resource is not indexed by this index.A resource is indexed if the following is all true:
- The index contains at last one index source matching the root path of the given resource.
- For this matching index source, the document type factory needed by the resource is also configured.
- Specified by:
getDocumentFactory
in interfaceI_CmsSearchIndex
- Parameters:
res
- the resource to check- Returns:
- the document type factory used for the given resource in this index, or
null
in case the resource is not indexed by this index
-
getFieldConfiguration
Description copied from interface:I_CmsSearchIndex
Returns the search field configuration of this index.- Specified by:
getFieldConfiguration
in interfaceI_CmsSearchIndex
- Returns:
- the search field configuration of this index
- See Also:
-
getFieldConfigurationName
Description copied from interface:I_CmsSearchIndex
Returns the name of the field configuration used for this index.- Specified by:
getFieldConfigurationName
in interfaceI_CmsSearchIndex
- Returns:
- the name of the field configuration used for this index
- See Also:
-
getIndexWriter
Returns a new index writer for this index.- Specified by:
getIndexWriter
in interfaceI_CmsSearchIndex
- Parameters:
report
- the report to write error messages oncreate
- iftrue
a whole new index is created, iffalse
an existing index is updated- Returns:
- a new instance of IndexWriter
- Throws:
CmsIndexException
- if the index can not be opened
-
getLocale
Returns the language locale of this index.- Specified by:
getLocale
in interfaceI_CmsSearchIndex
- Returns:
- the language locale of this index, for example "en"
-
getLocaleForResource
public Locale getLocaleForResource(CmsObject cms, CmsResource resource, List<Locale> availableLocales) Returns the language locale for the given resource in this index.- Specified by:
getLocaleForResource
in interfaceI_CmsSearchIndex
- Parameters:
cms
- the current OpenCms user contextresource
- the resource to checkavailableLocales
- a list of locales supported by the resource- Returns:
- the language locale for the given resource in this index
-
getName
Description copied from interface:I_CmsSearchIndex
Gets the name of this index.- Specified by:
getName
in interfaceI_CmsSearchIndex
- Returns:
- the name of the index
- See Also:
-
getPath
Description copied from interface:I_CmsSearchIndex
Returns the path where this index stores it's data in the "real" file system.- Specified by:
getPath
in interfaceI_CmsSearchIndex
- Returns:
- the path where this index stores it's data in the "real" file system
- See Also:
-
getProject
Description copied from interface:I_CmsSearchIndex
Gets the project of this index.- Specified by:
getProject
in interfaceI_CmsSearchIndex
- Returns:
- the project of the index, i.e. "online"
- See Also:
-
getRebuildMode
Description copied from interface:I_CmsSearchIndex
Get the rebuild mode of this index.- Specified by:
getRebuildMode
in interfaceI_CmsSearchIndex
- Returns:
- the current rebuild mode
- See Also:
-
getSourceNames
Description copied from interface:I_CmsSearchIndex
Returns all configured sources names of this search index.- Specified by:
getSourceNames
in interfaceI_CmsSearchIndex
- Returns:
- a list with all configured sources names of this search index
- See Also:
-
getSources
Description copied from interface:I_CmsSearchIndex
Returns all configured index sources of this search index.- Specified by:
getSources
in interfaceI_CmsSearchIndex
- Returns:
- all configured index sources of this search index
- See Also:
-
hashCode
-
initConfiguration
Description copied from interface:I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.- Specified by:
initConfiguration
in interfaceI_CmsConfigurationParameterHandler
- See Also:
-
initialize
Initializes the search index.- Specified by:
initialize
in interfaceI_CmsSearchIndex
- Throws:
CmsSearchException
- if the index source association failed or a configuration error occurred
-
isEnabled
Description copied from interface:I_CmsSearchIndex
Returnstrue
if this index is currently disabled.- Specified by:
isEnabled
in interfaceI_CmsSearchIndex
- Returns:
true
if this index is currently disabled- See Also:
-
isExtractingContent
Description copied from interface:I_CmsSearchIndex
Returnstrue
if full text is extracted by this index.Full text content extraction can be turned off in the index search configuration parameters in
opencms-search.xml
. Not extraction the full text information will highly improve performance.- Specified by:
isExtractingContent
in interfaceI_CmsSearchIndex
- Returns:
true
if full text is extracted by this index- See Also:
-
isInitialized
Description copied from interface:I_CmsSearchIndex
Returns a flag, indicating if the search index is successfully initialized.- Specified by:
isInitialized
in interfaceI_CmsSearchIndex
- Returns:
- a flag, indicating if the search index is successfully initialized.
- See Also:
-
isLanguageDetection
Description copied from interface:I_CmsSearchIndex
Returns the languageDetection.- Specified by:
isLanguageDetection
in interfaceI_CmsSearchIndex
- Returns:
- the languageDetection
- See Also:
-
isUpdatedIncremental
Returnstrue
in case this index is updated incremental.An index is updated incremental if the index rebuild mode as defined by
getRebuildMode()
is either set to "auto" or "offline". Moreover, at least one update must have been written to the index already.- Specified by:
isUpdatedIncremental
in interfaceI_CmsSearchIndex
- Returns:
true
in case this index is updated incremental
-
onIndexChanged
Description copied from interface:I_CmsSearchIndex
Method called by the search manager if the index has changed. Typically the index searcher is reset when the method is called.- Specified by:
onIndexChanged
in interfaceI_CmsSearchIndex
- Parameters:
force
- iffalse
the index might decide itself it it has to act on the change, iftrue
it should act, even if itself cannot detect an index change.- See Also:
-
removeSourceName
Description copied from interface:I_CmsSearchIndex
Removes an index source from this search index.- Specified by:
removeSourceName
in interfaceI_CmsSearchIndex
- Parameters:
sourceName
- the index source name to remove- See Also:
-
setEnabled
Description copied from interface:I_CmsSearchIndex
Can be used to enable / disable this index.- Specified by:
setEnabled
in interfaceI_CmsSearchIndex
- Parameters:
enabled
- the state of the index to set- See Also:
-
setFieldConfiguration
Sets the field configuration used for this index.- Parameters:
fieldConfiguration
- the field configuration to set
-
setFieldConfigurationName
Sets the name of the field configuration used for this index.- Specified by:
setFieldConfigurationName
in interfaceI_CmsSearchIndex
- Parameters:
fieldConfigurationName
- the name of the field configuration to set
-
setLanguageDetection
Sets the languageDetection.- Parameters:
languageDetection
- the languageDetection to set
-
setLocale
Description copied from interface:I_CmsSearchIndex
Sets the locale to index resources.- Specified by:
setLocale
in interfaceI_CmsSearchIndex
- Parameters:
locale
- the locale to index resources- See Also:
-
setLocaleString
Description copied from interface:I_CmsSearchIndex
Sets the locale to index resources as a String.- Specified by:
setLocaleString
in interfaceI_CmsSearchIndex
- Parameters:
locale
- the locale to index resources- See Also:
-
setName
Description copied from interface:I_CmsSearchIndex
Sets the logical key/name of this search index.- Specified by:
setName
in interfaceI_CmsSearchIndex
- Parameters:
name
- the logical key/name of this search index- Throws:
CmsIllegalArgumentException
- if the given name is null, empty or already taken by another search index- See Also:
-
setPath
Set the path to the index/core. This can either be the path to the directory where the index is stored or the URL where the index/core is reached.- Parameters:
path
- to the index/core.
-
setProject
Description copied from interface:I_CmsSearchIndex
Sets the name of the project used to index resources.- Specified by:
setProject
in interfaceI_CmsSearchIndex
- Parameters:
project
- the name of the project used to index resources- See Also:
-
setRebuildMode
Description copied from interface:I_CmsSearchIndex
Sets the rebuild mode of this search index.- Specified by:
setRebuildMode
in interfaceI_CmsSearchIndex
- Parameters:
rebuildMode
- the rebuild mode of this search index {auto|manual}- See Also:
-
shutDown
Description copied from interface:I_CmsSearchIndex
Shuts down the search index.This will close the local Lucene index searcher instance.
- Specified by:
shutDown
in interfaceI_CmsSearchIndex
- See Also:
-
createIndexWriter
protected abstract I_CmsIndexWriter createIndexWriter(boolean create, I_CmsReport report) throws CmsIndexException Creates a new index writer.- Parameters:
create
- iftrue
a whole new index is created, iffalse
an existing index is updatedreport
- the report- Returns:
- the created new index writer
- Throws:
CmsIndexException
- in case the writer could not be created- See Also:
-
isIndexing
Checks if the given resource should be indexed by this index or not.- Parameters:
res
- the resource candidate- Returns:
true
if the given resource should be indexed orfalse
if not
-
setExtractContent
Sets a flag, indicating if the index should extract content.- Parameters:
extract
- a flag, indicating if the index should extract content.
-
setIndexWriter
Sets the index writer.- Parameters:
writer
- the index writer to set
-