|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.opencms.search.CmsSearchIndex
Implements the search within an index and the management of the index configuration.
Field Summary | |
static java.lang.String |
EXCERPT
Constant for additional param to enable excerpt creation (default: true). |
static java.lang.String |
PERMISSIONS
Constant for additional param to enable permission checks (default: true). |
static java.lang.String |
PRIORITY
Constant for additional param to set the thread priority during search. |
static java.lang.String |
REBUILD_MODE_AUTO
Automatic ("auto") index rebuild mode. |
static java.lang.String |
REBUILD_MODE_MANUAL
Manual ("manual") index rebuild mode. |
static java.lang.String |
ROOT_PATH_SUFFIX
Deprecated. This is not longer requires since OpenCms version 7.0.2, since the implementation of CmsSearchManager.getAnalyzer(Locale) was modified to use always
use for the CmsSearchField.FIELD_ROOT filed. |
static java.lang.String |
ROOT_PATH_TOKEN
Special root path start token for optimized path queries. |
Fields inherited from interface org.opencms.configuration.I_CmsConfigurationParameterHandler |
ADD_PARAMETER_METHOD, INIT_CONFIGURATION_METHOD |
Constructor Summary | |
CmsSearchIndex()
Default constructor only intended to be used by the xml configuration. |
|
CmsSearchIndex(java.lang.String name)
Creates a new CmsSearchIndex with the given name. |
Method Summary | |
void |
addConfigurationParameter(java.lang.String key,
java.lang.String value)
Adds a parameter. |
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. |
boolean |
equals(java.lang.Object obj)
|
java.util.Map |
getConfiguration()
Returns the configuration of this parameter configurable class instance, or null if the class does not need to be configured. |
I_CmsDocumentFactory |
getDocumentFactory(CmsResource res)
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. |
java.util.List |
getDocumenttypes(java.lang.String path)
Deprecated. use getDocumentFactory(CmsResource) instead to find out if this index is 'interested' in a resource |
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. |
org.apache.lucene.index.IndexWriter |
getIndexWriter(boolean create)
Returns a new index writer for this index. |
java.util.Locale |
getLocale()
Gets the langauge of this index. |
java.lang.String |
getLocaleString()
Returns the locale of the index as a String. |
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 |
getSourceNames()
Returns all configured sources names of this search index. |
java.util.List |
getSources()
Returns all configured index sources of this search index. |
int |
hashCode()
|
protected boolean |
hasReadPermission(CmsObject cms,
org.apache.lucene.document.Document doc)
Checks if the OpenCms resource referenced by the result document can be read be the user of the given OpenCms context. |
void |
initConfiguration()
Initializes a configuration after all parameters have been added. |
void |
initialize()
Initializes the search index. |
boolean |
isEnabled()
Returns true if this index is currently disabled. |
protected boolean |
isInTimeRange(org.apache.lucene.document.Document doc,
CmsSearchParameters params)
Checks wether the document is in the time range specified in the search parameters. |
void |
removeSourceName(java.lang.String sourceName)
Removes an index source from this search index. |
static java.lang.String |
rootPathRewrite(java.lang.String path)
Rewrites the a resource path for use in the CmsSearchField.FIELD_ROOT field. |
static java.lang.String[] |
rootPathSplit(java.lang.String path)
Spits the a resource path into tokens for use in the field
and with the method. |
CmsSearchResultList |
search(CmsObject cms,
CmsSearchParameters params)
Performs a search on the index within the given fields. |
void |
setEnabled(boolean enabled)
Can be used to enable / disable this index. |
void |
setFieldConfiguration(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. |
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 |
setProject(java.lang.String projectName)
Sets the name of the project used to index resources. |
void |
setProjectName(java.lang.String projectName)
Sets the name of the project used to index resources. |
void |
setRebuildMode(java.lang.String rebuildMode)
Sets the rebuild mode of this search index. |
java.lang.String |
toString()
Returns the name ( ) of this search index. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String EXCERPT
public static final java.lang.String PERMISSIONS
public static final java.lang.String PRIORITY
public static final java.lang.String REBUILD_MODE_AUTO
public static final java.lang.String REBUILD_MODE_MANUAL
public static final java.lang.String ROOT_PATH_SUFFIX
CmsSearchManager.getAnalyzer(Locale)
was modified to use always
use for the CmsSearchField.FIELD_ROOT
filed.
rootPathRewrite(String)
,
Constant Field Valuespublic static final java.lang.String ROOT_PATH_TOKEN
Constructor Detail |
public CmsSearchIndex()
It is recommended to use the constructor
as it enforces the mandatory name argument. CmsSearchIndex(String)
public CmsSearchIndex(java.lang.String name) throws CmsIllegalArgumentException
name
- the system-wide unique name for the search index
CmsIllegalArgumentException
- if the given name is null, empty or already taken
by another search index.Method Detail |
public static java.lang.String rootPathRewrite(java.lang.String path)
CmsSearchField.FIELD_ROOT
field.This is required in order to use a Lucene "phrase query" on the resource path. Using a phrase query is much, much better for the search performance then using a straightforward "prefix query". With a "prefix query", Lucene would interally generate a huge list of boolean sub-queries, exactly one for every document in the VFS subtree of the query. So if you query on "/sites/default/*" on a large OpenCms installation, this means thousands of sub-queries. Using the "phrase query", only one (or very few) queries are internally generated, and the result is just the same.
Since OpenCms version 7.0.2, the CmsSearchField.FIELD_ROOT
field always uses a whitespace analyzer.
This is ensured by the CmsSearchManager.getAnalyzer(Locale)
implementation.
The Lucene whitespace analyzer uses all words as tokens, no lower case transformation or word stemming is done.
So the root path is now just split along the '/' chars, which are replaced by simple space chars.
Historical implementation sidenote:
Before 7.0.2, the CmsSearchField.FIELD_ROOT
used the analyzer configured by the language.
This introduced a number of issues as the language analyzer might modify the directory names, leading to potential
duplicates (e.g. members/
and member/
may both be trimmed to member
),
so that the prefix search returns more or different results then expected.
This was avoided by a workaround where this method basically replaced the "/" of a path with "@o.c ".
Using this trick most Lucene analyzers left the directory names untouched,
and treated them like literal email addresses. However, this trick did not work with all analyzers,
for example the Russian analyzer does not work as expected.
An additional workaround was required to avoid problems with folders that that are different
only by the upper / lower chars. Since 7.0.2, these workarounds are not longer required, since the
CmsSearchField.FIELD_ROOT
field always uses a whitespace analyzer, which is a much better solution.
path
- the path to rewrite
public static java.lang.String[] rootPathSplit(java.lang.String path)
CmsSearchField.FIELD_ROOT
field
and with the rootPathRewrite(String)
method.
path
- the path to split
rootPathRewrite(String)
public void addConfigurationParameter(java.lang.String key, java.lang.String value)
addConfigurationParameter
in interface I_CmsConfigurationParameterHandler
key
- the key/name of the parametervalue
- the value of the parameterpublic void addSourceName(java.lang.String sourceName)
sourceName
- the index source name to addpublic boolean checkConfiguration(CmsObject cms)
In case the check fails, the enabled
property
is set to false
cms
- a OpenCms user context to perform the checks with (should have "Administrator" permissions)
true
in case the index is correctly configured and enabled after the checkisEnabled()
public boolean equals(java.lang.Object obj)
Object.equals(java.lang.Object)
public java.util.Map getConfiguration()
I_CmsConfigurationParameterHandler
null
if the class does not need to be configured.
All elements in the configuration are key, value String pairs,
set using the I_CmsConfigurationParameterHandler.addConfigurationParameter(String, String)
method
during initialization of the loader.
Implementations will (should) not to return a direct reference to the internal configuration but just a copy of it, to avoid unwanted external manipulation.
getConfiguration
in interface I_CmsConfigurationParameterHandler
null
I_CmsConfigurationParameterHandler.getConfiguration()
public I_CmsDocumentFactory getDocumentFactory(CmsResource res)
null
in case the resource is not indexed by this index.A resource is indexed if the following is all true:
res
- the resource to check
null
in case the resource is not indexed by this indexpublic java.util.List getDocumenttypes(java.lang.String path)
getDocumentFactory(CmsResource)
instead to find out if this index is 'interested' in a resource
path
- path of the folder
public CmsSearchFieldConfiguration getFieldConfiguration()
public java.lang.String getFieldConfigurationName()
public org.apache.lucene.index.IndexWriter getIndexWriter(boolean create) throws CmsIndexException
create
- if true
a whole new index is created, if false
an existing index is updated
CmsIndexException
- if the index can not be openedpublic java.util.Locale getLocale()
public java.lang.String getLocaleString()
getLocale()
public java.lang.String getName()
public java.lang.String getPath()
public java.lang.String getProject()
public java.lang.String getRebuildMode()
public java.util.List getSourceNames()
public java.util.List getSources()
public int hashCode()
Object.hashCode()
public void initConfiguration()
I_CmsConfigurationParameterHandler
initConfiguration
in interface I_CmsConfigurationParameterHandler
I_CmsConfigurationParameterHandler.initConfiguration()
public void initialize() throws CmsSearchException
CmsSearchException
- if the index source association failedpublic boolean isEnabled()
true
if this index is currently disabled.
true
if this index is currently disabledpublic void removeSourceName(java.lang.String sourceName)
sourceName
- the index source name to removepublic CmsSearchResultList search(CmsObject cms, CmsSearchParameters params) throws CmsSearchException
The result is returned as List with entries of type I_CmsSearchResult.
cms
- the current user's Cms objectparams
- the parameters to use for the search
CmsSearchException
- if something goes wrongpublic void setEnabled(boolean enabled)
enabled
- the state of the index to setpublic void setFieldConfiguration(CmsSearchFieldConfiguration fieldConfiguration)
fieldConfiguration
- the field configuration to setpublic void setFieldConfigurationName(java.lang.String fieldConfigurationName)
fieldConfigurationName
- the name of the field configuration to setpublic void setLocale(java.util.Locale locale)
locale
- the locale to index resourcespublic void setLocaleString(java.lang.String locale)
locale
- the locale to index resourcessetLocale(Locale)
public void setName(java.lang.String name) throws CmsIllegalArgumentException
name
- the logical key/name of this search index
CmsIllegalArgumentException
- if the given name is null, empty or already taken
by another search index.public void setProject(java.lang.String projectName)
A duplicate method of
that allows
to use instances of this class as a widget object (bean convention,
cp.: setProjectName(String)
.getProject()
projectName
- the name of the project used to index resourcespublic void setProjectName(java.lang.String projectName)
projectName
- the name of the project used to index resourcespublic void setRebuildMode(java.lang.String rebuildMode)
rebuildMode
- the rebuild mode of this search index {auto|manual}public java.lang.String toString()
getName()
) of this search index.
getName()
) of this search indexObject.toString()
protected boolean hasReadPermission(CmsObject cms, org.apache.lucene.document.Document doc)
cms
- the OpenCms user context to use for permission testingdoc
- the search result document to check
true
if the user has read permissions to the resourceprotected boolean isInTimeRange(org.apache.lucene.document.Document doc, CmsSearchParameters params)
The creation date and/or the last modification date are checked.
doc
- the document to check the dates against the given time rangeparams
- the search parameters where the time ranges are specified
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |