Case insensitive Solr query for facets but preserv

2019-08-24 03:30发布

问题:

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?

回答1:

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.