solr学习笔记二(schema.xml)

模式配置Schema.xml

schema.xml这个配置文件可以在你下载solr包的安装解压目录的\solr\example\solr\collection1\conf中找到,它就是solr模式关联的文件。打开这个配置文件,你会发现有详细的注释。模式组织主要分为三个重要配置

1. types 部分

是一些常见的可重用定义,定义了 Solr(和 Lucene)如何处理 Field。也就是添加到索引中的xml文件属性中的类型,如int、text、date等.

参数说明:

<fieldType name="string" class="solr.StrField" sortMissingLast="true"/>
<fieldType name="boolean" class="solr.BoolField" sortMissingLast="true"/>
<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
属性 描述

name

标识而已

class

和其他属性决定了这个fieldType的实际行为。

sortMissingLast

设置成true没有该field的数据排在有该field的数据之后,而不管请求时的排序规则, 默认是设置成false。

sortMissingFirst

跟上面倒过来呗。 默认是设置成false

analyzer

字段类型指定的分词器

type

当前分词用用于的操作.index代表生成索引时使用的分词器query代码在查询时使用的分词器

tokenizer

分词器类

filter

分词后应用的过滤器  过滤器调用顺序和配置相同.

2. fileds

是你添加到索引文件中出现的属性名称,而声明类型就需要用到上面的types

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false"/>
<field name="path" type="text_smartcn" indexed="false" stored="true" multiValued="false"termVector="true" />
<field name="content" type="text_smartcn" indexed="false" stored="true" multiValued="false" termVector="true"/>
<field name ="text" type ="text_ik" indexed ="true" stored ="false" multiValued ="true"/>
<field name ="pinyin" type ="text_pinyin" indexed ="true" stored ="false" multiValued ="false"/>
<field name="_version_" type="long" indexed="true" stored="true"/>
<dynamicField name="*_i" type="int" indexed="true" stored="true"/>
<dynamicField name="*_l" type="long" indexed="true" stored="true"/>
<dynamicField name="*_s" type="string" indexed="true" stored="true" />
  • field: 固定的字段设置
  • dynamicField: 动态的字段设置,用于后期自定义字段,*号通配符.例如: test_i就是int类型的动态字段.

还有一个特殊的字段copyField,一般用于检索时用的字段这样就只对这一个字段进行索引分词就行了copyField的dest字段如果有多个source一定要设置multiValued=true,否则会报错的

<copyField source="content" dest="pinyin"/>
<copyField source="content" dest="text"/>
<copyField source="pinyin" dest="text"/>

字段属性说明:

属性 描述

name

 字段类型名

class

 java类名

indexed

 缺省true。 说明这个数据应被搜索和排序,如果数据没有indexed,则stored应是true。

stored

 缺省true。说明这个字段被包含在搜索结果中是合适的。如果数据没有stored,则indexed应是true。

omitNorms

 字段的长度不影响得分和在索引时不做boost时,设置它为true。

一般文本字段不设置为true。

termVectors

 如果字段被用来做more like this 和highlight的特性时应设置为true。

compressed

 字段是压缩的。这可能导致索引和搜索变慢,但会减少存储空间,只有StrField和TextField是可以压缩,这通常适合字段的长度超过200个字符。

multiValued

 字段多于一个值的时候,可设置为true。

positionIncrementGap

 和multiValued一起使用,设置多个值之间的虚拟空白的数量

注意:_version_是一个特殊字段,不能删除,是记录当前索引版本号的.

3. 其他配置

uniqueKey:唯一键,这里配置的是上面出现的fileds,一般是id、url等不重复的。在更新、删除的时候可以用到。

defaultSearchField:默认搜索属性,如q=solr就是默认的搜索那个字段

solrQueryParser:查询转换模式,是并且还是或者(AND/OR必须大写)

Comments are closed.