Using LowerCaseStrField with search indexes

DataStax Enterprise 6.0.8 introduces a custom field type, LowerCaseStrField, which provides the following features:
  • Converts the data into lowercase and correctly stores the lowercase data in docValues.
  • Converts the query values to lowercase.
Note: You cannot apply LowerCaseStrField to a table's primary key. You also cannot use any analyzers with LowerCaseStrField.

DataStax advises against using TextField with solr.KeywordTokenizer and solr.LowerCaseFilterFactory. Unintended search results could occur because the raw data was not stored as lowercase in docValues, contrary to expectations. Instead, use the custom LowerCaseStrField type as shown in the following examples.

To use LowerCaseStrField on a field in a new index:
CREATE SEARCH INDEX ON <table> WITH COLUMNS *, column { lowerCase : true };
The command creates a search index with column using the LowerCaseStrField field type. The field type is added automatically.
To add a new field to an existing column with the LowerCaseStrField field type:
ALTER SEARCH INDEX SCHEMA ON <table> ADD lowerCaseString column;
RELOAD SEARCH INDEX ON <table>;
REBUILD SEARCH INDEX ON <table>;
The ALTER SEARCH command adds the LowerCaseStrField field type if it does not exist.
There is a workaround to apply LowerCaseStrField to primary key columns. To do so, use the copyField declaration to copy the primary key field data to the new field that's defined as type LowerCaseStrField. Example:
ALTER SEARCH INDEX SCHEMA ON <table> ADD lowerCaseString key_column_copy;
ALTER SEARCH INDEX SCHEMA ON <table> ADD copyField[@source='key_column', @dest='key_column_copy'];
RELOAD SEARCH INDEX ON <table>;
REBUILD SEARCH INDEX ON <table>;
The search query is case insensitive. All queries are converted to lowercase and return the same result. For example, searches for the following values return the same result:
  • name
  • Name
  • NAME