简体   繁体   English

在solr中添加自定义字段类型

[英]Add a custom field type in solr

In solr schema.xml many field types are defined. 在solr schema.xml中,定义了许多字段类型。 for example 例如

<fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>

is a definition for an integer field. 是整数字段的定义。

How we define custom field types inside solr? 我们如何在solr中定义自定义字段类型?

Is it possible to add java types such as BigInteger, BigDecimal, Map and other types as field type in solr? 是否可以在solr中添加Java类型(例如BigInteger,BigDecimal,Map和其他类型)作为字段类型?

You can define new custom fields in solr by adding them to the schema.xml in the <fields> element: 您可以在solr中定义新的自定义字段,方法是将它们添加到<fields>元素中的schema.xml中:

<fields>
...
<field name="newfieldname" type="text_general" indexed="true" stored="true" multiValued="true"/>
...
</fields>

To have an overview on the supported types (used to define the <fieldType> in Solr, which then are used to define the field elements), take a look to this link: https://cwiki.apache.org/confluence/display/solr/Field+Types+Included+with+Solr . 要概述受支持的类型(用于在Solr中定义<fieldType> ,然后用于定义field元素),请查看以下链接: https : //cwiki.apache.org/confluence/display / solr / Field + Types + Included + with + Solr For example, the type "text_general" is defined in schema.xml as: 例如,在schema.xml中将type “ text_general”定义为:

<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>

You can see it uses the class="solr.TextField" as its basic field type. 您可以看到它使用class="solr.TextField"作为其基本字段类型。 The Solr schema already has several types defined by default... but you can define more, not sure if you can defined the ones you are asking for. 默认情况下,Solr模式已经定义了几种types ...但是您可以定义更多类型,不确定是否可以定义您要的类型。

You can define new fieldType by extending the FieldType class where you can define your own analyzer for the field and also add other attributes. 您可以通过扩展FieldType类来定义新的fieldType,在其中可以为该字段定义自己的分析器并添加其他属性。 For example the TextField is a subclass of the FieldType. 例如, TextField是FieldType的子类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM