Interface for custom field types
DSE Search implements a CustomFieldType interface that marks Apache 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.
A CustomFieldType can override this method to provide the FieldType for the binary response writer to look at when it determines whether to call the field’s toObject().
This allows the binary response writer, for example, to return java.util.Date in place of text for a CustomFieldType that extends TrieDateField.
To use the CustomFieldType interface:
-
Implement a custom field type class.
To ensure that custom field types control their serialized value, use the
getKnownType()method in yourCustomFieldTypeimplementation:public Class<? extends FieldType> getKnownType() { return getClass(); }For example:
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 ListIndexableField createFields(SchemaField sf, Object value) { String[] values = ((String) value).split(" "); ListIndexableField fields = new ArrayListIndexableField(); for (String v : values) { fields.add(createField(sf, v)); } return fields; } @Override public String toInternal(String value) { return value; } @Override public String toExternal(IndexableField f) { return f.stringValue(); } // Ensures that the custom field type controls its serialized value public Class<? extends FieldType> getKnownType() { return TrieField.class; } } -
Export the class to a JAR.
-
Store the JAR in the appropriate DSE and Solr resources directories for your installation type:
-
Package installations:
/usr/share/dse/solr/liband/usr/share/dse -
Tarball installations:
INSTALL_DIRECTORY/resources/solr/libandINSTALL_DIRECTORY/resources/dse/lib
The JAR is added to the
CLASSPATHautomatically. -