solrconfig.xml配置詳解

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

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

       1.datadir節點 linux

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

       

     2.luceneMatchVersion windows

             <luceneMatchVersion>4.8</luceneMatchVersion> 緩存

          表示solr底層使用的是lucene4.8 tomcat

      3. lib 服務器

            <lib dir="../../../contrib/extraction/lib"regex=".*\.jar"/> 多線程

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

 

      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時數據會丟失。且不支持索引複製

 

[html] view plain copy 在CODE上查看代碼片 派生到個人代碼片
  1. <directoryFactory class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}" name="DirectoryFactory">  
  2.    <str name="solr.hdfs.home">${solr.hdfs.home:}</str>  
  3.    <str name="solr.hdfs.confdir">${solr.hdfs.confdir:}</str>  
  4.    <str name="solr.hdfs.blockcache.enabled">${solr.hdfs.blockcache.enabled:true}</str>  
  5.    <str name="solr.hdfs.blockcache.global">${solr.hdfs.blockcache.global:true}</str>  
  6. </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節點

           定義更新處理器,

[html] view plain copy 在CODE上查看代碼片 派生到個人代碼片
  1. <updateLog>  
  2.  <str name="dir">${solr.ulog.dir:}</str>  
  3.  </updateLog>  

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

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

[html] view plain copy 在CODE上查看代碼片 派生到個人代碼片
  1. <autoCommit>  
  2.  <maxTime>15000</maxTime>  
  3.  <maxDocs>10000</maxDocs>  
  4.  <openSearcher>false</openSearcher>  
  5.  </autoCommit>  

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

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

                  

[html] view plain copy 在CODE上查看代碼片 派生到個人代碼片
  1. <updateHandler class="solr.DirectUpdateHandler2">  
  2.     <!-- 容許事務日誌  -->   
  3.     <updateLog>  
  4.       <str name="dir">${solr.ulog.dir:}</str>  
  5.     </updateLog>  
  6.   
  7.     <!--  
  8.    在知足必定條件時自動提交。maxDocs/maxTime/openSearcher 
  9.       -->  
  10.      <autoCommit>   
  11.        <maxTime>15000</maxTime>   
  12.        <openSearcher>false</openSearcher>   
  13.      </autoCommit>  
  14.   
  15.     <!-- 軟提交VS硬提交 -->  
  16.      <!--  
  17.       <autoSoftCommit>   
  18.          <maxTime>1000</maxTime>   
  19.        </autoSoftCommit>  
  20.       -->  
  21.   
  22.     <!--   
  23.        更新相關事件監聽器  
  24.         postCommit - fired after every commit or optimize command  
  25.          postOptimize - fired after every optimize command  
  26.       -->  
  27.     <!-- The RunExecutableListener executes an external command from a  
  28.          hook such as postCommit or postOptimize.  
  29.          exe - the name of the executable to run  
  30.          dir - dir to use as the current working directory. (default=".")  
  31.          wait - the calling thread waits until the executable returns.   
  32.                 (default="true")  
  33.          args - the arguments to pass to the program.  (default is none)  
  34.          env - environment variables to set.  (default is none)  
  35.       -->  
  36.     <!--  
  37.       <listener event="postCommit" class="solr.RunExecutableListener">  
  38.          <str name="exe">solr/bin/snapshooter</str>  
  39.          <str name="dir">.</str>  
  40.          <bool name="wait">true</bool>  
  41.          <arr name="args"> <str>arg1</str> <str>arg2</str> </arr>  
  42.          <arr name="env"> <str>MYVAR=val1</str> </arr>  
  43.        </listener>  
  44.       -->  
  45.   
  46.  </updateHandler>  


                 8.Query查詢節點

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

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

                         

[html] view plain copy 在CODE上查看代碼片 派生到個人代碼片
  1. <filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0"/>  
  2.   
  3. <queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0"/>  
  4.   
  5. <documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0"/>  
  6.   
  7. <queryResultMaxDocsCached>200</queryResultMaxDocsCached>  
  8.   
  9. <maxWarmingSearchers>2</maxWarmingSearchers>  


                9.Request Dispatcher

                        請求轉發器

 

           

[html] view plain copy 在CODE上查看代碼片 派生到個人代碼片
  1. <!-- Request Dispatcher  
  2.      主要是介紹當有請求訪問SolrCore時SolrDispatchFilter如何處理。  
  3.     handleSelect是一個之前版本中遺留下來的屬性,會影響請求的對應行爲(好比/select?qt=XXX)。  
  4.     當handleSelect="true"時致使SolrDispatchFilter將請求轉發給qt指定的處理器(前提是/select已經註冊)。  
  5.     當handleSelect="false"時會直接訪問/select,若/select未註冊則爲404。  
  6.     -->  
  7.    <requestDispatcher handleSelect="false" >  
  8.   
  9.      <!-- Request Parsing:請求解析  
  10.         這些設置說明Solr Requests如何被解析,以及對ContentStreams有什麼限制。  
  11.   
  12.          enableRemoteStreaming - 是否容許使用stream.file和stream.url參數來指定遠程streams。  
  13.   
  14.          multipartUploadLimitInKB - 指定多文件上傳時Solr容許的最大的size。  
  15.   
  16.          formdataUploadLimitInKB - 表單經過POST請求發送的最大size  
  17.        -->   
  18.      <requestParsers enableRemoteStreaming="true"  
  19.                      multipartUploadLimitInKB="2048000"  
  20.                      formdataUploadLimitInKB="2048"/>  
  21.   
  22.      <!-- HTTP Caching  
  23.          設置HTTP緩存的相關參數。  
  24.       -->  
  25.      <httpCaching never304="true" />  
  26.   
  27.      <!--  
  28.        <httpCaching never304="true" >  
  29.           <cacheControl>max-age=30, public</cacheControl>   
  30.         </httpCaching>  
  31.        -->  
  32.   
  33.      <!--  
  34.        <httpCaching lastModifiedFrom="openTime"  
  35.                      etagSeed="Solr">  
  36.           <cacheControl>max-age=30, public</cacheControl>   
  37.         </httpCaching>  
  38.        -->  
  39.    </requestDispatcher>  


         10.requestHandler

                          請求處理器

 

           

[html] view plain copy 在CODE上查看代碼片 派生到個人代碼片
  1. <!-- Request Handlers   
  2.      輸入的請求會經過請求中的路徑被轉發到特定的處理器。  
  3.     -->  
  4.    <!-- SearchHandler  
  5.      基本的請求處理器是SearchHandler,它提供一系列SearchComponents。  
  6.     經過multiple shards支持分佈式。  
  7.     -->  
  8.    <requestHandler name="/select" class="solr.SearchHandler">  
  9.      <!-- 能夠指定默認值。-->  
  10.       <lst name="defaults">  
  11.         <str name="echoParams">explicit</str>  
  12.         <int name="rows">10</int>  
  13.         <str name="df">text</str>  
  14.       </lst>  
  15.      <!-- 添加屬性 -->  
  16.      <!--  
  17.        <lst name="appends">  
  18.           <str name="fq">inStock:true</str>  
  19.         </lst>  
  20.        -->  
  21.   
  22.      <!-- 用法同上,儘可能不要使用。-->  
  23.      <!--  
  24.        <lst name="invariants">  
  25.           <str name="facet.field">cat</str>  
  26.           <str name="facet.field">manu_exact</str>  
  27.           <str name="facet.query">price:[* TO 500]</str>  
  28.           <str name="facet.query">price:[500 TO *]</str>  
  29.         </lst>  
  30.        -->  
  31.      <!-- 下面的配置能夠重置SearchComponents-->  
  32.      <!--  
  33.        <arr name="components">  
  34.           <str>nameOfCustomComponent1</str>  
  35.           <str>nameOfCustomComponent2</str>  
  36.         </arr>  
  37.        -->  
  38.      </requestHandler>  


 

 

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

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

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

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

相關文章
相關標籤/搜索