这里讲讲CoreContainer的load(String dir, File
configFile
)方法所做的事情,也就是如何根据主目录下的solr.xml配置文件的数据以及主目录来对每个ScoreCore进行初始设置的,这些工作属于服务器启
动的一部分。
先来说说参数吧,配置文件对象直接赋予CoreContainer的configFile
属性,而主目录路径dir则是用来构建一个Solr资源加载器(SolrResourceLoader),将该加载器作为当前CoreContainer
的loader属性。代码如下。
///////////
this.configFile = configFile;
this.loader = new SolrResourceLoader(dir);
//////////
SolrResourceLoader是管理当前目录下面的资源的类,这些资源包括目录名称,索引数据目录,类等等。
下面通过这个语句获得配置文件的内容流。
//////
FileInputStream cfgis = new FileInputStream(configFile);
//////
获得流以后,所做的工作概括来说就是读取配置文件中的类容并设置相关的属性,我们来具体看一看。
Config cfg = new Config(loader, null, cfgis, null);这句代码,我们知道返回一个Confige对象,该对象的本质是什么?构造函数的参数又是什么意思呢?
先看看构造函数的参数说明:
//////
/* Font definitions */html { font-family: 'Tahoma',sans-serif; font-size: 8pt; font-style: normal; font-weight: normal; }body, h4, h5, h6, p, table, td, caption, th, ul, ol, dl, li, dd, dt { font-size: 1em; }pre { font-family: monospace; }h1 { font-size: 1.8em; } h2 { font-size: 1.2em; }h3 { font-size: 1.1em; }/* Margins */h1 { margin-top: 0.3em; margin-bottom: 0.04em } h2 { margin-top: 2em; margin-bottom: 0.25em }h3 { margin-top: 1.7em; margin-bottom: 0.25em }h4 { margin-top: 2em; margin-bottom: 0.3em }h5 { margin-top: 0px; margin-bottom: 0px }p { margin-top: 1em; margin-bottom: 1em }pre { margin-left: 0.6em }ul { margin-top: 0px; margin-bottom: 1em; }li { margin-top: 0px; margin-bottom: 0px; } li p { margin-top: 0px; margin-bottom: 0px; } ol { margin-top: 0px; margin-bottom: 1em; }dl { margin-top: 0px; margin-bottom: 1em; }dt { margin-top: 0px; margin-bottom: 0px; font-weight: bold; }dd { margin-top: 0px; margin-bottom: 0px; }/* Styles and colors */a:link { color: #0000FF; }a:hover { color: #000080; }a:visited { text-decoration: underline; }h4 { font-style: italic; }strong { font-weight: bold; }em { font-style: italic; }var { font-style: italic; }th { font-weight: bold; }
Builds a config:
Note that the 'name' parameter is used to obtain a valid input stream
if no valid one is provided through 'is'. If no valid stream is
provided, a valid SolrResourceLoader instance should be provided
through 'loader' so the resource can be opened (@see
SolrResourceLoader#openResource); if no SolrResourceLoader instance is
provided, a default one will be created.
Consider passing a non-null 'name' parameter in all use-cases since it is used for logging & exception reporting.
Parameters:
loader
the resource loader used to obtain an input stream if 'is' is null
name
the resource name used if the input stream 'is' is null
is
the resource as a stream
prefix
an optional prefix that will be preprended to all non-absolute xpath expressions
Throws:
javax.xml.parsers.ParserConfigurationException
java.io.IOException
org.xml.sax.SAXException
public Config(SolrResourceLoader loader, String name, InputStream is, String prefix) ......
//////
这段话的意思是,name参数存在的意义是在is不能提供正确的输入流的情况下发挥作用以获得正确的流。is为空,那么将一个
SolrResourceLoader的实例通过loader来传递以确保能打开资源,如果没有提供一个
SolrResourceLoader的实例,那么会建立一个默认的。name参数最好为非空,以便记录日志。成功加载配置文件solr.xml之后,下面的代码不过是读取配置文件中的内容来设置一些属性而已。
//////
persistent = cfg.getBool( "solr/@persistent", false );
libDir = cfg.get( "solr/@sharedLib", null);
adminPath = cfg.get( "solr/cores/@adminPath", null );
managementPath = cfg.get("solr/cores/@managementPath", null );
//////
通常上面几个属性的值如下:
persistent:false
libDirnull
adminPath:/admin/cores
managementPathnull
下面这段代码是看solr.xml配置文件中是否指定了一个lib目录,如果有则加载之。
//////
if (libDir != null) {
// relative dir to conf
File f = new File(dir, libDir);
libDir = f.getPath();
log.info( "loading shared library: "+f.getAbsolutePath() );
libLoader = SolrResourceLoader.createClassLoader(f, null);
}
//////
下面的代码返回管理处理器
//////
if( adminPath != null ) {
coreAdminHandler = this.createMultiCoreHandler();
}
//////
下面的代码读取solr.xml文件中solr节点,如果有多个只返回第一个,其它的都忽略掉。
//////
containerProperties = readProperties(cfg, ((NodeList) cfg.evaluate("solr", XPathConstants.NODESET)).item(0));
//////
下面的代码获得xpath为solr/cores/core的节点,这里可能有多个节点,因此是一个NodeList类型。
//////
NodeList nodes = (NodeList)cfg.evaluate("solr/cores/core", XPathConstants.NODESET);
//////
下面的代码就是通过一个for循环来处理nodes中的信息,根据这里的信息来建立每个核(对应每个库),例如如果我的solr.xml中有多个core节点,并且主目录下有多个与这些节点对应的库的话,那么这里就是针对每一个库的初始化处理。
具体细节请看Solr1.3的启动过程分析三
敬请关注:http://www.lucas.gd.cn
/ 之Solr板块
----------------------------------------
原创文章:敬请著名出处http://www.lucas.gd.cn
。
作者:宋永维
email:lucas.song.cn@gmail.com
分享到:
相关推荐
(2)使用内置的Jetty来启动Solr服务器只需要在example目录下,执行start.jar程序即可,我们可以直接执行命令:java –jar start.jar。 (3)当服务启动后,默认发布在8983端口,所以可以访问该端口来访问Solr服务,...
详细阐述Solr-search 源码级别过程
solr讲解,案例分析
Lucidworks Solr 参考指南 1.3 http://www.ossez.com/forum.php?mod=viewthread&tid=12022&fromuid=426
lucene&solr原理分析,lucene搜索引擎和solr搜索服务器原理分析。
配置solr出现404,试过很多方法解决不了,这有配置好的现成的,在wen.xml中将solrhome路径改成你创建的solrhome的路径
开源企业搜索引擎SOLR的应用教程 ...Solr 1.3 版本开始支持从数据库(通过 JDBC)、RSS 提要、Web 页面和文件中导入数据,但是不直接支持从二进制文件格式中提取内容,比如 MS Office、Adobe PDF 或其他专有格式。
开源企业搜索引擎SOLR的应用教程, ...Solr 1.3 版本开始支持从数据库(通过 JDBC)、RSS 提要、Web 页面和文件中导入数据,但是不直接支持从二进制文件格式中提取内容,比如 MS Office、Adobe PDF 或其他专有格式。
solr5.5.4.war&tomcat8.5.20,solr环境已经配置好。直接启动Tomcat即可使用,使用的java环境是1.8的版本,低版本没测试过。solrHhome配置在Tomcat目录下,solr日志配置在Tomcat日志目录下。
关于Solr技术分析及运用的开发文档,从下载到运行的全过程。
完全配置好的solr容器,直接修改web.xml设置一下solr core路劲即可
2 Solr的安装与配置 13 2.1 在Tomcat下Solr安装 13 2.1.1 安装准备 13 2.1.2 安装过程 14 2.1.3 验证安装 15 2.2 中文分词配置 15 2.2.1 mmseg4j 15 2.2.2 paoding 19 2.3 多核(MultiCore)配置 22 2.3.1 MultiCore...
solr.warsolr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包solr.war包...
Solr和ElasticSearch分析比较
很多初学者在对solr进行配置时,会出现很多问题。最近学习了solr,把自己的问题和解决办法分享给大家,希望有所帮助。
solr技术分析及运用超详细教程solr开发指南,包括solr服务器搭建,新增数据库配置,配置增量更新,配置分词器,常见异常,删除默认字段,调试技巧,solr日志,,solr基本查询语法,solr多字段匹配,solri集成solr...
详细的tomcat和solr的配置安装过程
最新版windows solr-8.8.2.zip最新版windows solr-8.8.2.zip最新版windows solr-8.8.2.zip
solr