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
FieldsModifier and TypeFieldDescriptionstatic final StringSpecial value for the search.exclude property.static final StringSpecial value for the search.exclude property.static final StringThe use all locale.Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHODFields inherited from interface org.opencms.search.I_CmsSearchIndex
REBUILD_MODE_AUTO, REBUILD_MODE_MANUAL, REBUILD_MODE_NEVER, REBUILD_MODE_OFFLINE -
Constructor Summary
ConstructorsConstructorDescriptionDefault 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 TypeMethodDescriptionvoidaddConfigurationParameter(String key, String value) Adds a configuration parameter to this parameter configurable class instance.voidaddSourceName(String sourceName) Adds am index source to this search index.booleanChecks is this index has been configured correctly.protected abstract I_CmsIndexWritercreateIndexWriter(boolean create, I_CmsReport report) Creates a new index writer.booleanbooleanexcludeFromIndex(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, ornullin 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.inthashCode()voidInitializes a configuration after all parameters have been added.voidInitializes the search index.booleanReturnstrueif this index is currently disabled.booleanReturnstrueif full text is extracted by this index.protected booleanisIndexing(CmsResource res) Checks if the given resource should be indexed by this index or not.booleanReturns a flag, indicating if the search index is successfully initialized.booleanReturns the languageDetection.booleanReturnstruein case this index is updated incremental.voidonIndexChanged(boolean force) Method called by the search manager if the index has changed.voidremoveSourceName(String sourceName) Removes an index source from this search index.voidsetEnabled(boolean enabled) Can be used to enable / disable this index.protected voidsetExtractContent(boolean extract) Sets a flag, indicating if the index should extract content.voidsetFieldConfiguration(I_CmsSearchFieldConfiguration fieldConfiguration) Sets the field configuration used for this index.voidsetFieldConfigurationName(String fieldConfigurationName) Sets the name of the field configuration used for this index.protected voidsetIndexWriter(I_CmsIndexWriter writer) Sets the index writer.voidsetLanguageDetection(boolean languageDetection) Sets the languageDetection.voidSets the locale to index resources.voidsetLocaleString(String locale) Sets the locale to index resources as a String.voidSets the logical key/name of this search index.voidSet the path to the index/core.voidsetProject(String project) Sets the name of the project used to index resources.voidsetRebuildMode(String rebuildMode) Sets the rebuild mode of this search index.voidshutDown()Shuts down the search index.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods 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_CmsConfigurationParameterHandlerAdds a configuration parameter to this parameter configurable class instance.- Specified by:
addConfigurationParameterin 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:
addSourceNamein interfaceI_CmsSearchIndex- Parameters:
sourceName- the index source name to add
-
checkConfiguration
Description copied from interface:I_CmsSearchIndexChecks is this index has been configured correctly.In case the check fails, the
enabledproperty is set tofalse- Specified by:
checkConfigurationin interfaceI_CmsSearchIndex- Parameters:
cms- a OpenCms user context to perform the checks with (should have "Administrator" permissions)- Returns:
truein 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:
excludeFromIndexin 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:
getConfigurationin interfaceI_CmsConfigurationParameterHandler- Returns:
- the parameters of this configurable class instance,
or
nullif 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:
getContentIfUnchangedin 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, ornullin 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:
getDocumentFactoryin interfaceI_CmsSearchIndex- Parameters:
res- the resource to check- Returns:
- the document type factory used for the given resource in this index, or
nullin case the resource is not indexed by this index
-
getFieldConfiguration
Description copied from interface:I_CmsSearchIndexReturns the search field configuration of this index.- Specified by:
getFieldConfigurationin interfaceI_CmsSearchIndex- Returns:
- the search field configuration of this index
- See Also:
-
getFieldConfigurationName
Description copied from interface:I_CmsSearchIndexReturns the name of the field configuration used for this index.- Specified by:
getFieldConfigurationNamein 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:
getIndexWriterin interfaceI_CmsSearchIndex- Parameters:
report- the report to write error messages oncreate- iftruea whole new index is created, iffalsean 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:
getLocalein 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:
getLocaleForResourcein 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_CmsSearchIndexGets the name of this index.- Specified by:
getNamein interfaceI_CmsSearchIndex- Returns:
- the name of the index
- See Also:
-
getPath
Description copied from interface:I_CmsSearchIndexReturns the path where this index stores it's data in the "real" file system.- Specified by:
getPathin 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_CmsSearchIndexGets the project of this index.- Specified by:
getProjectin interfaceI_CmsSearchIndex- Returns:
- the project of the index, i.e. "online"
- See Also:
-
getRebuildMode
Description copied from interface:I_CmsSearchIndexGet the rebuild mode of this index.- Specified by:
getRebuildModein interfaceI_CmsSearchIndex- Returns:
- the current rebuild mode
- See Also:
-
getSourceNames
Description copied from interface:I_CmsSearchIndexReturns all configured sources names of this search index.- Specified by:
getSourceNamesin interfaceI_CmsSearchIndex- Returns:
- a list with all configured sources names of this search index
- See Also:
-
getSources
Description copied from interface:I_CmsSearchIndexReturns all configured index sources of this search index.- Specified by:
getSourcesin interfaceI_CmsSearchIndex- Returns:
- all configured index sources of this search index
- See Also:
-
hashCode
-
initConfiguration
Description copied from interface:I_CmsConfigurationParameterHandlerInitializes a configuration after all parameters have been added.- Specified by:
initConfigurationin interfaceI_CmsConfigurationParameterHandler- See Also:
-
initialize
Initializes the search index.- Specified by:
initializein interfaceI_CmsSearchIndex- Throws:
CmsSearchException- if the index source association failed or a configuration error occurred
-
isEnabled
Description copied from interface:I_CmsSearchIndexReturnstrueif this index is currently disabled.- Specified by:
isEnabledin interfaceI_CmsSearchIndex- Returns:
trueif this index is currently disabled- See Also:
-
isExtractingContent
Description copied from interface:I_CmsSearchIndexReturnstrueif 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:
isExtractingContentin interfaceI_CmsSearchIndex- Returns:
trueif full text is extracted by this index- See Also:
-
isInitialized
Description copied from interface:I_CmsSearchIndexReturns a flag, indicating if the search index is successfully initialized.- Specified by:
isInitializedin interfaceI_CmsSearchIndex- Returns:
- a flag, indicating if the search index is successfully initialized.
- See Also:
-
isLanguageDetection
Description copied from interface:I_CmsSearchIndexReturns the languageDetection.- Specified by:
isLanguageDetectionin interfaceI_CmsSearchIndex- Returns:
- the languageDetection
- See Also:
-
isUpdatedIncremental
Returnstruein 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:
isUpdatedIncrementalin interfaceI_CmsSearchIndex- Returns:
truein case this index is updated incremental
-
onIndexChanged
Description copied from interface:I_CmsSearchIndexMethod called by the search manager if the index has changed. Typically the index searcher is reset when the method is called.- Specified by:
onIndexChangedin interfaceI_CmsSearchIndex- Parameters:
force- iffalsethe index might decide itself it it has to act on the change, iftrueit should act, even if itself cannot detect an index change.- See Also:
-
removeSourceName
Description copied from interface:I_CmsSearchIndexRemoves an index source from this search index.- Specified by:
removeSourceNamein interfaceI_CmsSearchIndex- Parameters:
sourceName- the index source name to remove- See Also:
-
setEnabled
Description copied from interface:I_CmsSearchIndexCan be used to enable / disable this index.- Specified by:
setEnabledin 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:
setFieldConfigurationNamein 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_CmsSearchIndexSets the locale to index resources.- Specified by:
setLocalein interfaceI_CmsSearchIndex- Parameters:
locale- the locale to index resources- See Also:
-
setLocaleString
Description copied from interface:I_CmsSearchIndexSets the locale to index resources as a String.- Specified by:
setLocaleStringin interfaceI_CmsSearchIndex- Parameters:
locale- the locale to index resources- See Also:
-
setName
Description copied from interface:I_CmsSearchIndexSets the logical key/name of this search index.- Specified by:
setNamein 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_CmsSearchIndexSets the name of the project used to index resources.- Specified by:
setProjectin interfaceI_CmsSearchIndex- Parameters:
project- the name of the project used to index resources- See Also:
-
setRebuildMode
Description copied from interface:I_CmsSearchIndexSets the rebuild mode of this search index.- Specified by:
setRebuildModein interfaceI_CmsSearchIndex- Parameters:
rebuildMode- the rebuild mode of this search index {auto|manual}- See Also:
-
shutDown
Description copied from interface:I_CmsSearchIndexShuts down the search index.This will close the local Lucene index searcher instance.
- Specified by:
shutDownin interfaceI_CmsSearchIndex- See Also:
-
createIndexWriter
protected abstract I_CmsIndexWriter createIndexWriter(boolean create, I_CmsReport report) throws CmsIndexException Creates a new index writer.- Parameters:
create- iftruea whole new index is created, iffalsean 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:
trueif the given resource should be indexed orfalseif 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
-