How to ignore the case sensitivity in solr query

Rajeev Rajvaidya picture Rajeev Rajvaidya · Jan 6, 2017 · Viewed 7.2k times · Source

I have a database that consist of Names and locations. I am searching for names using case insensitivity USING SOLR. However I am not able to find any way I can do that. For example: I have a list of Names:

Rajeev rajeev raj Raj

when i search for cname:raj* i get the following rajeev raj

What do i do to get Rajeev and Raj also.

Answer

Oyeme picture Oyeme · Jan 6, 2017

You should add a new filter solr.LowerCaseFilterFactory to convert everything to a lowercase , this should apply to index and query.

Analyzers are components that pre-process input text at index time and/or at search time. It's important to use the same or similar analyzers that process text in a compatible manner at index and query time. For example, if an indexing analyzer lowercases words, then the query analyzer should do the same to enable finding the indexed words.

https://wiki.apache.org/solr/AnalyzersTokenizersTokenFilters#Analyzers

An example:
Schema.xml

<field name="Name" type="text_general" indexed="true" stored="true"/>


Where text_general type

<fieldType name="text_general" class="solr.TextField" omitNorms="false" positionIncrementGap="100" multiValued="true">
  <analyzer type="index">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    tokenizerFactory="solr.WhitespaceTokenizerFactory"/>
  </analyzer>
</fieldType>