Solr4.4中配置multicore

自己对solr也是新手,所以很多东西也不够了解,这里只是记录一下自己的学习过程。

主要参考资料:

本文主要记述SOLR4.4版本与旧版本在multicore配置方面的不同之处,所以引用了很多官方文档的内容,由于自己也是刚接触solr而且水平也低,因此可能介绍地不明不白,如果有疑问请移步到上面列出的官方wiki文档。


有关solr multicore的简介


关于solr multicore的介绍请参照官方的相关wiki页面:

http://wiki.apache.org/solr/CoreAdmin

该wiki上有这样几句话来介绍solr multicore:

In solr, the "multi core" concept refers to the ability to have multiple cores running in the same webapp.

Multiple cores let you have a single Solr instance with separate configurations and indexes, with their own config and schema for very different applications, but still have the convenience of unified administration. Individual indexes are still fairly isolated, but you can manage them as a single application, create new indexes on the fly by spinning up new SolrCores, and even make one SolrCore replace another SolrCore without ever restarting your Servlet Container. 

自己的英文不好,就不试着翻译了,想必都能看出来大体意思。multicore是在solr1.3中加入的,其目的就是运行一个solr实例,可以有多个搜索应用(这是别人的原话,引用一下)。


solr4.4中的multicore


在solr4.4之前的版本中,multicore都是在%SOLR_HOME%/solr.xml中配置的,虽然我没有使用过较旧版本的solr,但这从网上一些教程上可以看得出来。比如这里:

大体配置如下所示:

<cores adminPath="/admin/cores">  
    <core name="core0" instanceDir="core0" />  
    <core name="core1" instanceDir="core1" />
</cores> 

但solr4.4版本中的multicore相对于以前版本改变是非常大的,这些改变可以从以下两个页面看到:

从上面的页面中可以看出,从solr4.4开始,%SOLR_HOME%下的solr.xml结构发生变化,这些变化在5.0中将会强制执行。下面是官方wiki的介绍:

  • Optionally as of Solr4.4 and mandatory for Solr5.0, the structure of the solr.xml file has changed. In a nutshell, <cores> and <core> have been replaced by auto-discovering cores. Whether to use old or new-style core definitions is determined by whether the <cores> tag is present in solr.xml. In 5.0, presence of the <cores> tag will generate an error on startup.

  • An optional property coreRootDirectory can cause the discovery process to start at an arbitrary directory other than SOLR_HOME.

  • We'll distribute a new-style solr.xml as the default in the example directory with Solr4.4

  • The sharedLib attribute on the top-level <solr> element is replaced by a child str element (see below). In theory, the old mechanism should continue to support sharedLib, but SOLR-4791 documents the fact that it doesn't work in 4.3.0.

上面几段话的大体意思是从Solr4.4开始在solr.xml文件中取消了<cores/>节点,用自动探测cores来代替,这个改变在Solr4.4时是可选的,而从Solr5.0开始强制采用。


SOLR4.4中multicore的自动检测


那么SOLR是如何自动探测cores的呢?wiki同样有相关的描述:

Core discovery process

Exploration of the core tree terminates when a file named core.properties is encountered. Discovery of a file of that name is assumed to define the root of a core. There is no a-priori limit on the depth of the tree. That is, the directories under the core root are explored until a core.properties file is encountered, and that directory is assumed to be the instanceDir for that core. Subdirectories of any directory that has a core.properties file are NOT examined for additional cores. 

从上面的介绍中可以看到,探测将从core root开始(core root可以在solr.xml文件中以coreRootDirectory属性定义),不限制深度地递归遍历其所有子目录,直到一个名为core.properties的配置文件被发现。含有该core.properties文件的目录将被当作一个core的instanceDir目录,并且该目录下的子目录即使再含有core.properties文件也不会被当作另外core的instanceDir。

那么core.properties文件都可配置哪些信息呢?如下所示:

  • name - the name of the core. If not specified, the name comes from the containing directory.
  • config - the configuration file. Defaults to solrconfig.xml
  • dataDir - the directory where the index, tlog, etc. are stored. Again, since this is discovery-based, omit this unless you have special needs.
  • ulogDir - where the transaction log resides. It may be advantageous to put the transaction lot on a different disk than the index.
  • schema - the schema file. Defaults to schema.xml
  • shard - the shard ID.
  • collection - the collection to which this core belongs
  • roles - SolrCloud role definition

  • properties - properties file to override core definitions. TBD: This is probably obsolete since we're reading a properties file in the first place. Is there a use case for supporting this now?
  • loadOnStartup - [true|false] this core should be loaded and a searcher opened when Solr starts.

  • transient - [true|false] this core may be unloaded if the core cache exceeds transientCacheSize (defined in solr.propreties)

  • coreNodeName - SolrCloud core node name

所有的配置项都有相应的解释,也很简单,这里就不作过多解释。

  • 注1:如果core.properties文件是空的,也就是说里面没有任何文字内容,那么这个core的名字将与core.properties文件所在的目录名相同。比如一个空的core.properties文件出现在目录/solr/home/core1中, 则core的名字默认为 "core1",instanceDir 就是 /solr/home/core1,dataDir 就是 /solr/home/core1/data目录等。
  • 注2:很容易想像地到,如果要临时忽略掉一个core,那么最简单的方式就是将该core对应的instanceDir目录中的core.properites文件重命名,比如core.properties.bak。
  • 注3:上面提到在SOLR4.4版本solr.xml中的cores节点是可选的,也就是可有可无。是否含有cores节点将作为该solr.xml被按照新样式还是旧样式解析的依据,如果我们既在solr.xml文件中配置的了cores节点又在instanceDir目录中放置了core.properties文件,那么solr.xml文件中的配置优先。


实例配置


前面的内容都是空泛的理论,下面记一下自己的配置。

我的SOLR_HOME定义在/opt/tomcat-6.0.37/webapps/solr/solr_home目录,目录结构如下:


其中我的solr.xml文件中没有定义<cores/>节点,那么该solr.xml将被当作新样式的配置文件解析,也就是说SOLR将自动探测cores的定义。另外该目录下的collection1和core1子目录均含有core.properties配置文件,其中core1目录下的core.properties文件是空的,collection1目录下的core.properties文件只有一行内容:

name=core0

值得注意的是collection1和core1两个目录结构是相似的,不同的仅是core.properties文件和各自的schema.xml配置文件,其目录结构大体如下所示:



那么,根据上面的介绍,collection1和core1目录都会被当作core的instanceDir,两个core的名字分别为core0和core1。

启动Tomcat,浏览器访问的时候就可以看到在core选择列表上有两个core,分别为core0和core1,贴张图片验证一下:



配置了多core后mmseg4j中自定义词库的配置


如果是使用绝对路径的话比较简单,直接指定就可以了,如果是使用相对路径,需要注意的是“相对”是相对于当前的core所在路径来说的。

举个例子就比较清晰了:

假设我在solr.home中配置了两个core:core1和core2,然后把自定义词库文件放在solr.home中的dict目录,也就是说core1、core2和dict三个目录平级,都存在于solr.home目录中。那么core1和core2中的schema.xml文件中文分词就应该这样配置:

<!-- 中文分词 -->
<fieldType name="text_zh" class="solr.TextField" positionIncrementGap="100">
  <analyzer> 
	<tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex"
				dicPath="../dict" />
	<filter class="com.chenlb.mmseg4j.solr.CutLetterDigitFilterFactory"/>
  </analyzer>
</fieldType>
<!-- 中文分词 -->

另外也可以从Solr启动日志中查看词库载入信息,可以发现是相对于core所在目录来说的:




自定义词库文件名需要以words开关,后缀为.dic,例如:words-sg.dic ,词库格式描述如下:

http://blog.chenlb.com/2009/04/chinese-segment-mmseg4j-dictionary-format.html


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值