指尖上的电商---(6)solrconfig.xml配置详解
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 <lib dir="../../../contrib/extraction/lib"regex=".*.jar"/> 表示solr引用包的位置,当dir对应的目录不存在时候,会忽略此属性
4.directoryFactory 索引存储方案,共有以下存储方案 1、solr.StandardDirectoryFactory,这是一个基于文件系统存储目录的工厂,它会试图选择最好的实现基于你当前的操作系统和Java虚拟机版本。 mmap去访问存储在磁盘中的索引文件。它允许lucene或solr直接访问I/O缓存。如果不需要近实时搜索功能,使用此工厂是个不错的方案。 <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 <codecFactory class="solr.SchemaCodecFactory"/> 6.indexconfig节点 用于设置索引的低级别的属性 1、<filter class="solr.LimitTokenCountFilterFactory" maxTokenCount="10000"/>//限制token最大长度 18、 <infoStreamfile="INFOSTREAM.txt">false</infoStream>//相当于把创建索引时的日志输出。 <lockType>${solr.lock.type:native}</lockType> 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> --> </updateHandler>
<maxBooleanClauses>1024</maxBooleanClauses>
<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>
请求转发器
<!-- 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>
请求处理器
<!-- 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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |