Shubham Yelikar
Shubham Yelikar

Reputation: 93

Solr: How to search records ignoring case in field type "string"?

I have indexed the following record in my collection

 {
        "app_name":"atm inspection",
        "appversion":1,
        "id":"app_1427_version_2449",
        "icon":"/images/media/default_icons/app.png",
        "type":"app",
        "app_id":1427,
        "account_id":556,
        "app_description":"inspection",
        "_version_":1599625614495580160}]
  }

and It's working fine unless an until i search records case sensitively i.e if i write following Solr query to search records whose app_name contains atm then Solr is returning above response which is a correct behaviour.

http://localhost:8983/solr/NewAxoSolrCollectionLocal/select?fq=app_name:*atm\ *&q=*:*

However, If i execute following Solr query to search records whose app_name contains ATM

http://localhost:8983/solr/NewAxoSolrCollectionLocal/select?fq=app_name:*ATM\ *&q=*:*

Solr is not returning above response because ATM!=atm.

Can someone please help me with the Solr query to search records case insensitively.

Your help is greatly appreciated.

Upvotes: 1

Views: 305

Answers (1)

MatsLindh
MatsLindh

Reputation: 52802

You can't. The field type string requires an exact match (it's a single, unprocessed token being stored for the field value).

The way to do it is to use a TextField with an associated Tokenizer and a LowercaseFilter. If you use a KeywordTokenizer, the whole token will be kept intact (so it won't get split as you'd usually assume with a tokenizer), and since it's a TextField it can have a analysis chain associated - allowing you to add a LowercaseFilter.

The LowerCaseFilter is multiterm aware as far as I remember, but remember that wildcard queries will usually not have any filters applied. You should therefor lowercase the value before creating your query yourself (even if it probably will work in this simple case).

Upvotes: 1

Related Questions