加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

指尖上的电商---(6)solrconfig.xml配置详解

发布时间:2020-12-16 08:37:16 所属栏目:百科 来源:网络整理
导读:solrconfig.xml配置文件主要定义了SOLR的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置。 可以在tomcat的安装路径下找到这个文件C:Program FilesApache Software FoundationTomcat 8.0solrcollection1conf 1.datadir节点 1.d

solrconfig.xml配置文件主要定义了SOLR的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置。

可以在tomcat的安装路径下找到这个文件C:Program FilesApache Software FoundationTomcat 8.0solrcollection1conf

1.datadir节点

1.<dataDir>${solr.data.dir:d:/Server/Solr/data}</dataDir>定义了索引数据和日志文件的存放位置

2.luceneMatchVersion

<luceneMatchVersion>4.8</luceneMatchVersion>

表示solr底层使用的是lucene4.8

3. lib

<libdir="../../../contrib/extraction/lib"regex=".*.jar"/>

表示solr引用包的位置,当dir对应的目录不存在时候,会忽略此属性

4.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时数据会丢失。且不支持索引复制

[html] view plain copy
  1. <directoryFactoryclass="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}"name="DirectoryFactory">
  2. strname="solr.hdfs.home">${solr.hdfs.home:}</str>
  3. strname="solr.hdfs.confdir">${solr.hdfs.confdir:}strname="solr.hdfs.blockcache.enabled">${solr.hdfs.blockcache.enabled:true}strname="solr.hdfs.blockcache.global">${solr.hdfs.blockcache.global:true}directoryFactory>

5. codecFactory
编解码工厂允许使用自定义的编解码器。例如:如果想启动per-field DocValues格式,可以在solrconfig.xml里面设置SchemaCodecFactory:
docValuesFormat="Lucene42": 这是默认设置,所有数据会被加载到堆内存中。
docValuesFormat="Disk": 这是另外一个实现,将部分数据存储在磁盘上。
docValuesFormat="SimpleText": 文本格式,非常慢,用于学习。

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

6.indexconfig节点

用于设置索引的低级别的属性

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

  18、 <infoStreamfile="INFOSTREAM.txt">false</infoStream>//相当于把创建索引时的日志输出。

<lockType>${solr.lock.type:native}</lockType>
设置索引库的锁方式,主要有三种:
1.single:适用于只读的索引库,即索引库是定死的,不会再更改
2.native:使用本地操作系统的文件锁方式,不能用于多个solr服务共用同一个索引库。Solr3.6 及后期版本使用的默认锁机制。
3.simple:使用简单的文件锁机制

7. updateHandler节点

定义更新处理器,

copy
updateLogstrname="dir">${solr.ulog.dir:} 设置索引库更新日志,默认路径为solr home下面的data/tlog。随着索引库的频繁更新,tlog文件会越来越大,

所以建议提交索引时采用硬提交方式<autoCommit>,即批量提交。

copy
autoCommitmaxTime>15000maxDocs>10000openSearcher>false 自动硬提交方式:maxTime:设置多长时间提交一次maxDocs:设置达到多少文档提交一次openSearcher:文档提交后是否开启新的searcher,

如果false,文档只是提交到index索引库,搜索结果中搜不到此次提交的文档;如果true,既提交到index索引库,也能在搜索结果中搜到此次提交的内容。

copy

updateHandlerclass="solr.DirectUpdateHandler2" <!--允许事务日志-->
  • <!--
  • 在满足一定条件时自动提交。maxDocs/maxTime/openSearcher
  • -->
  • <!--软提交VS硬提交-->
  • <!--
  • autoSoftCommit>1000 --
  • 更新相关事件监听器
  • postCommit-firedaftereverycommitoroptimizecommand
  • postOptimize-firedaftereveryoptimizecommand
  • <!--TheRunExecutableListenerexecutesanexternalcommandfroma
  • hooksuchaspostCommitorpostOptimize.
  • exe-thenameoftheexecutabletorun
  • dir-dirtouseasthecurrentworkingdirectory.(default=".")
  • wait-thecallingthreadwaitsuntiltheexecutablereturns.
  • (default="true")
  • args-theargumentstopasstotheprogram.(defaultisnone)
  • env-environmentvariablestoset.(defaultisnone)
  • --listenerevent="postCommit"class="solr.RunExecutableListener"strname="exe">solr/bin/snapshooter>.boolname="wait">trueboolarrname="args">>arg1>arg2arrarrname="env">MYVAR=val1listenerupdateHandler
    8.Query查询节点

    <maxBooleanClauses>1024</maxBooleanClauses>
    设置boolean 查询中,最大条件数。在范围搜索或者前缀搜索时,会产生大量的 boolean 条件,
    如果条件数达到这个数值时,将抛出异常,限制这个条件数,可以防止条件过多查询等待时间过长。

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

    copy

    filterCacheclass="solr.FastLRUCache"size="512"initialSize="512"autowarmCount="0"/>
  • queryResultCacheclass="solr.LRUCache"size="512"initialSize="512"autowarmCount="0"documentCacheclass="solr.LRUCache"size="512"initialSize="512"autowarmCount="0"queryResultMaxDocsCached>200maxWarmingSearchers>2
    9.Request Dispatcher

    请求转发器

    copy
    <!--RequestDispatcher
  • 主要是介绍当有请求访问SolrCore时SolrDispatchFilter如何处理。
  • handleSelect是一个以前版本中遗留下来的属性,会影响请求的对应行为(比如/select?qt=XXX)。
  • handleSelect="true"时导致SolrDispatchFilter将请求转发给qt指定的处理器(前提是/select已经注册)。
  • handleSelect="false"时会直接访问/select,若/select未注册则为404。
  • requestDispatcherhandleSelect="false" <!--RequestParsing:请求解析
  • 这些设置说明SolrRequests如何被解析,以及对ContentStreams有什么限制。
  • enableRemoteStreaming-是否允许使用stream.file和stream.url参数来指定远程streams。
  • multipartUploadLimitInKB-指定多文件上传时Solr允许的最大的size。
  • formdataUploadLimitInKB-表单通过POST请求发送的最大size
  • requestParsersenableRemoteStreaming="true"
  • multipartUploadLimitInKB="2048000"
  • formdataUploadLimitInKB="2048"/>
  • <!--HTTPCaching
  • 设置HTTP缓存的相关参数。
  • httpCachingnever304="true" <!--
  • cacheControl>max-age=30,publichttpCachinghttpCachinglastModifiedFrom="openTime"
  • etagSeed="Solr"requestDispatcher
    10.requestHandler

    请求处理器

    copy

    <!--RequestHandlers
  • 输入的请求会通过请求中的路径被转发到特定的处理器。
  • <!--SearchHandler
  • 基本的请求处理器是SearchHandler,它提供一系列SearchComponents。
  • 通过multipleshards支持分布式。
  • requestHandlername="/select"class="solr.SearchHandler"<!--可以指定默认值。-->
  • lstname="defaults"strname="echoParams">explicitintname="rows">10intstrname="df">textlst<!--添加属性-->
  • lstname="appends"strname="fq">inStock:true<!--用法同上,尽量不要使用。-->
  • lstname="invariants"strname="facet.field">cat>manu_exactstrname="facet.query">price:[*TO500]>price:[500TO*]<!--下面的配置可以重置SearchComponents-->
  • arrname="components">nameOfCustomComponent1>nameOfCustomComponent2requestHandler

    如果想更深入了解,可以参考下这几篇文章,

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

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

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

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    • 推荐文章
        热点阅读