Add custom field type to solr

Many types of fields are defined in the solr schema.xml file. eg

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

- definition of an integer field.

How do we define custom field types inside solr?

Is it possible to add java types like BigInteger, BigDecimal, Map and other types as a field type in solr?

+4
source share
2 answers

You can define new custom fields in solr by adding them to schema.xml in the <fields> element:

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

For an overview of supported types (used to define <fieldType> in Solr, which is then used to define field elements), look at this link: https://cwiki.apache.org/confluence/display/solr/Field+Types+Included + with + Solr . For example, type "text_general" is defined in schema.xml as:

 <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 that class="solr.TextField" used as the main field type. There are already several types defined by default in the Solr schema ... but you can define more, not sure if you can define the ones you request.

+5
source

You can define a new fieldType type by expanding the FieldType class, where you can define your own parser for the field, as well as add other attributes. For example, TextField is a subclass of FieldType.

+3
source

Source: https://habr.com/ru/post/1494424/


All Articles