Solr5.5使用schema.xml

与之前版本不同,Solr5.5中默认不再使用schema.xml, 取而代之的是Managed Schema,此种方式必须通过Schema API的方式进行管理,不太方便。现在改为传统的schema.xml的配置文件方式。

以下是简介:

The schemaFactory option in solrconfig.xml controls whether the Schema should be defined as a
"managed index schema": schema modification is only possible through the Schema API.
All of the example config sets use the managed schema by default.
By default, if no schemaFactory is specified, then the default behavior is to use the "ClassicIndexSchemaFactory":
<schemaFactory class="ClassicIndexSchemaFactory"/>
The ClassicIndexSchemaFactory requires the use of a schema.xml file, which can be edited manually and
is only loaded only when the collection is loaded. This setting disallows Schema API methods that modify the
schema.


首先通过默认方式启动solr 并创建core(这里命名为core1), 这样会在solr-5.5.0/server/solr/core1/conf 目录下生成managed-schema,将此文件拷贝至同目录下名字为schema.xml。

然后编辑/solr-5.5.0/server/solr/core1/conf/solrconfig.xml,将以下代码注释掉:

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


同时新增<schemaFactory class="ClassicIndexSchemaFactory"/>


最后重启solr即可。


【Q&A】

1. Caused by: org.apache.solr.common.SolrException: Invalid Number: MA147LL/A

此问题是由于将schema.xml中的id设置为了int类型,<field name="id" type="int"

解决方式是把solr-5.5.0/server/solr/core1/conf中的elevate.xml的

<query text="ipod">
     <doc id="MA147LL/A" />
     <doc id="IW-02" exclude="true" />
</query>

注释掉

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Solr 8.7.0版本的schema.xml模板,你可以根据自己的需求进行相应的修改。 ``` <?xml version="1.0" encoding="UTF-8"?> <schema name="example" version="1.6"> <types> <fieldType name="string" class="solr.StrField" sortMissingLast="true" /> <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" /> <filter class="solr.LowerCaseFilterFactory" /> <filter class="solr.EnglishMinimalStemFilterFactory" /> </analyzer> <analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory" /> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" /> <filter class="solr.SynonymGraphFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true" /> <filter class="solr.LowerCaseFilterFactory" /> <filter class="solr.EnglishMinimalStemFilterFactory" /> </analyzer> </fieldType> <fieldType name="date" class="solr.DatePointField" /> <fieldType name="int" class="solr.IntPointField" /> <fieldType name="long" class="solr.LongPointField" /> <fieldType name="float" class="solr.FloatPointField" /> <fieldType name="double" class="solr.DoublePointField" /> <fieldType name="boolean" class="solr.BoolField" /> </types> <fields> <field name="id" type="string" indexed="true" stored="true" multiValued="false" required="true" /> <field name="title" type="text_general" indexed="true" stored="true" multiValued="false" /> <field name="content" type="text_general" indexed="true" stored="true" multiValued="false" /> <field name="date" type="date" indexed="true" stored="true" multiValued="false" /> <field name="price" type="double" indexed="true" stored="true" multiValued="false" /> <field name="location" type="string" indexed="true" stored="true" multiValued="false" /> <field name="category" type="string" indexed="true" stored="true" multiValued="false" /> <field name="is_new" type="boolean" indexed="true" stored="true" multiValued="false" /> <dynamicField name="*_i" type="int" indexed="true" stored="true" multiValued="false" /> <dynamicField name="*_l" type="long" indexed="true" stored="true" multiValued="false" /> <dynamicField name="*_f" type="float" indexed="true" stored="true" multiValued="false" /> <dynamicField name="*_d" type="double" indexed="true" stored="true" multiValued="false" /> <dynamicField name="*_dt" type="date" indexed="true" stored="true" multiValued="false" /> </fields> <uniqueKey>id</uniqueKey> <defaultSearchField>content</defaultSearchField> <solrQueryParser defaultOperator="OR" /> </schema> ``` 其中,该模板定义了一些常用的字段类型,如string、text_general、date、int、long、float、double和boolean等。同时,该模板还定义了一些常用的字段,如id、title、content、date、price、location、category和is_new等,以及动态字段。你可以根据自己的需求进行相应的添加和修改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值