Solr 3.5 – Search case insensitive on a string field for exact match

gCYkl

 

I use solr admin to find this data using query like this:

address_s:*Nadi*

and found those data. But when I use this query:

address_s:*nadi*

 

Solr has by default in the schema.xml the field type “string” available.

 name=“string” class=“solr.StrField” sortMissingLast=“true” omitNorms=“true”/>

With this field type you can search with a string to get an exact match, instead of a contains match that the “text_general” field type will give you. However another difference is that the “text_general” field type iscase insensitive by default and “string” is case sensitive.

To perform an case insensitive exact match search, you’ll have to add a custom field type in your Solr schema.xml, I called it “string_ci” (string case insensitive).

 name=“string_ci” class=“solr.TextField” sortMissingLast=“true” omitNorms=“true”>
 type=“query”>
 class=“solr.KeywordTokenizerFactory”/>
 class=“solr.LowerCaseFilterFactory”/>

Now you have to create your field with type of string_ci.

 name=“address_s” type=“string_ci” sorted=“true” multivalued=“true”/>

or you can also change the type of predefine field

 name=“ss_*” type=“string_ci” sorted=“true” multivalued=“true”/>

 

Now Restart the solr server and do reindexing.

Now it will work for both

address_s:*Nadi*

            or

address_s:*nadi*