projectblacklight / blacklight

Blacklight provides a discovery interface for any Solr (http://lucene.apache.org/solr) index.
http://projectblacklight.org/
Other
757 stars 256 forks source link

Translate negative facets into fq to exclude docs with a given facet value #3093

Open mjgiarlo opened 9 months ago

mjgiarlo commented 9 months ago

This commit is a rough first hack at adding the ability to filter out docs from a result set that match a facet value. For instance, all docs with language_ssim:Tibetan excluding those with language_ssim:English. None of the UI work to support this is included in this commit, which is more to get familiar (once again) with Solr and Blacklight. There is probably a better way to handle this BL query args-to-Solr query translation than injecting { exclude: true } into facet values and sniffing for it. Pushing this commit up for early feedback to come up with a solid approach before tackling UI work or tests.

Here's what the UI looks like with the current code changes:

Screenshot from 2023-10-12 16-25-19

You can see there are 5 search results, which is correct, since 6 docs have language_ssim:Tibetan and 1 doc has both language_ssim:Tibetan and language_ssim:English. That latter doc is what we're filtering out by changing f[language_ssim]=English to f[-language_ssim]=English in the URL. That the inclusive filters UI is loading is unintended, and likely because of how I'm stuffing the facet value (English) into an array with a hash ({ exclude: true }) in FilterField#values to make sure FilterField#add, FilterField#remove, and FilterField#include are aware of this behavior, and ultimately so that SearchBuilderBehavior#facet_value_to_fq_string (via SearchBuilderBehavior#add_facet_fq_to_solr) knows to prepend a - in front of the Solr FQ query arg for language = English in this example.

Once I get some feedback on this approach, the to-dos are: