SOLR Case Insensitive Search

Praditha picture Praditha · Nov 23, 2011 · Viewed 52k times · Source

I've a problem in SOLR Search.
I have a data like this:
enter image description here

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*

it doesn't found anything.
I've googling and I found an answer to create a field with the following script:

<fieldType name="c_text" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>

    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

I've copy paste those script into schema.xml, but it still doesn't work. What should I do? Can anyone help me?

Answer

Jayendra picture Jayendra · Nov 23, 2011

The address_s field should be defined as -

<field name="address_s" type="c_text" indexed="true" stored="true"/>

If you are using the default schema.xml, this defination should come before -

<dynamicField name="*_s"  type="string"  indexed="true"  stored="true"/>

which defines it as a string field type with no analysis performed.

Wildcard queries does not undergo analysis.
So if you apply lower case filter at index time query address_s:*nadi* would work.
However, query address_s:*Nadi* would not, as Nadi will not match nadi in index and you would need to lower case the queries at client side.