solrconfig.xml配置詳解

solrconfig.xml配置文件主要定義了SOLR的一些處理規則,包括索引數據的存放位置,更新,刪除,查詢的一些規則配置。html

      能夠在tomcat的安裝路徑下找到這個文件C:\Program Files\Apache Software Foundation\Tomcat 8.0\solr\collection1\conflinux

       1.datadir節點apache

         1.<dataDir>${solr.data.dir:d:/Server/Solr/data}</dataDir>定義了索引數據和日誌文件的存放位置      
windows

     2.luceneMatchVersion緩存

             <luceneMatchVersion>4.8</luceneMatchVersion>tomcat

          表示solr底層使用的是lucene4.8服務器

      3. lib多線程

            <lib dir="../../../contrib/extraction/lib"regex=".*\.jar"/>app

         表示solr引用包的位置,當dir對應的目錄不存在時候,會忽略此屬性
分佈式

      4.directoryFactory

          索引存儲方案,共有如下存儲方案

           一、solr.StandardDirectoryFactory,這是一個基於文件系統存儲目錄的工廠,它會試圖選擇最好的實現基於你當前的操做系統和Java虛擬機版本。
           二、solr.SimpleFSDirectoryFactory,適用於小型應用程序,不支持大數據和多線程。
           三、solr.NIOFSDirectoryFactory,適用於多線程環境,可是不適用在windows平臺(很慢),是由於JVM還存在bug。
           四、solr.MMapDirectoryFactory,這個是solr3.1到4.0版本在linux64位系統下默認的實現。它是經過使用虛擬內存和內核特性調用

             mmap去訪問存儲在磁盤中的索引文件。它容許lucene或solr直接訪問I/O緩存。若是不須要近實時搜索功能,使用此工廠是個不錯的方案。
           五、solr.NRTCachingDirectoryFactory,此工廠設計目的是存儲部分索引在內存中,從而加快了近實時搜索的速度。
           六、solr.RAMDirectoryFactory,這是一個內存存儲方案,不能持久化存儲,在系統重啓或服務器crash時數據會丟失。且不支持索引複製

 

<directoryFactory class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}" name="DirectoryFactory">
   <str name="solr.hdfs.home">${solr.hdfs.home:}</str>
   <str name="solr.hdfs.confdir">${solr.hdfs.confdir:}</str>
   <str name="solr.hdfs.blockcache.enabled">${solr.hdfs.blockcache.enabled:true}</str>
   <str name="solr.hdfs.blockcache.global">${solr.hdfs.blockcache.global:true}</str>
</directoryFactory>


             5. codecFactory
                   編解碼工廠容許使用自定義的編解碼器。例如:若是想啓動per-field DocValues格式, 能夠在solrconfig.xml裏面設置SchemaCodecFactory:
                    docValuesFormat="Lucene42": 這是默認設置,全部數據會被加載到堆內存中。
          docValuesFormat="Disk": 這是另一個實現,將部分數據存儲在磁盤上。
          docValuesFormat="SimpleText": 文本格式,很是慢,用於學習。

                  <codecFactory class="solr.SchemaCodecFactory"/>
                  <schemaFactory class="ClassicIndexSchemaFactory"/>

            6.indexconfig節點

                 用於設置索引的低級別的屬性

      一、<filter class="solr.LimitTokenCountFilterFactory" maxTokenCount="10000"/>//限制token最大長度
      二、<writeLockTimeout>1000</writeLockTimeout>//IndexWriter等待解鎖的最長時間(毫秒)。
      三、<maxIndexingThreads>8</maxIndexingThreads>//
      四、<useCompoundFile>false</useCompoundFile>//solr默認爲false。若是爲true,索引文件減小,檢索性能下降,追求平衡。
      五、<ramBufferSizeMB>100</ramBufferSizeMB>//緩存
      六、<maxBufferedDocs>1000</maxBufferedDocs>//同上。兩個同時定義時命中較低的那個。
      七、<mergePolicy class="org.apache.lucene.index.TieredMergePolicy">
         <int name="maxMergeAtOnce">10</int>
          <int name="segmentsPerTier">10</int>
         </mergePolicy>
          //合併策略。
      八、<mergeFactor>10</mergeFactor>//合併因子,每次合併多少個segments。
      九、<mergeScheduler class="org.apache.lucene.index.ConcurrentMergeScheduler"/>//合併調度器。
     十、<lockType>${solr.lock.type:native}</lockType>//鎖工廠。
     十一、<unlockOnStartup>false</unlockOnStartup>//是否啓動時先解鎖。
     十二、<termIndexInterval>128</termIndexInterval>//Lucene loads terms into memory 間隔
     1三、<reopenReaders>true</reopenReaders>//從新打開,替代先關閉-再打開。
     1四、<deletionPolicy class="solr.SolrDeletionPolicy">//提交刪除策略,必須實現org.apache.lucene.index.IndexDeletionPolicy
     1五、<str name="maxCommitsToKeep">1</str>
     1六、<str name="maxOptimizedCommitsToKeep">0</str>
     1七、<str name="maxCommitAge">30MINUTES</str> OR <str name="maxCommitAge">1DAY</str><br>   

     1八、   <infoStream   file="INFOSTREAM.txt">false</infoStream>//至關於把建立索引時的日誌輸出。

      <lockType>${solr.lock.type:native}</lockType>
       設置索引庫的鎖方式,主要有三種:
        1.single:適用於只讀的索引庫,即索引庫是定死的,不會再更改
        2.native:使用本地操做系統的文件鎖方式,不能用於多個solr服務共用同一個索引庫。Solr3.6 及後期版本使用的默認鎖機制。
        3.simple:使用簡單的文件鎖機制

    7. updateHandler節點

           定義更新處理器,

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

                設置索引庫更新日誌,默認路徑爲solr home下面的data/tlog。隨着索引庫的頻繁更新,tlog文件會愈來愈大,

        因此建議提交索引時採用硬提交方式<autoCommit>,即批量提交。       

<autoCommit>  
 <maxTime>15000</maxTime>  
 <maxDocs>10000</maxDocs>  
 <openSearcher>false</openSearcher>  
 </autoCommit>

          自動硬提交方式:maxTime:設置多長時間提交一次maxDocs:設置達到多少文檔提交一次openSearcher:文檔提交後是否開啓新的searcher,

          若是false,文檔只是提交到index索引庫,搜索結果中搜不到這次提交的文檔;若是true,既提交到index索引庫,也能在搜索結果中搜到這次提交的內容。

<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>
      -->
exe--可執行的文件類型   
dir--能夠用該目錄作爲當前的工做目錄。默認爲"."   
wait--調用線程要等到可執行的返回值   
args--傳遞給程序的參數 默認nothing   
env--環境變量的設置 默認nothing 
 </updateHandler>


                 8.Query查詢節點

             <maxBooleanClauses>1024</maxBooleanClauses>
             設置boolean 查詢中,最大條件數。在範圍搜索或者前綴搜索時,會產生大量的 boolean 條件,
             若是條件數達到這個數值時,將拋出異常,限制這個條件數,能夠防止條件過多查詢等待時間過長。

                             緩存方法http://www.cnblogs.com/phinecos/archive/2012/05/24/2517018.html

  

<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"/>

<queryResultMaxDocsCached>200</queryResultMaxDocsCached>

<maxWarmingSearchers>2</maxWarmingSearchers>


                9.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>


         10.requestHandler

                          請求處理器

 

<!-- 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>

 

      若是想更深刻了解,能夠參考下這幾篇文章,

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

          http://www.yunvn.com/thread-15932-1-1.html 

          http://www.luoshengsha.com/197.html   

相關文章
相關標籤/搜索