|
|||||||
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[] |
DOC_META_FIELDS
Constant for a field list that contains the "meta" field as well as the "content" field. |
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
Special root path append token for optimized path queries. |
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. |
java.util.List |
getDocumenttypes(java.lang.String path)
Returns the configured document types of this index for the given resource path. |
protected java.lang.String |
getExcerpt(java.lang.String content,
org.apache.lucene.search.Query searchQuery,
org.apache.lucene.analysis.Analyzer analyzer)
Returns an excerpt of the given content related to the given search query. |
org.apache.lucene.index.IndexWriter |
getIndexWriter(boolean create)
Returns a new index writer for this index. |
java.lang.String |
getLocale()
Gets the langauge of 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 |
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. |
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 I_CmsDocumentFactory.DOC_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,
int matchesPerPage)
Performs a search on the index within the given fields. |
void |
setEnabled(boolean enabled)
Can be used to enable / disable this index. |
void |
setLocale(java.lang.String locale)
Sets the locale to index resources. |
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[] DOC_META_FIELDS
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
public 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)
I_CmsDocumentFactory.DOC_ROOT
field.
All "/" chars in the path are replaced with the ROOT_PATH_SUFFIX
token.
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.
This implementation basically replaces the "/" of a path with "@o.c ".
This is a trick so that the Lucene analyzer leaves the
directory names untouched, since it treats them like literal email addresses.
Otherwise 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 results then expected.
path
- the path to rewrite
public static java.lang.String[] rootPathSplit(java.lang.String path)
I_CmsDocumentFactory.DOC_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 java.util.List getDocumenttypes(java.lang.String path)
The result List contains Strings with the names of the document types.
path
- path of the folder
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.lang.String 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, int matchesPerPage) 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 searchmatchesPerPage
- the number of search results per page, or -1 to return all found documents in the search result
CmsSearchException
- if something goes wrongpublic void setEnabled(boolean enabled)
enabled
- the state of the index to setpublic void setLocale(java.lang.String locale)
locale
- the locale to index resourcespublic 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 java.lang.String getExcerpt(java.lang.String content, org.apache.lucene.search.Query searchQuery, org.apache.lucene.analysis.Analyzer analyzer) throws java.io.IOException
content
- the contentsearchQuery
- the search queryanalyzer
- the analyzer used
java.io.IOException
- if something goes wrongprotected 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 resource
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |