Working with Enum Fields

EnumFieldType allows defining a field whose values are a closed set, and the sort order is pre-determined but is not alphabetic nor numeric. Examples of this are severity lists, or risk definitions.

EnumField has been Deprecated

EnumField has been deprecated in favor of EnumFieldType; all configuration examples below use EnumFieldType.

Defining an EnumFieldType in schema.xml

The EnumFieldType type definition is quite simple, as in this example defining field types for "priorityLevel" and "riskLevel" enumerations:

<fieldType name="priorityLevel" class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="priority"/>
<fieldType name="riskLevel"     class="solr.EnumFieldType" docValues="true" enumsConfig="enumsConfig.xml" enumName="risk"    />

Besides the name and the class, which are common to all field types, this type also takes two additional parameters:

enumsConfig
the name of a configuration file that contains the <enum/> list of field values and their order that you wish to use with this field type. If a path to the file is not defined specified, the file should be in the conf directory for the collection.
enumName
the name of the specific enumeration in the enumsConfig file to use for this type.

Note that docValues="true" must be specified either in the EnumFieldType fieldType or field specification.

Defining the EnumFieldType Configuration File

The file named with the enumsConfig parameter can contain multiple enumeration value lists with different names if there are multiple uses for enumerations in your Solr schema.

In this example, there are two value lists defined. Each list is between enum opening and closing tags:

<?xml version="1.0" ?>
<enumsConfig>
  <enum name="priority">
    <value>Not Available</value>
    <value>Low</value>
    <value>Medium</value>
    <value>High</value>
    <value>Urgent</value>
  </enum>
  <enum name="risk">
    <value>Unknown</value>
    <value>Very Low</value>
    <value>Low</value>
    <value>Medium</value>
    <value>High</value>
    <value>Critical</value>
  </enum>
</enumsConfig>
Changing Values

You cannot change the order, or remove, existing values in an <enum/> without reindexing.

You can however add new values to the end.