cmssearchmanager.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,663 行 · 第 1/5 页
JAVA
1,663 行
public void cmsEvent(CmsEvent event) {
switch (event.getType()) {
case I_CmsEventListener.EVENT_REBUILD_SEARCHINDEXES:
List indexNames = null;
if ((event.getData() != null)
&& CmsStringUtil.isNotEmptyOrWhitespaceOnly((String)event.getData().get(
I_CmsEventListener.KEY_INDEX_NAMES))) {
indexNames = CmsStringUtil.splitAsList((String)event.getData().get(
I_CmsEventListener.KEY_INDEX_NAMES), ",", true);
}
try {
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_EVENT_REBUILD_SEARCHINDEX_1,
indexNames == null ? "" : CmsStringUtil.collectionAsString(indexNames, ",")));
}
if (indexNames == null) {
rebuildAllIndexes(getEventReport(event));
} else {
rebuildIndexes(indexNames, getEventReport(event));
}
} catch (CmsException e) {
if (LOG.isErrorEnabled()) {
LOG.error(Messages.get().getBundle().key(
Messages.ERR_EVENT_REBUILD_SEARCHINDEX_1,
indexNames == null ? "" : CmsStringUtil.collectionAsString(indexNames, ",")), e);
}
}
break;
case I_CmsEventListener.EVENT_CLEAR_CACHES:
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_EVENT_CLEAR_CACHES_0));
}
break;
case I_CmsEventListener.EVENT_PUBLISH_PROJECT:
// event data contains a list of the published resources
CmsUUID publishHistoryId = new CmsUUID((String)event.getData().get(I_CmsEventListener.KEY_PUBLISHID));
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(Messages.LOG_EVENT_PUBLISH_PROJECT_1, publishHistoryId));
}
updateAllIndexes(m_adminCms, publishHistoryId, getEventReport(event));
if (LOG.isDebugEnabled()) {
LOG.debug(Messages.get().getBundle().key(
Messages.LOG_EVENT_PUBLISH_PROJECT_FINISHED_1,
publishHistoryId));
}
break;
default:
// no operation
}
}
/**
* Returns an unmodifiable view of the map that contains the {@link CmsSearchAnalyzer} list.<p>
*
* The keys in the map are {@link Locale} objects, and the values are {@link CmsSearchAnalyzer} objects.
*
* @return an unmodifiable view of the Analyzers Map
*/
public Map getAnalyzers() {
return Collections.unmodifiableMap(m_analyzers);
}
/**
* Returns the search analyzer for the given locale.<p>
*
* @param locale the locale to get the analyzer for
*
* @return the search analyzer for the given locale
*/
public CmsSearchAnalyzer getCmsSearchAnalyzer(Locale locale) {
return (CmsSearchAnalyzer)m_analyzers.get(locale);
}
/**
* Returns the name of the directory below WEB-INF/ where the search indexes are stored.<p>
*
* @return the name of the directory below WEB-INF/ where the search indexes are stored
*/
public String getDirectory() {
return m_path;
}
/**
* Returns a document type config.<p>
*
* @param name the name of the document type config
* @return the document type config.
*/
public CmsSearchDocumentType getDocumentTypeConfig(String name) {
// this is really used only for the search manager GUI,
// so performance is not an issue and no lookup map is generated
for (int i = 0; i < m_documentTypeConfigs.size(); i++) {
CmsSearchDocumentType type = (CmsSearchDocumentType)m_documentTypeConfigs.get(i);
if (type.getName().equals(name)) {
return type;
}
}
return null;
}
/**
* Returns an unmodifiable view (read-only) of the DocumentTypeConfigs Map.<p>
*
* @return an unmodifiable view (read-only) of the DocumentTypeConfigs Map
*/
public List getDocumentTypeConfigs() {
return Collections.unmodifiableList(m_documentTypeConfigs);
}
/**
* Returns the maximum age a text extraction result is kept in the cache (in hours).<p>
*
* @return the maximum age a text extraction result is kept in the cache (in hours)
*/
public float getExtractionCacheMaxAge() {
return m_extractionCacheMaxAge;
}
/**
* Returns the search field configuration with the given name.<p>
*
* In case no configuration is available with the given name, <code>null</code> is returned.<p>
*
* @param name the name to get the search field configuration for
*
* @return the search field configuration with the given name
*/
public CmsSearchFieldConfiguration getFieldConfiguration(String name) {
return (CmsSearchFieldConfiguration)m_fieldConfigurations.get(name);
}
/**
* Returns the unmodifieable List of configured {@link CmsSearchFieldConfiguration} entries.<p>
*
* @return the unmodifieable List of configured {@link CmsSearchFieldConfiguration} entries
*/
public List getFieldConfigurations() {
List result = new ArrayList(m_fieldConfigurations.values());
Collections.sort(result);
return Collections.unmodifiableList(result);
}
/**
* Returns the force unlock mode during indexing.<p>
*
* @return the force unlock mode during indexing
*/
public CmsSearchForceUnlockMode getForceunlock() {
return m_forceUnlockMode;
}
/**
* Returns the highlighter.<p>
*
* @return the highlighter
*/
public I_CmsTermHighlighter getHighlighter() {
return m_highlighter;
}
/**
* Returns the index belonging to the passed name.<p>
* The index must exist already.
*
* @param indexName then name of the index
* @return an object representing the desired index
*/
public CmsSearchIndex getIndex(String indexName) {
for (int i = 0, n = m_indexes.size(); i < n; i++) {
CmsSearchIndex searchIndex = (CmsSearchIndex)m_indexes.get(i);
if (indexName.equalsIgnoreCase(searchIndex.getName())) {
return searchIndex;
}
}
return null;
}
/**
* Returns the seconds to wait for an index lock during an update operation.<p>
*
* @return the seconds to wait for an index lock during an update operation
*/
public int getIndexLockMaxWaitSeconds() {
return m_indexLockMaxWaitSeconds;
}
/**
* Returns the names of all configured indexes.<p>
*
* @return list of names
*/
public List getIndexNames() {
List indexNames = new ArrayList();
for (int i = 0, n = m_indexes.size(); i < n; i++) {
indexNames.add(((CmsSearchIndex)m_indexes.get(i)).getName());
}
return indexNames;
}
/**
* Returns a search index source for a specified source name.<p>
*
* @param sourceName the name of the index source
* @return a search index source
*/
public CmsSearchIndexSource getIndexSource(String sourceName) {
return (CmsSearchIndexSource)m_indexSources.get(sourceName);
}
/**
* Returns the max. excerpt length.<p>
*
* @return the max excerpt length
*/
public int getMaxExcerptLength() {
return m_maxExcerptLength;
}
/**
* Returns an unmodifiable list of all configured <code>{@link CmsSearchIndex}</code> instances.<p>
*
* @return an unmodifiable list of all configured <code>{@link CmsSearchIndex}</code> instances
*/
public List getSearchIndexes() {
return Collections.unmodifiableList(m_indexes);
}
/**
* Returns an unmodifiable view (read-only) of the SearchIndexSources Map.<p>
*
* @return an unmodifiable view (read-only) of the SearchIndexSources Map
*/
public Map getSearchIndexSources() {
return Collections.unmodifiableMap(m_indexSources);
}
/**
* Returns the timeout to abandon threads indexing a resource.<p>
*
* @return the timeout to abandon threads indexing a resource
*/
public long getTimeout() {
return m_timeout;
}
/**
* Initializes the search manager.<p>
*
* @param cms the cms object
*
* @throws CmsRoleViolationException in case the given opencms object does not have <code>{@link CmsRole#WORKPLACE_MANAGER}</code> permissions
*/
public void initialize(CmsObject cms) throws CmsRoleViolationException {
OpenCms.getRoleManager().checkRole(cms, CmsRole.WORKPLACE_MANAGER);
try {
// store the Admin cms to index Cms resources
m_adminCms = OpenCms.initCmsObject(cms);
} catch (CmsException e) {
// this should never happen
}
// make sure the site root is the root site
m_adminCms.getRequestContext().setSiteRoot("/");
// create the extraction result cache
m_extractionResultCache = new CmsExtractionResultCache(
OpenCms.getSystemInfo().getAbsoluteRfsPathRelativeToWebInf(getDirectory()),
"/extractCache");
initializeIndexes();
// register the modified default similarity implementation
Similarity.setDefault(new CmsSearchSimilarity());
// register this object as event listener
OpenCms.addCmsEventListener(this, new int[] {
I_CmsEventListener.EVENT_CLEAR_CACHES,
I_CmsEventListener.EVENT_PUBLISH_PROJECT,
I_CmsEventListener.EVENT_REBUILD_SEARCHINDEXES});
}
/**
* Initializes all configured document types and search indexes.<p>
*
* This methods needs to be called if after a change in the index configuration has been made.
*/
public void initializeIndexes() {
initAvailableDocumentTypes();
initSearchIndexes();
}
/**
* Updates the indexes from as a scheduled job.<p>
*
* @param cms the OpenCms user context to use when reading resources from the VFS
* @param parameters the parameters for the scheduled job
*
* @throws Exception if something goes wrong
*
* @return the String to write in the scheduler log
*
* @see org.opencms.scheduler.I_CmsScheduledJob#launch(org.opencms.file.CmsObject, java.util.Map)
*/
public String launch(CmsObject cms, Map parameters) throws Exception {
CmsSearchManager manager = OpenCms.getSearchManager();
I_CmsReport report = null;
boolean writeLog = Boolean.valueOf((String)parameters.get(JOB_PARAM_WRITELOG)).booleanValue();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?