Interface for custom field types
The CustomFieldType interface marks Solr custom field types and provides their actual stored field type.
DataStax Enterprise implements a CustomFieldType interface that marks Solr custom field types and provides their actual stored field type. The custom field type stores an integer trie field as a string representing a comma separated list of integer values: when indexed, the string is split into its integer values, each one indexed as a trie integer field. This class effectively implements a multi-valued field based on its string representation.
- Implement a custom field type class something like the following reference implementation.
- Export the class to a JAR, and place the JAR in this location:
- Package installations: usr/share/dse
- Installer-No Services and Tarball installations: install_location/resources/dse/lib
The JAR is added to the CLASSPATH automatically.
Reference implementation
Here is an example of a custom field type class:
package com.datastax.bdp.search.solr.functional; import com.datastax.bdp.search.solr.CustomFieldType; import java.util.ArrayList; import java.util.List; import org.apache.lucene.index.IndexableField; import org.apache.solr.schema.FieldType; import org.apache.solr.schema.SchemaField; import org.apache.solr.schema.StrField; import org.apache.solr.schema.TrieField; public class CustomTestField extends TrieField implements CustomFieldType { public CustomTestField() { this.type = TrieField.TrieTypes.INTEGER; } @Override public FieldType getStoredFieldType() { return new StrField(); } @Override public boolean multiValuedFieldCache() { return true; } @Override public List<IndexableField> createFields(SchemaField sf, Object value, float boost) { String[] values = ((String) value).split(" "); List<IndexableField> fields = new ArrayList<IndexableField>(); for (String v : values) { fields.add(createField(sf, v, boost)); } return fields; } @Override public String toInternal(String value) { return value; } @Override public String toExternal(IndexableField f) { return f.stringValue(); } }