Add custom fields to a Solr schema
You can create a custom helper class to add custom fields to a Solr schema.
To add custom fields:
-
Create a class that inherits
SchemaPopulateHelper, and use this class to define the fields and the field types you want to add to the Solr schema:-
Override the
GetAllFieldsmethod to add custom fields. It is important that you call the base method and combine the results with the results of the custom method. -
Override the
GetAllFieldTypesmethod to add custom field types. It is important that you call the base method and combine the results with the results of the custom method. -
Use the
CreateFieldmethod to add new field and attributes. The Solr documentation has descriptions of all parameters, except for these two:Parameter
Type
Description
Default value
defaultName
string
Specify a default value for the field
null
isDynamic
bool
Specify whether the field is a dynamic field
false
-
Use the
CreateFieldTypemethod to add new field type and attributes. The Solr documementation has descriptions of all parameters.
-
-
Create a
PopulateHelperfactory class that inherits fromIPopulateHelperFactory, implements theGetPopulateHelpermethod, and returns your custom class: -
Create a configuration patch file that overrides the Sitecore class factory with the one you created: