cmssearchconfiguration.java
来自「找了很久才找到到源代码」· Java 代码 · 共 598 行 · 第 1/2 页
JAVA
598 行
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/configuration/CmsSearchConfiguration.java,v $
* Date : $Date: 2007-08-13 16:30:10 $
* Version: $Revision: 1.19 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.opencms.configuration;
import org.opencms.i18n.CmsLocaleComparator;
import org.opencms.main.CmsLog;
import org.opencms.main.OpenCms;
import org.opencms.search.CmsSearchAnalyzer;
import org.opencms.search.CmsSearchDocumentType;
import org.opencms.search.CmsSearchIndex;
import org.opencms.search.CmsSearchIndexSource;
import org.opencms.search.CmsSearchManager;
import org.opencms.search.fields.CmsSearchField;
import org.opencms.search.fields.CmsSearchFieldConfiguration;
import org.opencms.search.fields.CmsSearchFieldMapping;
import org.opencms.util.CmsStringUtil;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.digester.Digester;
import org.dom4j.Element;
/**
* Lucene search configuration class.<p>
*
* @author Thomas Weckert
*
* @version $Revision: 1.19 $
*
* @since 6.0.0
*/
public class CmsSearchConfiguration extends A_CmsXmlConfiguration implements I_CmsXmlConfiguration {
/** The "boost" attribute. */
public static final String A_BOOST = "boost";
/** The "displayName" attribute. */
public static final String A_DISPLAY = "display";
/** The "excerpt" attribute. */
public static final String A_EXCERPT = "excerpt";
/** The "index" attribute. */
public static final String A_INDEX = "index";
/** The "store" attribute. */
public static final String A_STORE = "store";
/** The name of the DTD for this configuration. */
public static final String CONFIGURATION_DTD_NAME = "opencms-search.dtd";
/** The name of the default XML file for this configuration. */
public static final String DEFAULT_XML_FILE_NAME = "opencms-search.xml";
/** Node name constant. */
public static final String N_ANALYZER = "analyzer";
/** Node name constant. */
public static final String N_ANALYZERS = "analyzers";
/** Node name constant. */
public static final String N_CLASS = "class";
/** Node name constant. */
public static final String N_CONFIGURATION = "configuration";
/** Node name constant. */
public static final String N_DESCRIPTION = "description";
/** Node name constant. */
public static final String N_DIRECTORY = "directory";
/** Node name constant. */
public static final String N_DOCUMENTTYPE = "documenttype";
/** Node name constant. */
public static final String N_DOCUMENTTYPES = "documenttypes";
/** Node name constant. */
public static final String N_DOCUMENTTYPES_INDEXED = "documenttypes-indexed";
/** Node name constant. */
public static final String N_EXCERPT = "excerpt";
/** Node name constant. */
public static final String N_EXTRACTION_CACHE_MAX_AGE = "extractionCacheMaxAge";
/** Node name constant. */
public static final String N_FIELD = "field";
/** Node name constant. */
public static final String N_FIELDCONFIGURATION = "fieldconfiguration";
/** Node name constant. */
public static final String N_FIELDCONFIGURATIONS = "fieldconfigurations";
/** Node name constant. */
public static final String N_FIELDS = "fields";
/** Node name constant. */
public static final String N_FORCEUNLOCK = "forceunlock";
/** Node name constant. */
public static final String N_HIGHLIGHTER = "highlighter";
/** Node name constant. */
public static final String N_INDEX = "index";
/** Node name constant. */
public static final String N_INDEXER = "indexer";
/** Node name constant. */
public static final String N_INDEXES = "indexes";
/** Node name constant. */
public static final String N_INDEXSOURCE = "indexsource";
/** Node name constant. */
public static final String N_INDEXSOURCES = "indexsources";
/** Node name constant. */
public static final String N_LOCALE = "locale";
/** Node name constant. */
public static final String N_MAPPING = "mapping";
/** Node name constant. */
public static final String N_MIMETYPE = "mimetype";
/** Node name constant. */
public static final String N_MIMETYPES = "mimetypes";
/** Node name constant. */
public static final String N_PROJECT = "project";
/** Node name constant. */
public static final String N_REBUILD = "rebuild";
/** Node name constant. */
public static final String N_RESOURCES = "resources";
/** Node name constant. */
public static final String N_RESOURCETYPE = "resourcetype";
/** Node name constant. */
public static final String N_RESOURCETYPES = "resourcetypes";
/** Node name constant. */
public static final String N_SEARCH = "search";
/** Node name constant. */
public static final String N_SOURCE = "source";
/** Node name constant. */
public static final String N_SOURCES = "sources";
/** Node name constant. */
public static final String N_STEMMER = "stemmer";
/** Node name constant. */
public static final String N_TIMEOUT = "timeout";
/** Node name constant. */
private static final String XPATH_SEARCH = "*/" + N_SEARCH;
/** The configured search manager. */
private CmsSearchManager m_searchManager;
/**
* Public constructor, will be called by configuration manager.<p>
*/
public CmsSearchConfiguration() {
setXmlFileName(DEFAULT_XML_FILE_NAME);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SEARCH_CONFIG_INIT_0));
}
}
/**
* @see org.opencms.configuration.I_CmsXmlConfiguration#addXmlDigesterRules(org.apache.commons.digester.Digester)
*/
public void addXmlDigesterRules(Digester digester) {
String xPath = null;
// add finish rule
digester.addCallMethod(XPATH_SEARCH, "initializeFinished");
// creation of the search manager
digester.addObjectCreate(XPATH_SEARCH, CmsSearchManager.class);
// search manager finished
digester.addSetNext(XPATH_SEARCH, "setSearchManager");
// directory rule
digester.addCallMethod(XPATH_SEARCH + "/" + N_DIRECTORY, "setDirectory", 0);
// timeout rule
digester.addCallMethod(XPATH_SEARCH + "/" + N_TIMEOUT, "setTimeout", 0);
// forceunlock rule
digester.addCallMethod(XPATH_SEARCH + "/" + N_FORCEUNLOCK, "setForceunlock", 0);
// rule for the max. char. lenght of the search result excerpt
digester.addCallMethod(XPATH_SEARCH + "/" + N_EXCERPT, "setMaxExcerptLength", 0);
// rule for the max. age of entries in the extraction cache
digester.addCallMethod(XPATH_SEARCH + "/" + N_EXTRACTION_CACHE_MAX_AGE, "setExtractionCacheMaxAge", 0);
// rule for the highlighter to highlight the search terms in the excerpt of the search result
digester.addCallMethod(XPATH_SEARCH + "/" + N_HIGHLIGHTER, "setHighlighter", 0);
// document type rule
xPath = XPATH_SEARCH + "/" + N_DOCUMENTTYPES + "/" + N_DOCUMENTTYPE;
digester.addObjectCreate(xPath, CmsSearchDocumentType.class);
digester.addCallMethod(xPath + "/" + N_NAME, "setName", 0);
digester.addCallMethod(xPath + "/" + N_CLASS, "setClassName", 0);
digester.addCallMethod(xPath + "/" + N_MIMETYPES + "/" + N_MIMETYPE, "addMimeType", 0);
digester.addCallMethod(xPath + "/" + N_RESOURCETYPES + "/" + N_RESOURCETYPE, "addResourceType", 0);
digester.addSetNext(xPath, "addDocumentTypeConfig");
// analyzer rule
xPath = XPATH_SEARCH + "/" + N_ANALYZERS + "/" + N_ANALYZER;
digester.addObjectCreate(xPath, CmsSearchAnalyzer.class);
digester.addCallMethod(xPath + "/" + N_CLASS, "setClassName", 0);
digester.addCallMethod(xPath + "/" + N_STEMMER, "setStemmerAlgorithm", 0);
digester.addCallMethod(xPath + "/" + N_LOCALE, "setLocaleString", 0);
digester.addSetNext(xPath, "addAnalyzer");
// search index rule
xPath = XPATH_SEARCH + "/" + N_INDEXES + "/" + N_INDEX;
digester.addObjectCreate(xPath, CmsSearchIndex.class);
digester.addCallMethod(xPath + "/" + N_NAME, "setName", 0);
digester.addCallMethod(xPath + "/" + N_REBUILD, "setRebuildMode", 0);
digester.addCallMethod(xPath + "/" + N_PROJECT, "setProjectName", 0);
digester.addCallMethod(xPath + "/" + N_LOCALE, "setLocaleString", 0);
digester.addCallMethod(xPath + "/" + N_CONFIGURATION, "setFieldConfigurationName", 0);
digester.addCallMethod(xPath + "/" + N_SOURCES + "/" + N_SOURCE, "addSourceName", 0);
digester.addSetNext(xPath, "addSearchIndex");
// search index source rule
xPath = XPATH_SEARCH + "/" + N_INDEXSOURCES + "/" + N_INDEXSOURCE;
digester.addObjectCreate(xPath, CmsSearchIndexSource.class);
digester.addCallMethod(xPath + "/" + N_NAME, "setName", 0);
digester.addCallMethod(xPath + "/" + N_INDEXER, "setIndexerClassName", 1);
digester.addCallParam(xPath + "/" + N_INDEXER, 0, N_CLASS);
digester.addCallMethod(xPath + "/" + N_RESOURCES + "/" + N_RESOURCE, "addResourceName", 0);
digester.addCallMethod(xPath + "/" + N_DOCUMENTTYPES_INDEXED + "/" + N_NAME, "addDocumentType", 0);
digester.addSetNext(xPath, "addSearchIndexSource");
// field configuration rules
xPath = XPATH_SEARCH + "/" + N_FIELDCONFIGURATIONS + "/" + N_FIELDCONFIGURATION;
digester.addObjectCreate(xPath, CmsSearchFieldConfiguration.class);
digester.addCallMethod(xPath + "/" + N_NAME, "setName", 0);
digester.addCallMethod(xPath + "/" + N_DESCRIPTION, "setDescription", 0);
digester.addSetNext(xPath, "addFieldConfiguration");
xPath = xPath + "/" + N_FIELDS + "/" + N_FIELD;
digester.addObjectCreate(xPath, CmsSearchField.class);
digester.addCallMethod(xPath, "setName", 1);
digester.addCallParam(xPath, 0, I_CmsXmlConfiguration.A_NAME);
digester.addCallMethod(xPath, "setDisplayNameForConfiguration", 1);
digester.addCallParam(xPath, 0, A_DISPLAY);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?