The schema.xml file contains all of the details about which fields your documents can contain, and how those fields should be dealt with when adding documents to the index, or when querying those fields.
schema.xml位于solr/conf/目录下,类似于数据表配置文件,定义了加入索引的数据的数据类型,主要包括type、fields和其他的一些缺省设置。 Data Types
The<types>section allows you to define a list of<fieldtype>declarations you wish to use in your schema, along with the underlying Solr class that should be used for that type, as well as the default optionsyou want for fields that use that type.
types节点,这里面定义FieldType子节点,包括name,class,positionIncrementGap等一些参数。
Fields
The<fields>section is where you list the individual<field>declarations you wish to use in your documents. Each<field>has anamethat you will use toreference it when adding documents or executing searches, and an associatedtypewhich identifies the name of the fieldtype you wish to use for this field. There are various field options that apply to a field. These can be set inthe field type declarations, and can also be overridden at an individual field's declaration.
字段t是文章的标题,字段a是文章的摘要,字段ta是文章标题和摘要的联合。添加索引文档时,只需要传入t和a字段的内容,solr会自动索引ta字段。 Dynamic fields
One of the powerful features of Lucene is that you don't have to pre-define every field when you first create your index. Even though Solr provides strong datatyping for fields, it still preserves that flexibility using "Dynamic Fields". Using<dynamicField>declarations,you can create field rules that Solr will use to understand what datatype should be used whenever it is given a field name that is not explicitly defined, but matches a prefix or suffix used in a dynamicField.
For example the following dynamic field declaration tells Solr that whenever it sees a field name ending in "_i" which is not an explicitly defined field, then it should dynamically create an integer field with that name...
Xml代码
The Unique Key Field
The<uniqueKey>declaration can be used to inform Solr that there is a field in your index which should be unique for all documents. If a document is added that contains the same value for this field as an existing document, the olddocument will be deleted. It is not mandatory for a schema to have a uniqueKey field.
5、其他一些标签
<uniqueKey>id</uniqueKey>
文档的唯一标识,必须填写这个field(除非该field被标记required="false"),否则solr建立索引报错。(跟wiki里说的It is not mandatory for a schema to have a uniqueKey field. 相反)
<defaultSearchField>text</defaultSearchField>
如果搜索参数中没有指定具体的field,那么这是默认的域。
<solrQueryParserdefaultOperator="OR"/>
配置搜索参数短语间的逻辑,可以是"AND|OR"。