|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opencms.search.CmsSearchIndex
public class CmsSearchIndex
Implements the search within an index and the management of the index configuration.
| Field Summary | |
|---|---|
static String[] |
DOC_META_FIELDS
Constant for a field list that cointains only the "meta" field. |
static String |
EXCERPT
Constant for additional param to enable excerpt creation (default: true). |
static String |
PERMISSIONS
Constant for additional param to enable permission checks (default: true). |
static String |
PRIORITY
Constant for additional param to set the thread priority during search. |
static String |
REBUILD_MODE_AUTO
Automatic ("auto") index rebuild mode. |
static String |
REBUILD_MODE_MANUAL
Manual ("manual") index rebuild mode. |
static String |
ROOT_PATH_SUFFIX
Special root path append token for optimized path queries. |
static 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()
Creates a new CmsSearchIndex. |
|
| Method Summary | |
|---|---|
void |
addConfigurationParameter(String key,
String value)
Adds a parameter. |
void |
addSourceName(String sourceName)
Adds am index source to this search index. |
boolean |
equals(Object obj)
|
Map |
getConfiguration()
Returns the configuration of this parameter configurable class instance, or null if the class does not need to be configured. |
List |
getDocumenttypes(String path)
Returns the configured document types of this index for the given resource path. |
protected String |
getExcerpt(String content,
Query searchQuery,
Analyzer analyzer)
Returns an excerpt of the given content related to the given search query. |
IndexWriter |
getIndexWriter(boolean create)
Returns a new index writer for this index. |
String |
getLocale()
Gets the langauge of this index. |
String |
getName()
Gets the name of this index. |
String |
getPath()
Returns the path where this index stores it's data in the "real" file system. |
String |
getProject()
Gets the project of this index. |
String |
getRebuildMode()
Get the rebuild mode of this index. |
List |
getSourceNames()
Returns all configured sources names of this search index. |
List |
getSources()
Returns all configured index sources of this search index. |
int |
hashCode()
|
protected boolean |
hasReadPermission(CmsObject cms,
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. |
void |
removeSourceName(String sourceName)
Removes an index source from this search index. |
static String |
rootPathRewrite(String path)
Rewrites the a resource path for use in the I_CmsDocumentFactory.DOC_ROOT field. |
static String[] |
rootPathSplit(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 page,
int matchesPerPage)
Performs a search on the index within the given fields. |
void |
setLocale(String locale)
Sets the locale to index resources. |
void |
setName(String name)
Sets the logical key/name of this search index. |
void |
setProjectName(String projectName)
Sets the name of the project used to index resources. |
void |
setRebuildMode(String rebuildMode)
Sets the rebuild mode of this search index. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String[] DOC_META_FIELDS
public static final String EXCERPT
public static final String PERMISSIONS
public static final String PRIORITY
public static final String REBUILD_MODE_AUTO
public static final String REBUILD_MODE_MANUAL
public static final String ROOT_PATH_SUFFIX
public static final String ROOT_PATH_TOKEN
| Constructor Detail |
|---|
public CmsSearchIndex()
| Method Detail |
|---|
public static String rootPathRewrite(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 String[] rootPathSplit(String path)
I_CmsDocumentFactory.DOC_ROOT field
and with the rootPathRewrite(String) method.
path - the path to split
rootPathRewrite(String)
public void addConfigurationParameter(String key,
String value)
addConfigurationParameter in interface I_CmsConfigurationParameterHandlerkey - the key/name of the parametervalue - the value of the parameterpublic void addSourceName(String sourceName)
sourceName - the index source name to addpublic boolean equals(Object obj)
equals in class ObjectObject.equals(java.lang.Object)public Map getConfiguration()
I_CmsConfigurationParameterHandlernull 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_CmsConfigurationParameterHandlernullI_CmsConfigurationParameterHandler.getConfiguration()public List getDocumenttypes(String path)
The result List contains Strings with the names of the document types.
path - path of the folder
public 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 String getLocale()
public String getName()
public String getPath()
public String getProject()
public String getRebuildMode()
public List getSourceNames()
public List getSources()
public int hashCode()
hashCode in class ObjectObject.hashCode()public void initConfiguration()
I_CmsConfigurationParameterHandler
initConfiguration in interface I_CmsConfigurationParameterHandlerI_CmsConfigurationParameterHandler.initConfiguration()
public void initialize()
throws CmsSearchException
CmsSearchException - if the index source association failedpublic void removeSourceName(String sourceName)
sourceName - the index source name to remove
public CmsSearchResultList search(CmsObject cms,
CmsSearchParameters params,
int page,
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 searchpage - the page to calculate the search result list, or -1 to return all found documents in the search resultmatchesPerPage - the number of search results per page, or -1 to return all found documents in the search result
CmsSearchException - if something goes wrongpublic void setLocale(String locale)
locale - the locale to index resourcespublic void setName(String name)
name - the logical key/name of this search indexpublic void setProjectName(String projectName)
projectName - the name of the project used to index resourcespublic void setRebuildMode(String rebuildMode)
rebuildMode - the rebuild mode of this search index {auto|manual}
protected String getExcerpt(String content,
Query searchQuery,
Analyzer analyzer)
throws IOException
content - the contentsearchQuery - the search queryanalyzer - the analyzer used
IOException - if something goes wrong
protected boolean hasReadPermission(CmsObject cms,
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 | |||||||||