aven 发表于 2015-11-12 09:18:45

[搜索] Solr (二) 配置文件

Solr配置文件
  Solr包含两个主要配置:solr的主目录solr\collection1\conf下面的schema.xml,solrConfig.xml。


[*]solrconfig.xml:主要定义solr的处理程序(handler)和一些扩展程序;
[*]schema.xml:主要定义索引的字段和字段类型。

schema.xml


[*]field 字段节点<field name=&quot;id&quot;      type=&quot;string&quot;   indexed=&quot;true&quot;stored=&quot;true&quot;multiValued=&quot;false&quot; required=&quot;true&quot;/>
<field name=&quot;type&quot;      type=&quot;string&quot;   indexed=&quot;true&quot;stored=&quot;true&quot;multiValued=&quot;false&quot; />
<field name=&quot;name&quot;      type=&quot;string&quot;   indexed=&quot;true&quot;stored=&quot;true&quot;multiValued=&quot;false&quot; />
<field name=&quot;core0&quot;   type=&quot;string&quot;   indexed=&quot;true&quot;stored=&quot;true&quot;multiValued=&quot;false&quot; />
<field name=&quot;_version_&quot; type=&quot;long&quot;   indexed=&quot;true&quot;stored=&quot;true&quot;/> <!-- _version_ field是必需的,不能注掉 -->

[*]type:字段类型,对应fieldType节点,在此结点中可以配置对应字段类型的相应分词器
[*]indexed :是否进行索引
[*]stored:是否进行保存,如不保存,可以进行索引但不能显示此字段的内容
[*]multiValues:是否允许多值
[*]required:是否是必须字段,如是,则该字段必须有值,否则索引报错


[*]dynamicField 动态字段节点<dynamicField name=&quot;*_i&quot;type=&quot;int&quot;    indexed=&quot;true&quot;stored=&quot;true&quot;/>
<dynamicField name=&quot;*_is&quot; type=&quot;int&quot;    indexed=&quot;true&quot;stored=&quot;true&quot;multiValued=&quot;true&quot;/>
<dynamicField name=&quot;*_s&quot;type=&quot;string&quot;indexed=&quot;true&quot;stored=&quot;true&quot; />
<dynamicField name=&quot;*_ss&quot; type=&quot;string&quot;indexed=&quot;true&quot;stored=&quot;true&quot; multiValued=&quot;true&quot;/>
<dynamicField name=&quot;*_l&quot;type=&quot;long&quot;   indexed=&quot;true&quot;stored=&quot;true&quot;/>
<dynamicField name=&quot;*_ls&quot; type=&quot;long&quot;   indexed=&quot;true&quot;stored=&quot;true&quot;multiValued=&quot;true&quot;/>
<dynamicField name=&quot;*_t&quot;type=&quot;text_general&quot;    indexed=&quot;true&quot;stored=&quot;true&quot;/>动态字段表示:如果字段的定义没有在配置中找到,例如menu_s字段,field节点中没有配置,就可以在dynamicField中匹配name=&quot;*_s&quot;,表示该字段为string类型
[*]copyField 复制字段节点<copyField source=&quot;title&quot; dest=&quot;text&quot;/>
<copyField source=&quot;author&quot; dest=&quot;text&quot;/>
<copyField source=&quot;manu&quot; dest=&quot;manu_exact&quot;/>
<copyField source=&quot;price&quot; dest=&quot;price_c&quot;/>复制源字段到目标字段。通过复制字段的配置,就可以把这些字段放到一起,这样搜索的时候不用写很复杂的查询组合就可以在所有的字段中搜索
[*]fieldType 字段类型节点<fieldType name=&quot;string&quot; class=&quot;solr.StrField&quot; sortMissingLast=&quot;true&quot; />
<fieldType name=&quot;text_general&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;>
<analyzer type=&quot;index&quot;>
<tokenizer class=&quot;solr.StandardTokenizerFactory&quot;/>
<filter class=&quot;solr.StopFilterFactory&quot; ignoreCase=&quot;true&quot; words=&quot;stopwords.txt&quot; />
<!-- in this example, we will only use synonyms at query time
<filter class=&quot;solr.SynonymFilterFactory&quot; synonyms=&quot;index_synonyms.txt&quot; ignoreCase=&quot;true&quot; expand=&quot;false&quot;/>
-->
<filter class=&quot;solr.LowerCaseFilterFactory&quot;/>
</analyzer>
<analyzer type=&quot;query&quot;>
<tokenizer class=&quot;solr.StandardTokenizerFactory&quot;/>
<filter class=&quot;solr.StopFilterFactory&quot; ignoreCase=&quot;true&quot; words=&quot;stopwords.txt&quot; />
<filter class=&quot;solr.SynonymFilterFactory&quot; synonyms=&quot;synonyms.txt&quot; ignoreCase=&quot;true&quot; expand=&quot;true&quot;/>
<filter class=&quot;solr.LowerCaseFilterFactory&quot;/>
</analyzer>
</fieldType>添加处理对应字段类型的方法,包括相应分词器等
[*]
其他节点<uniqueKey>id</uniqueKey><!-- 唯一标示,如建索引时遇到重复,则覆盖 -->

         -------------------------------------------------------------------------------------

solrconfig.xml

solrconfig.xml中配置很多,大部分可以保持默认


[*]
dataDir 索引数据data路径<dataDir>${solr.data.dir:}</dataDir>默认不指定,默认房子每个code下data目录中
[*]
autoCommit 自动提交<autoCommit>
<maxTime>${solr.autoCommit.maxTime:15000}</maxTime>
<openSearcher>false</openSearcher> <!-- 默认关闭-->
</autoCommit>
[*]
autoSoftCommit 软提交(近实时搜索)<!-- softAutoCommit is like autoCommit except it causes a
'soft' commit which only ensures that changes are visible
but does not ensure that data is synced to disk.This is
faster and more near-realtime friendly than a hard commit.
-->
<autoSoftCommit>
<maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime>
</autoSoftCommit>Solr创建索引数据时要在提交(Commit)时写入磁盘,这是硬提交,确保即便是停电也不会丢失数据,如果想进行实时的查询操作需要每次进行commit操作,但是这种方式是比较消耗资源的。为了提供更实时的检索能力,同时又能保证性能,Solr设定了一种软提交方式。软提交(soft
commit):仅把数据提交到内存,index可见,此时没有写入到磁盘索引文件中。通常的用法是:每1-10分钟自动触发硬提交,每秒钟自动触发软提交
[*]
other



Solr (三) 全量索引与增量索引

版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: [搜索] Solr (二) 配置文件