Package org.opencms.search
Class A_CmsSearchIndex
- java.lang.Object
-
- org.opencms.search.A_CmsSearchIndex
-
- All Implemented Interfaces:
java.io.Serializable
,I_CmsConfigurationParameterHandler
,I_CmsSearchIndex
- Direct Known Subclasses:
CmsSearchIndex
public abstract class A_CmsSearchIndex extends java.lang.Object implements I_CmsSearchIndex
Abstract base class for search indexes. It provides default implementations that should fit most use cases when adding own index implementations.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROPERTY_SEARCH_EXCLUDE_VALUE_ALL
Special value for the search.exclude property.static java.lang.String
PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY
Special value for the search.exclude property.static java.lang.String
USE_ALL_LOCALE
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
Constructors Constructor Description A_CmsSearchIndex()
Default constructor only intended to be used by the XML configuration.A_CmsSearchIndex(java.lang.String name)
Creates a new CmsSearchIndex with the given name.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addConfigurationParameter(java.lang.String key, java.lang.String value)
Adds a configuration parameter to this parameter configurable class instance.void
addSourceName(java.lang.String sourceName)
Adds am index source to this search index.boolean
checkConfiguration(CmsObject cms)
Checks is this index has been configured correctly.protected abstract I_CmsIndexWriter
createIndexWriter(boolean create, I_CmsReport report)
Creates a new index writer.boolean
equals(java.lang.Object obj)
boolean
excludeFromIndex(CmsObject cms, CmsResource resource)
Checks if the provided resource should be excluded from this search index.CmsParameterConfiguration
getConfiguration()
Returns the empty configuration.I_CmsExtractionResult
getContentIfUnchanged(CmsResource resource)
We always assume we have no unchanged copy of the content, since it depends on the concrete index.I_CmsDocumentFactory
getDocumentFactory(CmsResource res)
Returns the document type factory used for the given resource in this index, ornull
in case the resource is not indexed by this index.I_CmsSearchFieldConfiguration
getFieldConfiguration()
Returns the search field configuration of this index.java.lang.String
getFieldConfigurationName()
Returns the name of the field configuration used for this index.I_CmsIndexWriter
getIndexWriter(I_CmsReport report, boolean create)
Returns a new index writer for this index.java.util.Locale
getLocale()
Returns the language locale of this index.java.util.Locale
getLocaleForResource(CmsObject cms, CmsResource resource, java.util.List<java.util.Locale> availableLocales)
Returns the language locale for the given resource in this index.java.lang.String
getName()
Gets the name of this index.java.lang.String
getPath()
Returns the path where this index stores it's data in the "real" file system.java.lang.String
getProject()
Gets the project of this index.java.lang.String
getRebuildMode()
Get the rebuild mode of this index.java.util.List<java.lang.String>
getSourceNames()
Returns all configured sources names of this search index.java.util.List<CmsSearchIndexSource>
getSources()
Returns all configured index sources of this search index.int
hashCode()
void
initConfiguration()
Initializes a configuration after all parameters have been added.void
initialize()
Initializes the search index.boolean
isEnabled()
Returnstrue
if this index is currently disabled.boolean
isExtractingContent()
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
isInitialized()
Returns a flag, indicating if the search index is successfully initialized.boolean
isLanguageDetection()
Returns the languageDetection.boolean
isUpdatedIncremental()
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(java.lang.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(java.lang.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
setLocale(java.util.Locale locale)
Sets the locale to index resources.void
setLocaleString(java.lang.String locale)
Sets the locale to index resources as a String.void
setName(java.lang.String name)
Sets the logical key/name of this search index.void
setPath(java.lang.String path)
Set the path to the index/core.void
setProject(java.lang.String project)
Sets the name of the project used to index resources.void
setRebuildMode(java.lang.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 Detail
-
PROPERTY_SEARCH_EXCLUDE_VALUE_ALL
public static final java.lang.String PROPERTY_SEARCH_EXCLUDE_VALUE_ALL
Special value for the search.exclude property.- See Also:
- Constant Field Values
-
PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY
public static final java.lang.String PROPERTY_SEARCH_EXCLUDE_VALUE_GALLERY
Special value for the search.exclude property.- See Also:
- Constant Field Values
-
USE_ALL_LOCALE
public static final java.lang.String USE_ALL_LOCALE
The use all locale.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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
public A_CmsSearchIndex(java.lang.String name) throws CmsIllegalArgumentException
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 Detail
-
addConfigurationParameter
public void addConfigurationParameter(java.lang.String key, java.lang.String value)
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:
I_CmsConfigurationParameterHandler.addConfigurationParameter(java.lang.String, java.lang.String)
-
addSourceName
public void addSourceName(java.lang.String sourceName)
Adds am index source to this search index.- Specified by:
addSourceName
in interfaceI_CmsSearchIndex
- Parameters:
sourceName
- the index source name to add
-
checkConfiguration
public boolean checkConfiguration(CmsObject cms)
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:
I_CmsSearchIndex.checkConfiguration(org.opencms.file.CmsObject)
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
- See Also:
Object.equals(java.lang.Object)
-
excludeFromIndex
public boolean excludeFromIndex(CmsObject cms, CmsResource resource)
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
public CmsParameterConfiguration 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:
I_CmsConfigurationParameterHandler.getConfiguration()
-
getContentIfUnchanged
public I_CmsExtractionResult getContentIfUnchanged(CmsResource resource)
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:
I_CmsSearchIndex.getContentIfUnchanged(org.opencms.file.CmsResource)
-
getDocumentFactory
public I_CmsDocumentFactory getDocumentFactory(CmsResource res)
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
public I_CmsSearchFieldConfiguration 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:
I_CmsSearchIndex.getFieldConfiguration()
-
getFieldConfigurationName
public java.lang.String 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:
I_CmsSearchIndex.getFieldConfigurationName()
-
getIndexWriter
public I_CmsIndexWriter getIndexWriter(I_CmsReport report, boolean create) throws CmsIndexException
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
public java.util.Locale 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 java.util.Locale getLocaleForResource(CmsObject cms, CmsResource resource, java.util.List<java.util.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
public java.lang.String 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:
I_CmsSearchIndex.getName()
-
getPath
public java.lang.String 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:
I_CmsSearchIndex.getPath()
-
getProject
public java.lang.String 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:
I_CmsSearchIndex.getProject()
-
getRebuildMode
public java.lang.String 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:
I_CmsSearchIndex.getRebuildMode()
-
getSourceNames
public java.util.List<java.lang.String> 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:
I_CmsSearchIndex.getSourceNames()
-
getSources
public java.util.List<CmsSearchIndexSource> 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:
I_CmsSearchIndex.getSources()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- See Also:
Object.hashCode()
-
initConfiguration
public void initConfiguration()
Description copied from interface:I_CmsConfigurationParameterHandler
Initializes a configuration after all parameters have been added.- Specified by:
initConfiguration
in interfaceI_CmsConfigurationParameterHandler
- See Also:
I_CmsConfigurationParameterHandler.initConfiguration()
-
initialize
public void initialize() throws CmsSearchException
Initializes the search index.- Specified by:
initialize
in interfaceI_CmsSearchIndex
- Throws:
CmsSearchException
- if the index source association failed or a configuration error occurred
-
isEnabled
public boolean 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:
I_CmsSearchIndex.isEnabled()
-
isExtractingContent
public boolean 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:
I_CmsSearchIndex.isExtractingContent()
-
isInitialized
public boolean 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:
I_CmsSearchIndex.isInitialized()
-
isLanguageDetection
public boolean isLanguageDetection()
Description copied from interface:I_CmsSearchIndex
Returns the languageDetection.- Specified by:
isLanguageDetection
in interfaceI_CmsSearchIndex
- Returns:
- the languageDetection
- See Also:
I_CmsSearchIndex.isLanguageDetection()
-
isUpdatedIncremental
public boolean 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
public void onIndexChanged(boolean force)
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:
I_CmsSearchIndex.onIndexChanged(boolean)
-
removeSourceName
public void removeSourceName(java.lang.String sourceName)
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:
I_CmsSearchIndex.removeSourceName(String)
-
setEnabled
public void setEnabled(boolean enabled)
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:
I_CmsSearchIndex.setEnabled(boolean)
-
setFieldConfiguration
public void setFieldConfiguration(I_CmsSearchFieldConfiguration fieldConfiguration)
Sets the field configuration used for this index.- Parameters:
fieldConfiguration
- the field configuration to set
-
setFieldConfigurationName
public void setFieldConfigurationName(java.lang.String fieldConfigurationName)
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
public void setLanguageDetection(boolean languageDetection)
Sets the languageDetection.- Parameters:
languageDetection
- the languageDetection to set
-
setLocale
public void setLocale(java.util.Locale locale)
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:
I_CmsSearchIndex.setLocale(java.util.Locale)
-
setLocaleString
public void setLocaleString(java.lang.String locale)
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:
I_CmsSearchIndex.setLocaleString(java.lang.String)
-
setName
public void setName(java.lang.String name) throws CmsIllegalArgumentException
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:
I_CmsSearchIndex.setName(java.lang.String)
-
setPath
public void setPath(java.lang.String path)
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
public void setProject(java.lang.String project)
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:
I_CmsSearchIndex.setProject(java.lang.String)
-
setRebuildMode
public void setRebuildMode(java.lang.String rebuildMode)
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:
I_CmsSearchIndex.setRebuildMode(java.lang.String)
-
shutDown
public void 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:
I_CmsSearchIndex.shutDown()
-
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:
getIndexWriter(I_CmsReport, boolean)
-
isIndexing
protected boolean isIndexing(CmsResource res)
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
protected void setExtractContent(boolean extract)
Sets a flag, indicating if the index should extract content.- Parameters:
extract
- a flag, indicating if the index should extract content.
-
setIndexWriter
protected void setIndexWriter(I_CmsIndexWriter writer)
Sets the index writer.- Parameters:
writer
- the index writer to set
-
-