摘要 solrconfig.xml配置文件主要定义了Solr的一些处理规则,包括索引数据的存放位置,更新,删除,查询的一些规则配置。
luceneMatchVersion
<luceneMatchVersion>6.0.0</luceneMatchVersion>
表示Solr底层使用的是Lucene6
lib
<lib dir="./lib" />
<lib dir="${solr.install.dir:../../../..}/contrib/extraction/lib" regex=".*\.jar" />
定义了Solr需要额外引用的jar包位置,如果对应的文件不存在,会自动忽略这一配置,一般建议将其注释掉,只添加需要使用的jar包。
dataDir
<dataDir>${solr.data.dir:}</dataDir>
定义索引数据的存放位置。默认存放在solr home
的./data
目录下。
directoryFactory
<directoryFactory name="DirectoryFactory"
class="${solr.directoryFactory:solr.NRTCachingDirectoryFactory}">
<!-- These will be used if you are using the solr.HdfsDirectoryFactory,
otherwise they will be ignored. If you don't plan on using hdfs,
you can safely remove this section. -->
<!-- The root directory that collection data should be written to. -->
<str name="solr.hdfs.home">${solr.hdfs.home:}</str>
<!-- The hadoop configuration files to use for the hdfs client. -->
<str name="solr.hdfs.confdir">${solr.hdfs.confdir:}</str>
<!-- Enable/Disable the hdfs cache. -->
<str name="solr.hdfs.blockcache.enabled">${solr.hdfs.blockcache.enabled:true}</str>
<!-- Enable/Disable using one global cache for all SolrCores.
The settings used will be from the first HdfsDirectoryFactory created. -->
<str name="solr.hdfs.blockcache.global">${solr.hdfs.blockcache.global:true}</str>
</directoryFactory>
索引存储方案,默认使用的是近实时搜索NRT。
codecFactory
<codecFactory class="solr.SchemaCodecFactory"/>
编解码工厂允许使用自定义的编解码器。
indexConfig
<indexConfig>
<!-- 锁类型:single 只读索引;native 本地锁方式;simple 简单的文件锁机制 -->
<lockType>${solr.lock.type:native}</lockType>
<!-- 相当于把创建索引时的日志输出 -->
<infoStream>true</infoStream>
</indexConfig>
用于设置索引的低级别的属性。
updateHandler
<updateHandler class="solr.DirectUpdateHandler2">
<!-- 设置更新日志,默认存放于solr home的data/tlog目录下 -->
<updateLog>
<str name="dir">${solr.ulog.dir:}</str>
</updateLog>
<!-- 自动提交的设置 -->
<autoCommit>
<maxTime>${solr.autoCommit.maxTime:15000}</maxTime>
<!-- 文档提交以后是否开新的searcher -->
<openSearcher>false</openSearcher>
</autoCommit>
<autoSoftCommit>
<maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime>
</autoSoftCommit>
</updateHandler>
定义更新处理方式。DirectUpdateHandler2 是一个高性能的索引更新处理类,它支持软提交。参见solr近实时搜索
query
<query>
<!-- 最大条件查询条件个数。在范围搜索或者前缀搜索时,会产生大量的 boolean 条件,如果条件数达到这个数值时,将抛出异常,限制这个条件数,可以防止条件过多查询等待时间过长。-->
<maxBooleanClauses>1024</maxBooleanClauses>
<!-- 通过存储一个匹配给定查询的文档 id 的无序集,过滤器让 Solr 能够有效提高查询的性能。缓存这些过滤器意味着对Solr的重复调用可以导致结果集的快速查找。更常见的场景是缓存一个过滤器,然后再发起后续的精炼查询,这种查询能使用过滤器来限制要搜索的文档数。-->
<filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0"/>
<!-- 为查询、排序条件和所请求文档的数量缓存文档 id 的有序集合。-->
<queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0"/>
<!-- 缓存Lucene Document,使用内部Lucene文档id(以便不与Solr唯一id相混淆)。由于Lucene的内部Document id 可以因索引操作而更改,这种缓存不能自热。-->
<documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0"/>
<!-- 命名缓存是用户定义的缓存,可被 Solr定制插件 所使用。-->
<cache name="perSegFilter" class="solr.search.LRUCache" size="10" initialSize="0" autowarmCount="10" regenerator="solr.NoOpRegenerator" />
<!-- 如果应用程序只会检索Document上少数几个Field,那么可以将这个属性设置为true。懒散加载的一个常见场景大都发生在应用程序返回一些列搜索结果的时候,用户常常会单击其中的一个来查看存储在此索引中的原始文档。初始的现实常常只需要现实很短的一段信息。若是检索大型的Document,除非必需,否则就应该避免加载整个文档。-->
<enableLazyFieldLoading>true</enableLazyFieldLoading>
<queryResultWindowSize>20</queryResultWindowSize>
<queryResultMaxDocsCached>200</queryResultMaxDocsCached>
<!-- Solr可以使用事件来制定实例化新Searcher或第一个Searcher时,应该执行哪些查询。如果应用程序期望请求某些特定的查询,那么在创建新Searcher或第一个Searcher时就应该反注释这些部分并执行适当的查询。-->
<listener event="newSearcher" class="solr.QuerySenderListener">
<arr name="queries">
</arr>
</listener>
<useColdSearcher>false</useColdSearcher>
<maxWarmingSearchers>2</maxWarmingSearchers>
</query>
查询参数设置。
对于所有缓存模式而言,在设置缓存参数时,都有必要在内存、cpu和磁盘访问之间进行均衡。统计信息管理页(管理员界面的Statistics)对于分析缓存的 hit-to-miss 比例以及微调缓存大小的统计数据都非常有用。而且,并非所有应用程序都会从缓存受益。实际上,一些应用程序反而会由于需要将某个永远也用不到的条目存储在缓存中这一额外步骤而受到影响。
requestDispatcher
<requestDispatcher handleSelect="false" >
<!-- 这些设置说明Solr Requests如何被解析,以及对ContentStreams有什么限制。 -->
<requestParsers enableRemoteStreaming="true"
multipartUploadLimitInKB="2048000"
formdataUploadLimitInKB="2048"
addHttpRequestToContext="false"/>
<!-- 设置HTTP缓存的相关参数。Never304 即告诉服务器,不管我访问的资源有没有更新过,都给我重新返回不走 Http 缓存。-->
<httpCaching never304="true" />
</requestDispatcher>
定义当有请求访问Solr core时SolrDispatchFilter如何处理。
handleSelect是一个以前版本中遗留下来的属性,会影响请求的对应行为(比如/select?qt=XXX)。
当handleSelect=”true”时导致SolrDispatchFilter将请求转发给qt指定的处理器(前提是/select已经注册)。
当handleSelect=”false”时会直接访问/select,若/select未注册则为404。
requestHandler
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
</lst>
</requestHandler>
定义请求处理器行为。
这个 requestHandler 配置的是请求 URL /query 跟请求处理类 SearcherHandler 之间的一个映射关系,即你访问
http://localhost:8080/solr/core/query?q=xxx
时,会交给 SearcherHandler 类来处理这个 http 请求,你可以配置一些参数来干预 SearcherHandler 处理细节。
searchComponent
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">cat</str>
<str name="weightField">price</str>
<str name="suggestAnalyzerFieldType">string</str>
</lst>
</searchComponent>
用来配置查询组件。在requestHandler中会使用到。