Skip to content

Configuration Solr fields

Chris Beer edited this page Mar 22, 2014 · 8 revisions

Discovery configuration

In this section, we will discuss some of the features available to control the discovery experience, including pagination, sorting, and fielded searches.

Per Page

Three configuration options control the behavior of the per-page and pagination controls.

config.per_page # [10,20,50,100]
config.default_per_page # the first per_page value, or the value given here
config.max_per_page # 100

The options presented in the per-page dropdown are the values for the per_page configuration, in the order given. The default_per_page can be used if you want to offer a default per-page value that isn't the smallest value. Finally, max_per_page is used as a sanity check for user-supplied values.

We can explicitly set the configuration in our CatalogController configuration:

class CatalogController
...
  configure_blacklight do |config|
    ...
    config.per_page = [6,12,24,48]
    config.default_per_page = 24
  end
end

Sort Fields

    config.add_sort_field 'score desc, pub_date_sort desc, title_sort asc', :label => 'relevance'
    config.add_sort_field 'pub_date_sort desc, title_sort asc', :label => 'year'
    config.add_sort_field 'author_sort asc, title_sort asc', :label => 'author'
    config.add_sort_field 'title_sort asc, pub_date_sort desc', :label => 'title'

Targeting Search Queries at Configurable Fields

  • Search queries can be targeted at configurable fields (or sets of fields) to return precise search results. Advanced search capabilities are provided through the Advanced Search Add-On Search fields in actionSearch fields in action
    # This one uses all the defaults set by the solr request handler. Which
    # solr request handler? The one set in config[:default_solr_parameters][:qt],
    # since we aren't specifying it otherwise. 
    
    config.add_search_field 'all_fields', :label => 'All Fields'
    # Now we see how to over-ride Solr request handler defaults, in this
    # case for a BL "search field", which is really a dismax aggregate
    # of Solr search fields. 
    
    config.add_search_field('title') do |field|
      # solr_parameters hash are sent to Solr as ordinary url query params. 
      field.solr_parameters = { :'spellcheck.dictionary' => 'title' }

      # :solr_local_parameters will be sent using Solr LocalParams
      # syntax, as eg {! qf=$title_qf }. This is neccesary to use
      # Solr parameter de-referencing like $title_qf.
      # See: http://wiki.apache.org/solr/LocalParams
      field.solr_local_parameters = { 
        :qf => '$title_qf',
        :pf => '$title_pf'
      }
    end

View Types

Clone this wiki locally