Krunal
Krunal

Reputation: 3269

Case insensitive Solr query for facets but preserve case for results

I am using Solr to power faceting features for our e-commerce application. Its been implemented in standard way as described here https://wiki.apache.org/solr/SimpleFacetParameters#Tagging_and_excluding_Filters

On application side, we have used facets returned by Solr to offer filtering experience on UI and the URLs are built using the facets as params. These parameters are then used to further pass on the faceting parameters for fq into Solr.

This works great except that our URLs are case sensitive as the moment we change to small case the facet query no longer work and gives us Undefined field error.

How can we have Case insensitive Solr Query for Faceting but still preserve case for results that are being used to display facets?

Upvotes: 1

Views: 767

Answers (1)

MatsLindh
MatsLindh

Reputation: 52822

First: it seems weird that you're getting an error about undefined fields. You should probably not let the end user specify the field used without validating the field against those that you want to allow filtering or faceting for.

Second: Use one field for generating the facets, and one for filtering. There is nothing that says you have to use the same field for presenting the facets and for use in fq.

You can have a field with a KeywordTokenizer and an LowercaseFilter to use for filtering, and then use <copyField> to copy content from the field you use for faceting into the lowercased field for filtering.

Upvotes: 1

Related Questions