schema.xml文件在SolrCore的conf目录下,它是Solr数据表配置文件,在此配置文件中定义了域以及域的类型还有其他一些配置,在solr中域必须先定义后使用
<field name="id"@H_403_5@ type@H_403_5@="string"@H_403_5@ indexed="true"@H_403_5@ stored="true"@H_403_5@ required="true"@H_403_5@ multiValued="false"@H_403_5@ />
Name:域的名称
Type:域的类型
Indexed:是否索引
Stored:是否存储
required:是否必须
multiValued:是否是多值,存储多个值时设置为true,solr允许一个Field存储多个值,比如存储一个用户的好友id(多个)
<!-- A general text field that has reasonable,generic cross-language defaults: it tokenizes with StandardTokenizer,removes stop words from case-insensitive "stopwords.txt" (empty by default),and down cases. At query time only,it also applies synonyms. -->@H_403_5@
<fieldType@H_403_5@ name@H_403_5@="text_general"@H_403_5@ class@H_403_5@="solr.TextField"@H_403_5@ positionIncrementGap@H_403_5@="100"@H_403_5@>@H_403_5@
<analyzer@H_403_5@ type@H_403_5@="index"@H_403_5@>@H_403_5@
<tokenizer@H_403_5@ class@H_403_5@="solr.StandardTokenizerFactory"@H_403_5@/>@H_403_5@
<filter@H_403_5@ class@H_403_5@="solr.StopFilterFactory"@H_403_5@ ignoreCase@H_403_5@="true"@H_403_5@ words@H_403_5@="stopwords.txt"@H_403_5@ />@H_403_5@
<!-- in this example,we will only use synonyms at query time <filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/> -->@H_403_5@
<filter@H_403_5@ class@H_403_5@="solr.LowerCaseFilterFactory"@H_403_5@/>@H_403_5@
</analyzer@H_403_5@>@H_403_5@
<analyzer@H_403_5@ type@H_403_5@="query"@H_403_5@>@H_403_5@
<tokenizer@H_403_5@ class@H_403_5@="solr.StandardTokenizerFactory"@H_403_5@/>@H_403_5@
<filter@H_403_5@ class@H_403_5@="solr.StopFilterFactory"@H_403_5@ ignoreCase@H_403_5@="true"@H_403_5@ words@H_403_5@="stopwords.txt"@H_403_5@ />@H_403_5@
<filter@H_403_5@ class@H_403_5@="solr.SynonymFilterFactory"@H_403_5@ synonyms@H_403_5@="synonyms.txt"@H_403_5@ ignoreCase@H_403_5@="true"@H_403_5@ expand@H_403_5@="true"@H_403_5@/>@H_403_5@
<filter@H_403_5@ class@H_403_5@="solr.LowerCaseFilterFactory"@H_403_5@/>@H_403_5@
</analyzer@H_403_5@>@H_403_5@
</fieldType@H_403_5@>@H_403_5@
name:域类型的名称
class:指定域类型的solr类型。
analyzer:指定分词器。在FieldType定义的时候最重要的就是定义这个类型的数据在建立索引和进行查询的时候要使用的分析器analyzer,包括分词和过滤。
type:index和query。Index 是创建索引,query是查询索引。
tokenizer:指定分词器
filter:指定过滤器
<uniqueKey@H_403_5@>@H_403_5@id</uniqueKey@H_403_5@>@H_403_5@
相当于主键,每个文档中必须有一个id域。
<copyField source@H_403_5@="cat"@H_403_5@ dest="text"@H_403_5@ />
可以将多个Field复制到一个Field中,以便进行统一的检索。当创建索引时,solr服务器会自动的将源域的内容复制到目标域中。
source:源域
dest:目标域,搜索时,指定目标域为默认搜索域,可以提供查询效率
定义目标域
<!-- catchall field,containing all other searchable text fields (implemented via copyField further on in this schema -->@H_403_5@
<field@H_403_5@ name@H_403_5@="text"@H_403_5@ type@H_403_5@="text_general"@H_403_5@ indexed@H_403_5@="true"@H_403_5@ stored@H_403_5@="false"@H_403_5@ multiValued@H_403_5@="true"@H_403_5@/>@H_403_5@
<dynamicField name="*_i"@H_403_5@ type@H_403_5@="int"@H_403_5@ indexed="true"@H_403_5@ stored="true"@H_403_5@/>
Name:动态域的名称,是一个表达式,*匹配任意字符,只要域的名称和表达式的规则能够匹配就可以使用。
例如:搜索时查询条件【product_i:钻石】就可以匹配这个动态域,可以直接使用,不用单独再定义一个product_i域。