天天看点

跟益达学Solr5之solrconfig.xml配置详解

  solrconfig.xml配置文件中包含了很多solr自身配置相关的参数,solrconfig.xml配置文件示例可以从solr的解压目录下找到,如图:

跟益达学Solr5之solrconfig.xml配置详解

 用文本编辑软件打开solrconfig.xml配置,你将会看到以下配置内容:

跟益达学Solr5之solrconfig.xml配置详解

<?xml version="1.0" encoding="utf-8" ?>  

<!--  

 licensed to the apache software foundation (asf) under one or more  

 contributor license agreements.  see the notice file distributed with  

 this work for additional information regarding copyright ownership.  

 the asf licenses this file to you under the apache license, version 2.0  

 (the "license"); you may not use this file except in compliance with  

 the license.  you may obtain a copy of the license at  

     http://www.apache.org/licenses/license-2.0  

 unless required by applicable law or agreed to in writing, software  

 distributed under the license is distributed on an "as is" basis,  

 without warranties or conditions of any kind, either express or implied.  

 see the license for the specific language governing permissions and  

 limitations under the license.  

-->  

<!--   

     for more details about configurations options that may appear in  

     this file, see http://wiki.apache.org/solr/solrconfigxml.   

<config>  

  <!-- in all configuration below, a prefix of "solr." for class names  

       is an alias that causes solr to search appropriate packages,  

       including org.apache.solr.(search|update|request|core|analysis)  

       you may also specify a fully qualified java classname if you  

       have your own custom plugins.  

    -->  

  <!-- controls what version of lucene various components of solr  

       adhere to.  generally, you want to use the latest version to  

       get all bug fixes and improvements. it is highly recommended  

       that you fully re-index after changing this setting as it can  

       affect both how text is indexed and queried.  

  -->  

  <lucenematchversion>5.1.0</lucenematchversion>  

  <!-- data directory  

       used to specify an alternate directory to hold all index data  

       other than the default ./data under the solr home.  if  

       replication is in use, this should match the replication  

       configuration.  

  <!-- 

  <datadir>${solr.data.dir:}</datadir> 

  <datadir>c:\solr_home\core1\data</datadir>  

  <!-- the directoryfactory to use for indexes.  

       solr.standarddirectoryfactory is filesystem  

       based and tries to pick the best implementation for the current  

       jvm and platform.  solr.nrtcachingdirectoryfactory, the default,  

       wraps solr.standarddirectoryfactory and caches small files in memory  

       for better nrt performance.  

       one can force a particular implementation via solr.mmapdirectoryfactory,  

       solr.niofsdirectoryfactory, or solr.simplefsdirectoryfactory.  

       solr.ramdirectoryfactory is memory based, not  

       persistent, and doesn't work with replication.  

  <directoryfactory name="directoryfactory"   

                    class="${solr.directoryfactory:solr.nrtcachingdirectoryfactory}">  

  </directoryfactory>   

  <!-- the codecfactory for defining the format of the inverted index.  

       the default implementation is schemacodecfactory, which is the official lucene  

       index format, but hooks into the schema to provide per-field customization of  

       the postings lists and per-document values in the fieldtype element  

       (postingsformat/docvaluesformat). note that most of the alternative implementations  

       are experimental, so if you choose to customize the index format, it's a good  

       idea to convert back to the official format e.g. via indexwriter.addindexes(indexreader)  

       before upgrading to a newer version to avoid unnecessary reindexing.  

  <codecfactory class="solr.schemacodecfactory"/>  

  <schemafactory class="classicindexschemafactory"/>  

  <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  

       index config - these settings control low-level behavior of indexing  

       most example settings here show the default value, but are commented  

       out, to more easily see where customizations have been made.  

       note: this replaces <indexdefaults> and <mainindex> from older versions  

       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->  

  <indexconfig>  

    <!-- lockfactory   

         this option specifies which lucene lockfactory implementation  

         to use.  

         single = singleinstancelockfactory - suggested for a  

                  read-only index or when there is no possibility of  

                  another process trying to modify the index.  

         native = nativefslockfactory - uses os native file locking.  

                  do not use when multiple solr webapps in the same  

                  jvm are attempting to share a single index.  

         simple = simplefslockfactory  - uses a plain file for locking  

         defaults: 'native' is default for solr3.6 and later, otherwise  

                   'simple' is the default  

         more details on the nuances of each lockfactory...  

         http://wiki.apache.org/lucene-java/availablelockfactories  

    <locktype>${solr.lock.type:native}</locktype>  

    <!-- lucene infostream  

         to aid in advanced debugging, lucene provides an "infostream"  

         of detailed information when indexing.  

         setting the value to true will instruct the underlying lucene  

         indexwriter to write its info stream to solr's log. by default,  

         this is enabled here, and controlled through log4j.properties.  

      -->  

     <infostream>true</infostream>  

  </indexconfig>  

  <!-- jmx  

       this example enables jmx if and only if an existing mbeanserver  

       is found, use this if you want to configure jmx through jvm  

       parameters. remove this to disable exposing solr configuration  

       and statistics to jmx.  

       for more details see http://wiki.apache.org/solr/solrjmx  

  <jmx />  

  <!-- if you want to connect to a particular server, specify the  

       agentid   

  <!-- <jmx agentid="myagent" /> -->  

  <!-- if you want to start a new mbeanserver, specify the serviceurl -->  

  <!-- <jmx serviceurl="service:jmx:rmi:///jndi/rmi://localhost:9999/solr"/> 

  <!-- the default high-performance update handler -->  

  <updatehandler class="solr.directupdatehandler2">  

    <!-- enables a transaction log, used for real-time get, durability, and  

         and solr cloud replica recovery.  the log can grow as big as  

         uncommitted changes to the index, so use of a hard autocommit  

         is recommended (see below).  

         "dir" - the target directory for transaction logs, defaults to the  

                solr data directory.  -->   

    <updatelog>  

      <str name="dir">${solr.ulog.dir:}</str>  

    </updatelog>  

    <!-- autocommit  

         perform a hard commit automatically under certain conditions.  

         instead of enabling autocommit, consider using "commitwithin"  

         when adding documents.   

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

         maxdocs - maximum number of documents to add since the last  

                   commit before automatically triggering a new commit.  

         maxtime - maximum amount of time in ms that is allowed to pass  

                   since a document was added before automatically  

                   triggering a new commit.   

         opensearcher - if false, the commit causes recent index changes  

           to be flushed to stable storage, but does not cause a new  

           searcher to be opened to make those changes visible.  

         if the updatelog is enabled, then it's highly recommended to  

         have some sort of hard autocommit to limit the log size.  

     <autocommit>   

       <maxtime>${solr.autocommit.maxtime:15000}</maxtime>   

       <opensearcher>false</opensearcher>   

     </autocommit>  

    <!-- softautocommit is like autocommit except it causes a  

         'soft' commit which only ensures that changes are visible  

         but does not ensure that data is synced to disk.  this is  

         faster and more near-realtime friendly than a hard commit.  

     <autosoftcommit>   

       <maxtime>${solr.autosoftcommit.maxtime:-1}</maxtime>   

     </autosoftcommit>  

  </updatehandler>  

       query section - these settings control query time things like caches  

  <query>  

    <!-- max boolean clauses  

         maximum number of clauses in each booleanquery,  an exception  

         is thrown if exceeded.  

         ** warning **  

         this option actually modifies a global lucene property that  

         will affect all solrcores.  if multiple solrconfig.xml files  

         disagree on this property, the value at any given moment will  

         be based on the last solrcore to be initialized.  

    <maxbooleanclauses>1024</maxbooleanclauses>  

    <!-- solr internal query caches  

         there are two implementations of cache available for solr,  

         lrucache, based on a synchronized linkedhashmap, and  

         fastlrucache, based on a concurrenthashmap.    

         fastlrucache has faster gets and slower puts in single  

         threaded operation and thus is generally faster than lrucache  

         when the hit ratio of the cache is high (> 75%), and may be  

         faster under other scenarios on multi-cpu systems.  

    <!-- filter cache  

         cache used by solrindexsearcher for filters (docsets),  

         unordered sets of *all* documents that match a query.  when a  

         new searcher is opened, its caches may be prepopulated or  

         "autowarmed" using data from caches in the old searcher.  

         autowarmcount is the number of items to prepopulate.  for  

         lrucache, the autowarmed items will be the most recently  

         accessed items.  

         parameters:  

           class - the solrcache implementation lrucache or  

               (lrucache or fastlrucache)  

           size - the maximum number of entries in the cache  

           initialsize - the initial capacity (number of entries) of  

               the cache.  (see java.util.hashmap)  

           autowarmcount - the number of entries to prepopulate from  

               and old cache.    

    <filtercache class="solr.fastlrucache"  

                 size="512"  

                 initialsize="512"  

                 autowarmcount="0"/>  

    <!-- query result cache  

         caches results of searches - ordered lists of document ids  

         (doclist) based on a query, a sort, and the range of documents requested.    

    <queryresultcache class="solr.lrucache"  

                     size="512"  

                     initialsize="512"  

                     autowarmcount="0"/>  

    <!-- document cache  

         caches lucene document objects (the stored fields for each  

         document).  since lucene internal document ids are transient,  

         this cache will not be autowarmed.    

    <documentcache class="solr.lrucache"  

                   size="512"  

                   initialsize="512"  

                   autowarmcount="0"/>  

    <!-- custom cache currently used by block join -->   

    <cache name="persegfilter"  

      class="solr.search.lrucache"  

      size="10"  

      initialsize="0"  

      autowarmcount="10"  

      regenerator="solr.noopregenerator" />  

    <!-- lazy field loading  

         if true, stored fields that are not requested will be loaded  

         lazily.  this can result in a significant speed improvement  

         if the usual case is to not load all stored fields,  

         especially if the skipped fields are large compressed text  

         fields.  

    <enablelazyfieldloading>true</enablelazyfieldloading>  

   <!-- result window size  

        an optimization for use with the queryresultcache.  when a search  

        is requested, a superset of the requested number of document ids  

        are collected.  for example, if a search for a particular query  

        requests matching documents 10 through 19, and querywindowsize is 50,  

        then documents 0 through 49 will be collected and cached.  any further  

        requests in that range can be satisfied via the cache.    

     -->  

   <queryresultwindowsize>20</queryresultwindowsize>  

   <!-- maximum number of documents to cache for any entry in the  

        queryresultcache.   

   <queryresultmaxdocscached>200</queryresultmaxdocscached>  

    <!-- use cold searcher  

         if a search request comes in and there is no current  

         registered searcher, then immediately register the still  

         warming searcher and use it.  if "false" then all requests  

         will block until the first searcher is done warming.  

    <usecoldsearcher>false</usecoldsearcher>  

    <!-- max warming searchers  

         maximum number of searchers that may be warming in the  

         background concurrently.  an error is returned if this limit  

         is exceeded.  

         recommend values of 1-2 for read-only slaves, higher for  

         masters w/o cache warming.  

    <maxwarmingsearchers>2</maxwarmingsearchers>  

  </query>  

  <!-- request dispatcher  

       this section contains instructions for how the solrdispatchfilter  

       should behave when processing requests for this solrcore.  

       handleselect is a legacy option that affects the behavior of requests  

       such as /select?qt=xxx  

       handleselect="true" will cause the solrdispatchfilter to process  

       the request and dispatch the query to a handler specified by the   

       "qt" param, assuming "/select" isn't already registered.  

       handleselect="false" will cause the solrdispatchfilter to  

       ignore "/select" requests, resulting in a 404 unless a handler  

       is explicitly registered with the name "/select"  

       handleselect="true" is not recommended for new users, but is the default  

       for backwards compatibility  

  <requestdispatcher handleselect="false" >  

    <!-- request parsing  

         these settings indicate how solr requests may be parsed, and  

         what restrictions may be placed on the contentstreams from  

         those requests  

         enableremotestreaming - enables use of the stream.file  

         and stream.url parameters for specifying remote streams.  

         multipartuploadlimitinkb - specifies the max size (in kib) of  

         multipart file uploads that solr will allow in a request.  

         formdatauploadlimitinkb - specifies the max size (in kib) of  

         form data (application/x-www-form-urlencoded) sent via  

         post. you can use post to pass request parameters not  

         fitting into the url.  

         addhttprequesttocontext - if set to true, it will instruct  

         the requestparsers to include the original httpservletrequest  

         object in the context map of the solrqueryrequest under the   

         key "httprequest". it will not be used by any of the existing  

         solr components, but may be useful when developing custom   

         plugins.  

         *** warning ***  

         the settings below authorize solr to fetch remote files, you  

         should make sure your system has some authentication before  

         using enableremotestreaming="true"  

      -->   

    <requestparsers enableremotestreaming="true"   

                    multipartuploadlimitinkb="2048000"  

                    formdatauploadlimitinkb="2048"  

                    addhttprequesttocontext="false"/>  

    <!-- http caching  

         set http caching related parameters (for proxy caches and clients).  

         the options below instruct solr not to output any http caching  

         related headers  

    <httpcaching never304="true" />  

  </requestdispatcher>  

  <!-- request handlers   

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

       incoming queries will be dispatched to a specific handler by name  

       based on the path specified in the request.  

       legacy behavior: if the request path uses "/select" but no request  

       handler has that name, and if handleselect="true" has been specified in  

       the requestdispatcher, then the request handler is dispatched based on  

       the qt parameter.  handlers without a leading '/' are accessed this way  

       like so: http://host/app/[core/]select?qt=name  if no qt is  

       given, then the requesthandler that declares default="true" will be  

       used or the one named "standard".  

       if a request handler is declared with startup="lazy", then it will  

       not be initialized until the first request that uses it.  

  <!-- searchhandler  

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

       for processing search queries, the primary request handler  

       provided with solr is "searchhandler" it delegates to a sequent  

       of searchcomponents (see below) and supports distributed  

       queries across multiple shards  

  <!--  

  <requesthandler name="/dataimport" class="solr.dataimporthandler">  

    <lst name="defaults">  

      <str name="config">solr-data-config.xml</str>  

    </lst>  

  </requesthandler>  

      <str name="config">data-config.xml</str>  

  <requesthandler name="/select" class="solr.searchhandler">  

    <!-- default values for query parameters can be specified, these  

         will be overridden by parameters in the request  

     <lst name="defaults">  

       <str name="echoparams">explicit</str>  

       <int name="rows">10</int>  

     </lst>  

    </requesthandler>  

  <!-- a request handler that returns indented json by default -->  

  <requesthandler name="/query" class="solr.searchhandler">  

       <str name="wt">json</str>  

       <str name="indent">true</str>  

       <str name="df">text</str>  

    the export request handler is used to export full sorted result sets.  

    do not change these defaults.  

  <requesthandler name="/export" class="solr.searchhandler">  

    <lst name="invariants">  

      <str name="rq">{!xport}</str>  

      <str name="wt">xsort</str>  

      <str name="distrib">false</str>  

    <arr name="components">  

      <str>query</str>  

    </arr>  

  <initparams path="/update/**,/query,/select,/tvrh,/elevate,/spell">  

      <str name="df">text</str>  

  </initparams>  

  <!-- field analysis request handler  

       requesthandler that provides much the same functionality as  

       analysis.jsp. provides the ability to specify multiple field  

       types and field names in the same request and outputs  

       index-time and query-time analysis for each of them.  

       request parameters are:  

       analysis.fieldname - field name whose analyzers are to be used  

       analysis.fieldtype - field type whose analyzers are to be used  

       analysis.fieldvalue - text for index-time analysis  

       q (or analysis.q) - text for query time analysis  

       analysis.showmatch (true|false) - when set to true and when  

           query analysis is performed, the produced tokens of the  

           field value analysis will be marked as "matched" for every  

           token that is produces by the query analysis  

   -->  

  <requesthandler name="/analysis/field"   

                  startup="lazy"  

                  class="solr.fieldanalysisrequesthandler" />  

  <!-- document analysis handler  

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

       an analysis handler that provides a breakdown of the analysis  

       process of provided documents. this handler expects a (single)  

       content stream with the following format:  

       <docs>  

         <doc>  

           <field name="id">1</field>  

           <field name="name">the name</field>  

           <field name="text">the text value</field>  

         </doc>  

         <doc>...</doc>  

         ...  

       </docs>  

    note: each document must contain a field which serves as the  

    unique key. this key is used in the returned response to associate  

    an analysis breakdown to the analyzed document.  

    like the fieldanalysisrequesthandler, this handler also supports  

    query analysis by sending either an "analysis.query" or "q"  

    request parameter that holds the query text to be analyzed. it  

    also supports the "analysis.showmatch" parameter which when set to  

    true, all field tokens that match the query tokens will be marked  

    as a "match".   

  <requesthandler name="/analysis/document"   

                  class="solr.documentanalysisrequesthandler"   

                  startup="lazy" />  

  <!-- echo the request contents back to the client -->  

  <requesthandler name="/debug/dump" class="solr.dumprequesthandler" >  

     <str name="echoparams">explicit</str>   

     <str name="echohandler">true</str>  

  <!-- search components  

       search components are registered to solrcore and used by   

       instances of searchhandler (which can access them by name)  

       by default, the following components are available:  

       <searchcomponent name="query"     class="solr.querycomponent" />  

       <searchcomponent name="facet"     class="solr.facetcomponent" />  

       <searchcomponent name="mlt"       class="solr.morelikethiscomponent" />  

       <searchcomponent name="highlight" class="solr.highlightcomponent" />  

       <searchcomponent name="stats"     class="solr.statscomponent" />  

       <searchcomponent name="debug"     class="solr.debugcomponent" />  

  <!-- terms component  

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

       a component to return terms and document frequency of those  

       terms  

  <searchcomponent name="terms" class="solr.termscomponent"/>  

  <!-- a request handler for demonstrating the terms component -->  

  <requesthandler name="/terms" class="solr.searchhandler" startup="lazy">  

      <bool name="terms">true</bool>  

      <bool name="distrib">false</bool>  

    </lst>       

      <str>terms</str>  

  <!-- legacy config for the admin interface -->  

  <admin>  

    <defaultquery>*:*</defaultquery>  

  </admin>  

</config>  

 下面我将对其中关键地方加以解释说明:

 lib

<lib> 标签指令可以用来告诉solr如何去加载solr plugins(solr插件)依赖的jar包,在solrconfig.xml配置文件的注释中有配置示例,例如:

<lib dir="./lib" regex=”lucene-\w+\.jar”/>

这里的dir表示一个jar包目录路径,该目录路径是相对于你当前core根目录的;regex表示一个正则表达式,用来过滤文件名的,符合正则表达式的jar文件将会被加载

datadir parameter

用来指定一个solr的索引数据目录,solr创建的索引会存放在data\index目录下,默认datadir是相对于当前core目录(如果solr_home下存在core的话),如果solr_home下不存在core的话,那datadir默认就是相对于solr_home啦,不过一般datadir都在core.properties下配置。

     <datadir>/var/data/solr</datadir>

 用来设置lucene倒排索引的编码工厂类,默认实现是官方提供的schemacodecfactory类。

在solrconfig.xml的<indexconfig>标签中间有很多关于此配置项的说明:

<!-- maxfieldlength was removed in 4.0. to get similar behavior, include a

         limittokencountfilterfactory in your fieldtype definition. e.g.

     <filter class="solr.limittokencountfilterfactory" maxtokencount="10000"/>

提供我们maxfieldlength配置项已经从4.0版本开始就已经被移除了,可以使用配置一个filter达到相似的效果,maxtokencount即在对某个域分词的时候,最多只提取前10000个token,后续的域值将被抛弃。maxfieldlength若表示1000,则意味着只会对域值的0~1000范围内的字符串进行分词索引。

<writelocktimeout>1000</writelocktimeout>

writelocktimeout表示indexwriter实例在获取写锁的时候最大等待超时时间,超过指定的超时时间仍未获取到写锁,则indexwriter写索引操作将会抛出异常

<maxindexingthreads>8</maxindexingthreads>

表示创建索引的最大线程数,默认是开辟8个线程来创建索引

<usecompoundfile>false</usecompoundfile>

是否开启复合文件模式,启用了复合文件模式即意味着创建的索引文件数量会减少,这样占用的文件描述符也会减少,但这会带来性能的损耗,在lucene中,它默认是开启,而在solr中,自从3.6版本开始,默认就是禁用的

 <rambuffersizemb>100</rambuffersizemb>

表示创建索引时内存缓存大小,单位是mb,默认最大是100m,

<maxbuffereddocs>1000</maxbuffereddocs>

表示在document写入到硬盘之前,缓存的document最大个数,超过这个最大值会触发索引的flush操作。

跟益达学Solr5之solrconfig.xml配置详解

<mergepolicy class="org.apache.lucene.index.tieredmergepolicy">  

    <int name="maxmergeatonce">10</int>  

<int name="segmentspertier">10</int>  

</mergepolicy>  

 用来配置lucene索引段合并策略的,里面有两个参数:

maxmergeatone: 一次最多合并段个数

segmentpertier:  每个层级的段个数,同时也是内存buffer递减的等比数列的公比,看源码:

跟益达学Solr5之solrconfig.xml配置详解

// compute max allowed segs in the index  

    long levelsize = minsegmentbytes;  

    long bytesleft = totindexbytes;  

    double allowedsegcount = 0;  

    while(true) {  

      final double segcountlevel = bytesleft / (double) levelsize;  

      if (segcountlevel < segspertier) {  

        allowedsegcount += math.ceil(segcountlevel);  

        break;  

      }  

      allowedsegcount += segspertier;  

      bytesleft -= segspertier * levelsize;  

      levelsize *= maxmergeatonce;  

    }  

int allowedsegcountint = (int) allowedsegcount;  

 <mergefactor>10</mergefactor>

要理解mergefactor因子的含义,还是先看看lucene in action中给出的解释:

跟益达学Solr5之solrconfig.xml配置详解

indexwriter’s mergefactor lets you control how many documents to store in memory  

before writing them to the disk, as well as how often to merge multiple index  

segments together. (index segments are covered in appendix b.) with the default  

value of 10, lucene stores 10 documents in memory before writing them to a single  

segment on the disk. the mergefactor value of 10 also means that once the  

number of segments on the disk has reached the power of 10, lucene merges  

these segments into a single segment.  

for instance, if you set mergefactor to 10, a new segment is created on the disk  

for every 10 documents added to the index. when the tenth segment of size 10 is  

added, all 10 are merged into a single segment of size 100. when 10 such segments  

of size 100 have been added, they’re merged into a single segment containing  

1,000 documents, and so on. therefore, at any time, there are no more than 9  

segments in the index, and the size of each merged segment is the power of 10.  

there is a small exception to this rule that has to do with maxmergedocs,  

another indexwriter instance variable: while merging segments, lucene ensuresthat no segment with more than maxmergedocs documents is created. for instance,  

suppose you set maxmergedocs to 1,000. when you add the ten-thousandth document,  

instead of merging multiple segments into a single segment of size 10,000,  

lucene creates the tenth segment of size 1,000 and keeps adding new segments  

of size 1,000 for every 1,000 documents added.  

 indexwriter的mergefactory允许你来控制索引在写入磁盘之前内存中能缓存的document数量,以及合并

多个段文件的频率。默认这个值为10. 当往内存中存储了10个document,此时lucene还没有把单个段文件

写入磁盘,mergefactor值等于10也意味着当硬盘上的段文件数量达到10,lucene将会把这10个段文件合

并到一个段文件中。例如:如果你把mergefactor设置为10,当你往索引中添加了10个document,一个段

文件将会在硬盘上被创建,当第10个段文件被添加时,这10个段文件就会被合并到1个段文件,此时这个

段文件中有100个document,当10个这样的包含了100个document的段文件被添加时,他们又会被合并到一

个新的段文件中,而此时这个段文件包含 1000个document,以此类推。所以,在任何时候,在索引中不

存在超过9个段文件。每个被合并的段文件包含的document个数都是10,但这样有点小问题,我们还必须

 设置一个maxmergedocs变量,当合并段文件的时候,lucene必须确保没有哪个段文件超过maxmergedocs

 变量规定的最大document数量。设置maxmergedocs的目的是为了防止单个段文件中包含的document数量

过大,假定你把maxmergedocs设置为1000,当你创建第10个包含1000个document段文件的时候,这时并

 不会触发段文件合并(如果没有设置maxmergedocs为100的话,按理来说,这10个包含了1000个document

的段文件将会被合并到一个包含了10000个document的段文件当中,但maxmergedocs限制了单个段文件中

最多包含1000个document,所以此时并不会触发段合并操作)。影响段合并还有一些其他参数,比如:

mergefactor:当大小几乎相当的段的数量达到此值的时候,开始合并。

minmergesize:所有大小小于此值的段,都被认为是大小几乎相当,一同参与合并。

maxmergesize:当一个段的大小大于此值的时候,就不再参与合并。

maxmergedocs:当一个段包含的文档数大于此值的时候,就不再参与合并。

段合并分两个步骤:

 1.首先筛选出哪些段需要合并,这一步由mergepolicy合并策略类来决定

2.然后就是真正的段合并过程了,这一步是交给mergescheduler来完成的,mergescheduler类主要做两件事:

      a.对存储域,项向量,标准化因子即norms等信息进行合并

      b.对倒排索引信息进行合并

     尼玛扯远了,接着继续我们的solrconfig.xml中影响索引创建的一些参数配置;

<mergescheduler class="org.apache.lucene.index.concurrentmergescheduler"/>

mergescheduler刚才提到过了,这是用来配置段合并操作的处理类。默认实现类是lucene中自带的concurrentmergescheduler。

<locktype>${solr.lock.type:native}</locktype>

这个是用来指定lucene中lockfactory实现的,可配置项如下:

跟益达学Solr5之solrconfig.xml配置详解

single = singleinstancelockfactory - suggested for a  

 single:表示只读锁,没有另外一个处理线程会去修改索引数据

native:即lucene中的nativefslockfactory实现,使用的是基于操作系统的本地文件锁

simple:即lucene中的simplefslockfactory实现,通过在硬盘上创建write.lock锁文件实现

defaults:从solr3.6版本开始,这个默认值是native,否则,默认值就是simple,意思就是说,你如果配置为defaults,到底使用哪种锁实现,取决于你当前使用的solr版本。

<unlockonstartup>false</unlockonstartup>

如果这个设置为true,那么在solr启动后,indexwriter和commit提交操作拥有的锁将会被释放,这会打破lucene的锁机制,请谨慎使用。如果你的locktype设置为single,那么这个配置true or false都不会产生任何影响。

<deletionpolicy class="solr.solrdeletionpolicy">

用来配置索引删除策略的,默认使用的是solr的solrdeletionpolicy实现。如果你需要自定义删除策略,那么你需要实现lucene的org.apache.lucene.index.indexdeletionpolicy接口。

<jmx />

这个配置是用来在solr中启用jmx,有关这方面的详细信息,请移步到solr官方wiki,访问地址如下:

<a href="http://wiki.apache.org/solr/solrjmx">http://wiki.apache.org/solr/solrjmx</a>

&lt;updatehandler class="solr.directupdatehandler2"&gt;

指定索引更新操作处理类,directupdatehandler2是一个高性能的索引更新处理类,它支持软提交

&lt;updatelog&gt;

      &lt;str name="dir"&gt;${solr.ulog.dir:}&lt;/str&gt;

&lt;/updatelog&gt;

&lt;updatelog&gt;用来指定上面的updatehandler的处理事务日志存放路径的,默认值是solr的data目录即solr的datadir配置的目录。

&lt;query&gt;标签是有关索引查询相关的配置项

&lt;maxbooleanclauses&gt;1024&lt;/maxbooleanclauses&gt;

表示booleanquery最大能链接多少个子query,当不同的core下的solrconfig.xml中此配置项的参数值配置的不一样时,以最后一个初始化的core的配置为准。

&lt;filtercache class="solr.fastlrucache"

                 size="512"

                 initialsize="512"

                 autowarmcount="0"/&gt;

用来配置filter过滤器的缓存相关的参数

&lt;queryresultcache class="solr.lrucache"

                      size="512"

                      initialsize="512"

                      autowarmcount="0"/&gt;

用来配置对query返回的查询结果集即topdocs的缓存

&lt;documentcache class="solr.lrucache"

                   size="512"

                   initialsize="512"

                   autowarmcount="0"/&gt;

用来配置对document中存储域的缓存,因为每次从硬盘上加载存储域的值都是很昂贵的操作,这里说的存储域指的是那些store.yes的field,所以你懂的。

&lt;fieldvaluecache class="solr.fastlrucache"

                        size="512"

                        autowarmcount="128"

                        showitems="32" /&gt;

这个配置是用来缓存document id的,用来快速访问你的document id的。这个配置项默认就是开启的,无需显式配置。

&lt;cache name="myusercache"

              class="solr.lrucache"

              size="4096"

              initialsize="1024"

              autowarmcount="1024"

              regenerator="com.mycompany.myregenerator"

              /&gt;

这个配置是用来配置你的自定义缓存的,你自己的regenerator需要实现solr的cacheregenerator接口。

&lt;enablelazyfieldloading&gt;true&lt;/enablelazyfieldloading&gt;

表示启用存储域的延迟加载,前提是你的存储域在query的时候没有显式指定需要return这个域。

&lt;usefilterforsortedquery&gt;true&lt;/usefilterforsortedquery&gt;

表示当你的query没有使用score进行排序时,是否使用filter来替代query.

跟益达学Solr5之solrconfig.xml配置详解

&lt;listener event="newsearcher" class="solr.querysenderlistener"&gt;  

      &lt;arr name="queries"&gt;  

        &lt;!--  

           &lt;lst&gt;&lt;str name="q"&gt;solr&lt;/str&gt;&lt;str name="sort"&gt;price asc&lt;/str&gt;&lt;/lst&gt;  

           &lt;lst&gt;&lt;str name="q"&gt;rocks&lt;/str&gt;&lt;str name="sort"&gt;weight asc&lt;/str&gt;&lt;/lst&gt;  

          --&gt;  

      &lt;/arr&gt;  

&lt;/listener&gt;  

   querysenderlistener用来监听查询发送过程,即你可以在query请求发送之前追加一些请求参数,如上面给的示例中,可以追加qery关键字以及sort排序规则。

&lt;requestdispatcher handleselect="false" &gt;

这个select请求是为了兼容先前的旧版本,已经不推荐使用。

&lt;httpcaching never304="true" /&gt;

表示solr服务器段永远不返回304,那http响应状态码304表示什么呢?表示服务器端告诉客户端,你请求的资源尚未被修改过,我返回给你的是上次缓存的内容。never304即告诉服务器,不管我访问的资源有没有更新过,都给我重新返回不走http缓存。这属于http协议相关知识,不清楚的请去google http协议详细了解去。

跟益达学Solr5之solrconfig.xml配置详解

&lt;requesthandler name="/query" class="solr.searchhandler"&gt;  

      &lt;str name="echoparams"&gt;explicit&lt;/str&gt;  

      &lt;str name="wt"&gt;json&lt;/str&gt;  

      &lt;str name="indent"&gt;true&lt;/str&gt;  

其他的一些requesthandler说明就略过了,其实都大同小异,就是一个请求url跟请求处理类的一个映射,就好比springmvc中请求url和controller类的一个映射。

&lt;searchcomponent name="spellcheck" class="solr.spellcheckcomponent"&gt;

用来配置查询组件比如spellcheckcomponent拼写检查,有关拼写检查的详细配置说明留到以后说到spellcheck时再说吧。

&lt;searchcomponent name="terms" class="solr.termscomponent"/&gt;

用来返回所有的term以及每个document中term的出现频率

&lt;searchcomponent class="solr.highlightcomponent" name="highlight"&gt;

用来配置关键字高亮的,solr高亮配置的详细说明这里暂时先略过,这篇我们只是先暂时大致了解下每个配置项的含义即可,具体如何使用留到后续再深入研究。

有关searchcomponent查询组件的其他配置我就不一一说明了,太多了。你们自己看里面的英文注释吧,如果你实在看不懂再来问我。

跟益达学Solr5之solrconfig.xml配置详解

&lt;queryresponsewriter name="json" class="solr.jsonresponsewriter"&gt;  

    &lt;!-- for the purposes of the tutorial, json responses are written as  

     plain text so that they are easy to read in *any* browser.  

     if you expect a mime type of "application/json" just remove this override.  

    &lt;str name="content-type"&gt;text/plain; charset=utf-8&lt;/str&gt;  

&lt;/queryresponsewriter&gt;  

 这个是用来配置solr响应数据转换类,jsonresponsewriter就是把http响应数据转成json格式,content-type即response响应头信息中的content-type,即告诉客户端返回的数据的mime类型为text/plain,且charset字符集编码为utf-8.

内置的响应数据转换器还有velocity,xslt等,如果你想自定义一个基于freemarker的转换器,那你需要实现solr的queryresponsewriter接口,模仿其他实现类,你懂的,然后在solrconfig.xml中添加类似的&lt;queryresponsewriter配置即可

   最后需要说明下的是solrconfig.xml中有大量类似&lt;arr&gt; &lt;list&gt; &lt;str&gt; &lt;int&gt;这样的自定义标签,下面做个统一的说明:

跟益达学Solr5之solrconfig.xml配置详解

 这张图摘自于solr in action这本书,由于是英文的,所以我稍微解释下:

arr:即array的缩写,表示一个数组,name即表示这个数组参数的变量名

lst即list的缩写,但注意它里面存放的是key-value键值对

bool表示一个boolean类型的变量,name表示boolean变量名,

同理还有int,long,float,str等等

str即string的缩写,唯一要注意的是arr下的str子元素是没有name属性的,而list下的str元素是有name属性的

最后总结下:

solrconfig.xml中的配置项主要分以下几大块:

     1.依赖的lucene版本配置,这决定了你创建的lucene索引结构,因为lucene各版本之间的索引结构并不是完全兼容的,这个需要引起你的注意。

     2.索引创建相关的配置,如索引目录,indexwriterconfig类中的相关配置(它决定了你的索引创建性能)

     3.solrconfig.xml中依赖的外部jar包加载路径配置

     4.jmx相关配置

     5.缓存相关配置,缓存包括过滤器缓存,查询结果集缓存,document缓存,以及自定义缓存等等

     6.updatehandler配置即索引更新操作相关配置

     7.requesthandler相关配置,即接收客户端http请求的处理类配置

     8.查询组件配置如hightlight,spellchecker等等

     9.responsewriter配置即响应数据转换器相关配置,决定了响应数据是以什么样格式返回给客户端的。

     10.自定义valuesourceparser配置,用来干预document的权重、评分,排序

     solrconfig.xml就解释到这儿了,理解这些配置项是为后续solr学习扫清障碍。有些我没说到的或者我有意略过的,就留给你们自己去阅读和理解了,毕竟内容太多,1000多行的配置,一行不拉的解释完太耗时,有些都是类似的配置,我想你们应该能看懂。

  如果你还有什么问题请加我Q-q:7-3-6-0-3-1-3-0-5,

或者加裙

跟益达学Solr5之solrconfig.xml配置详解

一起交流学习!

转载:http://iamyida.iteye.com/blog/2211728