blacklight icon indicating copy to clipboard operation
blacklight copied to clipboard

Different suggest dictionaries for different fields

Open mattcg opened this issue 8 years ago • 2 comments

The solr_parameters config field for defining a search field using config.add_search_field in the catalog controller allows us to specify different spellchecking dictionaries (using the spellcheck.dictionary Solr parameter). However, we cannot do the same for suggest.dictionary. Blacklight will always send a parameter-less query to the /suggest endpoint in Solr.

Would it be possible to allow the dictionary to be defined by the user, so that for example, a "title" field could use a "title" dictionary, an "author" field an "author" dictionary, and so on?

mattcg avatar Mar 07 '17 15:03 mattcg

That makes a lot of sense to me. Our first stab at implementing it is pretty basic, and there's obviously room for enhancement.

On the surface, this seems like a relatively simple matter of passing the appropriate parameters through from the view -> javascript -> controller -> service. Here are the relevant bits of code:

  • https://github.com/projectblacklight/blacklight/blob/master/app/views/catalog/_search_form.html.erb (the search_field control probably has the data we want)
  • https://github.com/projectblacklight/blacklight/blob/master/app/assets/javascripts/blacklight/autocomplete.js (no idea, off-hand, how to get bloodhound to pass that information through)
  • https://github.com/projectblacklight/blacklight/blob/master/app/controllers/concerns/blacklight/catalog.rb (the #suggest action in particular; it seems like we might need to pass the blacklight_config through to the model so we can act on it there..)
  • https://github.com/projectblacklight/blacklight/blob/master/app/models/blacklight/suggest_search.rb (it seems like there's an opportunity to do something more interesting than hard-coding parameters for the index -- maybe using Blacklight::SearchService or Blacklght::SearchBuilder -- and some of the functionality we might get for free.

The analogous behavior for changing search parameters based on the search field is here:

https://github.com/projectblacklight/blacklight/blob/master/lib/blacklight/solr/search_builder_behavior.rb#L45-L48

cbeer avatar Mar 07 '17 15:03 cbeer

This seems like (a la facets and fields) there's a backwards compatible way to add this feature (current inplementation only dealing with defaults), so I'm marking 7.x.

barmintor avatar Oct 24 '18 17:10 barmintor