SolrConfig中的ManagedIndexSchemaFactory和add-unknown-fields-to-the-schema

来源:互联网 发布:淘宝上的古着店 编辑:程序博客网 时间:2024/05/17 18:28

新的SolrConfig配置中使用了一个管理Schema的功能配置,以4.9.0为例:

solr-4.9.0/example/example-schemaless/solr/collection1/conf/solrconfig.xml这个示例配置文件中,有一个ManagedIndexSchemaFactory配置项,其含义翻译如下:

如果使用了ManagedIndexSchemaFactory,Solr会从"managedSchemaResourceName"指定的文件名中加载schema,而不是从schema.xml;如果指定的文件(managed-schema)不存在,将会从schema.xml中加载并创建文件,并将schema.xml重命名为'schema.xml.bak'.

不要编辑managed schema – 外部的修改会被忽略,并被修改schema 的RestAPI调用所覆盖。

mutable = true 修改schema 的RestAPI调用被允许,否则会报错。

 

[root@localhost conf]# vim solrconfig.xml

 <!-- To disable dynamic schema REST APIs, use the following for<schemaFactory>:

 

      <schemaFactory class="ClassicIndexSchemaFactory"/>

 

      When ManagedIndexSchemaFactory is specified instead, Solr will load theschema from

      he resource named in 'managedSchemaResourceName', rather than fromschema.xml.

      Note that the managed schema resource CANNOT be named schema.xml.  If the managed

      schema does not exist, Solr will create it after reading schema.xml,then rename

      'schema.xml' to 'schema.xml.bak'.

      

      Do NOT hand edit the managed schema - external modifications will beignored and

      overwritten as a result of schema modification REST API calls.

 

      When ManagedIndexSchemaFactory is specified with mutable = true, schema

      modification REST API calls will be allowed; otherwise, error responseswill be

      sent back for these requests.

 -->

 <schemaFactory class="ManagedIndexSchemaFactory">

   <bool name="mutable">true</bool>

   <strname="managedSchemaResourceName">managed-schema</str>

 </schemaFactory>

 

[root@localhost conf]# vim managed-schema

<?xml version="1.0"encoding="UTF-8"?>

<!-- Solr managed schema - automaticallygenerated - DO NOT EDIT -->

<schema name="shops"version="1.5">

 <uniqueKey>id</uniqueKey>


如果使用了ManagedIndexSchemaFactory并且mutable为true,Solr可以启用添加未知域到Schema的功能(add-unknown-fields-to-the-schema),solrconfig.xml中有如下的配置:

(里面使用的booleans, tdates等类型是在schema中定义的,如果schema中没有这些定义,则创建collection时solr服务会抛出异常:not found fieldType booleans,

从solr-4.9.0/example/example-schemaless/solr/collection1/conf/schema.xml拷贝)

<updateRequestProcessorChain name="add-unknown-fields-to-the-schema">    <processor class="solr.RemoveBlankFieldUpdateProcessorFactory"/>    <processor class="solr.ParseBooleanFieldUpdateProcessorFactory"/>    <processor class="solr.ParseLongFieldUpdateProcessorFactory"/>    <processor class="solr.ParseDoubleFieldUpdateProcessorFactory"/>    <processor class="solr.ParseDateFieldUpdateProcessorFactory">      <arr name="format">        <str>yyyy-MM-dd'T'HH:mm:ss.SSSZ</str>        <str>yyyy-MM-dd'T'HH:mm:ss,SSSZ</str>        <str>yyyy-MM-dd'T'HH:mm:ss.SSS</str>        <str>yyyy-MM-dd'T'HH:mm:ss,SSS</str>        <str>yyyy-MM-dd'T'HH:mm:ssZ</str>        <str>yyyy-MM-dd'T'HH:mm:ss</str>        <str>yyyy-MM-dd'T'HH:mmZ</str>        <str>yyyy-MM-dd'T'HH:mm</str>        <str>yyyy-MM-dd HH:mm:ss.SSSZ</str>        <str>yyyy-MM-dd HH:mm:ss,SSSZ</str>        <str>yyyy-MM-dd HH:mm:ss.SSS</str>        <str>yyyy-MM-dd HH:mm:ss,SSS</str>        <str>yyyy-MM-dd HH:mm:ssZ</str>        <str>yyyy-MM-dd HH:mm:ss</str>        <str>yyyy-MM-dd HH:mmZ</str>        <str>yyyy-MM-dd HH:mm</str>        <str>yyyy-MM-dd</str>      </arr>    </processor>    <processor class="solr.AddSchemaFieldsUpdateProcessorFactory">      <str name="defaultFieldType">text_general</str>      <lst name="typeMapping">        <str name="valueClass">java.lang.Boolean</str>        <str name="fieldType">booleans</str>      </lst>      <lst name="typeMapping">        <str name="valueClass">java.util.Date</str>        <str name="fieldType">tdates</str>      </lst>      <lst name="typeMapping">        <str name="valueClass">java.lang.Long</str>        <str name="valueClass">java.lang.Integer</str>        <str name="fieldType">tlongs</str>      </lst>      <lst name="typeMapping">        <str name="valueClass">java.lang.Number</str>        <str name="fieldType">tdoubles</str>      </lst>    </processor>    <processor class="solr.LogUpdateProcessorFactory"/>    <processor class="solr.RunUpdateProcessorFactory"/>  </updateRequestProcessorChain>

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

如果不想使用自动schema管理,需要将下面的内容注释掉:

  <!--
  <schemaFactory class="ManagedIndexSchemaFactory">
    <bool name="mutable">true</bool>
    <str name="managedSchemaResourceName">managed-schema</str>
  </schemaFactory>
  -->
  <schemaFactory class="ClassicIndexSchemaFactory"/>

  <requestHandler name="/update" class="solr.UpdateRequestHandler">
    <!--
    <lst name="defaults">
      <str name="update.chain">add-unknown-fields-to-the-schema</str>
    </lst>
    -->
  </requestHandler>

0 0
原创粉丝点击