Solr入门之(6)配置文件solrconfig.xml

solrconfig.xml包含了用于配置自身行为的绝大部分参数,其作用范围是当前core。该文件位于${solr_home}/solr/core1/conf/下。

参数列表概览

  A、lib
  B、dataDir parameter
  C、directoryFactory
  D、codecFactory
  E、indexConfig Section
  F、Update Handler Section
  G、The Query Section
  H、Request Dispatcher
  I、Request Handler Plug-in Section
  J、UpdateRequestProcessorChain section
  K、The Highlighter plugin configuration section
  L、The Admin/GUI Section
  M、System property substitution
  N、Enable/disable components
  O、XInclude
  P、Includes via Document Entities


一、lib:
  1、<lib/>标签用于加载solr所需要的jar包,从而支持solrconfig.xml 或者 schema.xml中定义的插件(例如:Analyzers,Request Handlers...)
  2、所有的路径都是相对路径,相对于当前实例文件夹${solr_home}/solr/core1
  3、在定义<lib/>时需要注意各个jar包之间的依赖,从而按照正确的顺序引入。例如:jar1依赖jar2,那么必须把jar2定义在jar1之前。
  4、如果存在"./lib"文件夹,将会默认将其中所有的jar包引入。类似于语法:<lib dir="./lib" />
  5、相当于把<lib/>中引用的所有jar包加入到了classpath中。
  6、当存在regex属性时,进行过滤。

  实例代码:

  <lib dir="../../../contrib/extraction/lib" regex=".*.jar" />
   <lib dir="../../../dist/" regex="solr-cell-d.*.jar" />
   <lib dir="/non/existent/dir/yields/warning" /> 

二、dataDir parameter
  solr默认将索引文件存放在${solr_home}/data目录下。而<dataDir>可以设置索引文件存放在任意指定的目录下。
  如果配置了replication,那么这里的定义需要与其匹配。

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

三、directoryFactory

  用于定义选择索引存储方案,directoryFactory总共有以下几种选择索引存储方案:

1、solr.StandardDirectoryFactory,这是一个基于文件系统存储目录的工厂,它会试图选择最好的实现基于你当前的操作系统和Java虚拟机版本。
2、solr.SimpleFSDirectoryFactory,适用于小型应用程序,不支持大数据和多线程。
3、solr.NIOFSDirectoryFactory,适用于多线程环境,但是不适用在windows平台(很慢),是因为JVM还存在bug。
4、solr.MMapDirectoryFactory,这个是solr3.1到4.0版本在linux64位系统下默认的实现。它是通过使用虚拟内存和内核特性调用mmap去访问存储在磁盘中的索引文件。它允许lucene或solr直接访问I/O缓存。如果不需要近实时搜索功能,使用此工厂是个不错的方案。
5、solr.NRTCachingDirectoryFactory,此工厂设计目的是存储部分索引在内存中,从而加快了近实时搜索的速度。
6、solr.RAMDirectoryFactory,这是一个内存存储方案,不能持久化存储,在系统重启或服务器crash时数据会丢失。且不支持索引复制。

四、codecFactory
  编解码工厂允许使用自定义的编解码器。例如:如果想启动per-field DocValues格式, 可以在solrconfig.xml里面设置SchemaCodecFactory:

<codecFactory class="solr.SchemaCodecFactory"/>

五、indexConfig Section
  该模块用于设置索引的低级别的属性。

     1、<filter class="solr.LimitTokenCountFilterFactory" maxTokenCount="10000"/>//限制token最大长度
	2、<writeLockTimeout>1000</writeLockTimeout>//IndexWriter等待解锁的最长时间(毫秒)。
	3、<maxIndexingThreads>8</maxIndexingThreads>//
	4、<useCompoundFile>false</useCompoundFile>//solr默认为false。如果为true,索引文件减少,检索性能降低,追求平衡。
	5、<ramBufferSizeMB>100</ramBufferSizeMB>//缓存
	6、<maxBufferedDocs>1000</maxBufferedDocs>//同上。两个同时定义时命中较低的那个。
	7、<mergePolicy class="org.apache.lucene.index.TieredMergePolicy">
          <int name="maxMergeAtOnce">10</int>
          <int name="segmentsPerTier">10</int>
        </mergePolicy>
		//合并策略。
	8、<mergeFactor>10</mergeFactor>//合并因子,每次合并多少个segments。
	9、<mergeScheduler class="org.apache.lucene.index.ConcurrentMergeScheduler"/>//合并调度器。
	10、<lockType>${solr.lock.type:native}</lockType>//锁工厂。
	11、<unlockOnStartup>false</unlockOnStartup>//是否启动时先解锁。
	12、<termIndexInterval>128</termIndexInterval>//Lucene loads terms into memory 间隔
	13、<reopenReaders>true</reopenReaders>//重新打开,替代先关闭-再打开。
	14、<deletionPolicy class="solr.SolrDeletionPolicy">//提交删除策略,必须实现org.apache.lucene.index.IndexDeletionPolicy
	15、<str name="maxCommitsToKeep">1</str>
	16、<str name="maxOptimizedCommitsToKeep">0</str>
	17、<str name="maxCommitAge">30MINUTES</str> OR <str name="maxCommitAge">1DAY</str>
     18、<infoStream file="INFOSTREAM.txt">false</infoStream>//相当于把创建索引时的日志输出。

六、Update Handler Section
该模块用于定义更新处理器。

 <updateHandler class="solr.DirectUpdateHandler2">
    <!-- 允许事务日志  --> 
    <updateLog>
      <str name="dir">${solr.ulog.dir:}</str>
    </updateLog>
 
    <!-- 
	在满足一定条件时自动提交。maxDocs/maxTime/openSearcher
      -->
     <autoCommit> 
       <maxTime>15000</maxTime> 
       <openSearcher>false</openSearcher> 
     </autoCommit>

    <!-- 软提交VS硬提交 -->
     <!--
       <autoSoftCommit> 
         <maxTime>1000</maxTime> 
       </autoSoftCommit>
      -->

    <!-- 
		更新相关事件监听器
         postCommit - fired after every commit or optimize command
         postOptimize - fired after every optimize command
      -->
    <!-- The RunExecutableListener executes an external command from a
         hook such as postCommit or postOptimize.
         exe - the name of the executable to run
         dir - dir to use as the current working directory. (default=".")
         wait - the calling thread waits until the executable returns. 
                (default="true")
         args - the arguments to pass to the program.  (default is none)
         env - environment variables to set.  (default is none)
      -->
    <!--
       <listener event="postCommit" class="solr.RunExecutableListener">
         <str name="exe">solr/bin/snapshooter</str>
         <str name="dir">.</str>
         <bool name="wait">true</bool>
         <arr name="args"> <str>arg1</str> <str>arg2</str> </arr>
         <arr name="env"> <str>MYVAR=val1</str> </arr>
       </listener>
      -->

  </updateHandler>

七、The Query Section
  该模块用于设置查询时的一些处理,涉及到solr的调优,后续分析。
  1、<maxBooleanClauses>1024</maxBooleanClauses>
  2、各种Cache的使用,详情参考博文http://www.cnblogs.com/phinecos/archive/2012/05/24/2517018.html
  3、<enableLazyFieldLoading>true</enableLazyFieldLoading>
  4、<useFilterForSortedQuery>true</useFilterForSortedQuery>
  5、<queryResultWindowSize>20</queryResultWindowSize>
  6、<queryResultMaxDocsCached>200</queryResultMaxDocsCached>
  7、<listener>
  8、<useColdSearcher>false</useColdSearcher>
  9、<maxWarmingSearchers>2</maxWarmingSearchers>

  示例代码:

<query>

    <filterCache class="solr.FastLRUCache"
                 size="512"
                 initialSize="512"
                 autowarmCount="0"/>
				 
    <queryResultCache class="solr.LRUCache"
                     size="512"
                     initialSize="512"
                     autowarmCount="0"/>
   
    <documentCache class="solr.LRUCache"
                   size="512"
                   initialSize="512"
                   autowarmCount="0"/>
    
    <!--
       <fieldValueCache class="solr.FastLRUCache"
                        size="512"
                        autowarmCount="128"
                        showItems="32" />
      -->

    <!--
       <cache name="myUserCache"
              class="solr.LRUCache"
              size="4096"
              initialSize="1024"
              autowarmCount="1024"
              regenerator="com.mycompany.MyRegenerator"
              />
      -->

    <enableLazyFieldLoading>true</enableLazyFieldLoading>

   <!--
      <useFilterForSortedQuery>true</useFilterForSortedQuery>
     -->

   <queryResultWindowSize>20</queryResultWindowSize>

   <queryResultMaxDocsCached>200</queryResultMaxDocsCached>

    <listener event="newSearcher" class="solr.QuerySenderListener">
      <arr name="queries">
        <!--
           <lst><str name="q">solr</str><str name="sort">price asc</str></lst>
           <lst><str name="q">rocks</str><str name="sort">weight asc</str></lst>
          -->
      </arr>
    </listener>
    <listener event="firstSearcher" class="solr.QuerySenderListener">
      <arr name="queries">
        <lst>
          <str name="q">static firstSearcher warming in solrconfig.xml</str>
        </lst>
      </arr>
    </listener>

    <useColdSearcher>false</useColdSearcher>

    <maxWarmingSearchers>2</maxWarmingSearchers>

  </query>

8、Request Dispatcher
  请求转发器。

<!-- Request Dispatcher
	主要是介绍当有请求访问SolrCore时SolrDispatchFilter如何处理。
	handleSelect是一个以前版本中遗留下来的属性,会影响请求的对应行为(比如/select?qt=XXX)。
	当handleSelect="true"时导致SolrDispatchFilter将请求转发给qt指定的处理器(前提是/select已经注册)。
	当handleSelect="false"时会直接访问/select,若/select未注册则为404。
    -->
  <requestDispatcher handleSelect="false" >
  	
    <!-- Request Parsing:请求解析
		这些设置说明Solr Requests如何被解析,以及对ContentStreams有什么限制。

         enableRemoteStreaming - 是否允许使用stream.file和stream.url参数来指定远程streams。

         multipartUploadLimitInKB - 指定多文件上传时Solr允许的最大的size。
         
         formdataUploadLimitInKB - 表单通过POST请求发送的最大size
      --> 
    <requestParsers enableRemoteStreaming="true" 
                    multipartUploadLimitInKB="2048000"
                    formdataUploadLimitInKB="2048"/>

    <!-- HTTP Caching
		设置HTTP缓存的相关参数。
      -->
    <httpCaching never304="true" />
	
    <!--
       <httpCaching never304="true" >
         <cacheControl>max-age=30, public</cacheControl> 
       </httpCaching>
      -->
	  
    <!--
       <httpCaching lastModifiedFrom="openTime"
                    etagSeed="Solr">
         <cacheControl>max-age=30, public</cacheControl> 
       </httpCaching>
      -->
  </requestDispatcher>

9、Request Handler Plug-in Section
  请求处理器插件模块,可以在这里定义各种请求处理器。

 A、第一个示例代码,后续中的参数设置与此相同:

<!-- Request Handlers 
	输入的请求会通过请求中的路径被转发到特定的处理器。
    -->
  <!-- SearchHandler
  	基本的请求处理器是SearchHandler,它提供一系列SearchComponents。
	通过multiple shards支持分布式。
    -->
  <requestHandler name="/select" class="solr.SearchHandler">
    <!-- 可以指定默认值。-->
     <lst name="defaults">
       <str name="echoParams">explicit</str>
       <int name="rows">10</int>
       <str name="df">text</str>
     </lst>
    <!-- 添加属性 -->
    <!--
       <lst name="appends">
         <str name="fq">inStock:true</str>
       </lst>
      -->
	  
    <!-- 用法同上,尽量不要使用。-->
    <!--
       <lst name="invariants">
         <str name="facet.field">cat</str>
         <str name="facet.field">manu_exact</str>
         <str name="facet.query">price:[* TO 500]</str>
         <str name="facet.query">price:[500 TO *]</str>
       </lst>
      -->
    <!-- 下面的配置可以重置SearchComponents-->
    <!--
       <arr name="components">
         <str>nameOfCustomComponent1</str>
         <str>nameOfCustomComponent2</str>
       </arr>
      -->
    </requestHandler>

10、UpdateRequestProcessorChain section
  此处暂时不做说明,后续补充。

  示例代码:

<!-- Update Processors --> 
  <!-- Deduplication -->
  <!---->
     <updateRequestProcessorChain name="dedupe">
       <processor class="solr.processor.SignatureUpdateProcessorFactory">
         <bool name="enabled">true</bool>
         <str name="signatureField">id</str>
         <bool name="overwriteDupes">false</bool>
         <str name="fields">name,features,cat</str>
         <str name="signatureClass">solr.processor.Lookup3Signature</str>
       </processor>
       <processor class="solr.LogUpdateProcessorFactory" />
       <processor class="solr.RunUpdateProcessorFactory" />
     </updateRequestProcessorChain>
    
  
  <!-- Language identification -->
    <!---->
     <updateRequestProcessorChain name="langid">
       <processor class="org.apache.solr.update.processor.TikaLanguageIdentifierUpdateProcessorFactory">
         <str name="langid.fl">text,title,subject,description</str>
         <str name="langid.langField">language_s</str>
         <str name="langid.fallback">en</str>
       </processor>
       <processor class="solr.LogUpdateProcessorFactory" />
       <processor class="solr.RunUpdateProcessorFactory" />
     </updateRequestProcessorChain>
    

  <!-- Script update processor -->
  <!-- -->
    <updateRequestProcessorChain name="script">
      <processor class="solr.StatelessScriptUpdateProcessorFactory">
        <str name="script">update-script.js</str>
        <lst name="params">
          <str name="config_param">example config parameter</str>
        </lst>
      </processor>
      <processor class="solr.RunUpdateProcessorFactory" />
    </updateRequestProcessorChain>

 11、Response Writers

   后续讨论,见名知意。

   实例代码:

 <!-- Response Writers 响应对象通过wt参数中指定的writer写回数据。-->
  <!--
     <queryResponseWriter name="xml" 
                          default="true"
                          class="solr.XMLResponseWriter" />
     <queryResponseWriter name="json" class="solr.JSONResponseWriter"/>
     <queryResponseWriter name="python" class="solr.PythonResponseWriter"/>
     <queryResponseWriter name="ruby" class="solr.RubyResponseWriter"/>
     <queryResponseWriter name="php" class="solr.PHPResponseWriter"/>
     <queryResponseWriter name="phps" class="solr.PHPSerializedResponseWriter"/>
     <queryResponseWriter name="csv" class="solr.CSVResponseWriter"/>
     <queryResponseWriter name="schema.xml" class="solr.SchemaXmlResponseWriter"/>
    -->

  <queryResponseWriter name="json" class="solr.JSONResponseWriter">
    <str name="content-type">text/plain; charset=UTF-8</str>
  </queryResponseWriter>
  
  <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" startup="lazy"/>
  
  <queryResponseWriter name="xslt" class="solr.XSLTResponseWriter">
    <int name="xsltCacheLifetimeSeconds">5</int>
  </queryResponseWriter>

 12、Query Parsers

<!-- Query Parsers -->
  <queryParser name="myparser" class="com.mycompany.MyQParserPlugin"/>

  <!-- Function Parsers
       Multiple ValueSourceParsers can be registered by name, and then
       used as function names when using the "func" QParser.
    -->
  <!-- example of registering a custom function parser  -->
  <valueSourceParser name="myfunc" 
                        class="com.mycompany.MyValueSourceParser" />
原文地址:https://www.cnblogs.com/tq03/p/3605413.html