Class: Blacklight::Configuration

Inherits:
OpenStructWithHashAccess show all
Includes:
Fields
Defined in:
lib/blacklight/configuration.rb,
lib/blacklight/configuration/fields.rb,
lib/blacklight/configuration/context.rb,
lib/blacklight/configuration/view_config.rb

Overview

Blacklight::Configuration holds the configuration for a Blacklight::Controller, including fields to display, facets to show, sort options, and search fields.

Defined Under Namespace

Modules: Fields Classes: Context, DisplayField, FacetField, Field, IndexField, NullField, SearchField, ShowField, SortField, ToolConfig, ViewConfig

Constant Summary collapse

BASIC_SEARCH_PARAMETERS =
[:q, :qt, :page, :per_page, :search_field, :sort, :controller, :action, :'facet.page', :'facet.prefix', :'facet.sort', :rows, :format, :view].freeze
ADVANCED_SEARCH_PARAMETERS =
[{ clause: {} }, :op].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Fields

#add_blacklight_field

Methods inherited from OpenStructWithHashAccess

#deep_dup, #merge, #merge!, #reverse_merge, #select, #sort_by, #sort_by!, #to_h

Constructor Details

#initialize(hash = {}) {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



380
381
382
383
384
385
386
387
# File 'lib/blacklight/configuration.rb', line 380

def initialize(hash = {})
  self.class.initialize_default_configuration unless self.class.initialized_default_configuration?

  super(self.class.default_values.deep_dup.merge(hash))
  yield(self) if block_given?

  @view_config ||= {}
end

Instance Attribute Details

#action_mappingHash{Symbol => Blacklight::Configuration::ViewConfig}

Returns:

Since:

  • v7.16.0



218
219
220
221
222
223
# File 'lib/blacklight/configuration.rb', line 218

property :action_mapping, default: NestedOpenStructWithHashAccess.new(
  ViewConfig,
  default: { top_level_config: :index },
  show: { top_level_config: :show },
  citation: { parent_config: :show }
)

#advanced_search#enabled

Returns:

  • (#enabled)

Since:

  • v7.15.0



312
# File 'lib/blacklight/configuration.rb', line 312

property :advanced_search, default: OpenStruct.new(enabled: false)

#autocomplete_suggesterString

Returns:

  • (String)

Since:

  • v7.0.0



297
# File 'lib/blacklight/configuration.rb', line 297

property :autocomplete_suggester, default: 'mySuggester'

#connection_configClass

repository connection configuration

Returns:

  • (Class)

Since:

  • v5.13.0



155
# File 'lib/blacklight/configuration.rb', line 155

property :connection_config, default: nil

#crawler_detector<nil, Proc>

proc for determining whether the session is a crawler/bot ex.: crawler_detector: lambda { |req| req.env =~ /bot/ }

Returns:

  • (<nil, Proc>)

Since:

  • v7.0.0



292
# File 'lib/blacklight/configuration.rb', line 292

property :crawler_detector, default: nil

#default_document_solr_paramsHash

Returns Default values of parameters to send with every single-document request.

Returns:

  • (Hash)

    Default values of parameters to send with every single-document request



76
# File 'lib/blacklight/configuration.rb', line 76

property :default_document_solr_params, default: {}

#default_facet_limitInteger

Returns:

  • (Integer)

Since:

  • v5.10.0



281
# File 'lib/blacklight/configuration.rb', line 281

property :default_facet_limit, default: 10

#default_more_limitInteger

Returns:

  • (Integer)

Since:

  • v7.0.0



285
# File 'lib/blacklight/configuration.rb', line 285

property :default_more_limit, default: 20

#default_per_pageInteger

Returns:

  • (Integer)


268
# File 'lib/blacklight/configuration.rb', line 268

property :default_per_page, default: nil

#default_solr_paramsHash

Returns Default values of parameters to send with every search request.

Returns:

  • (Hash)

    Default values of parameters to send with every search request



55
# File 'lib/blacklight/configuration.rb', line 55

property :default_solr_params, default: {}

#document_factoryObject

A class that builds documents



125
# File 'lib/blacklight/configuration.rb', line 125

property :document_factory, default: nil

#document_modelClass

the model to use for each response document

Returns:

  • (Class)


133
# File 'lib/blacklight/configuration.rb', line 133

property :document_model, default: nil

#document_pagination_paramsHash

Returns Default values of parameters to send when getting the previous + next documents.

Returns:

  • (Hash)

    Default values of parameters to send when getting the previous + next documents



87
# File 'lib/blacklight/configuration.rb', line 87

property :document_pagination_params, default: {}

#document_solr_pathString

Returns The url path (relative to the solr base url) to use when requesting only a single document.

Returns:

  • (String)

    The url path (relative to the solr base url) to use when requesting only a single document

Since:

  • v5.2.0



65
# File 'lib/blacklight/configuration.rb', line 65

property :document_solr_path, default: 'get'

#document_solr_request_handlerString

Returns The solr request handler to use when requesting only a single document.

Returns:

  • (String)

    The solr request handler to use when requesting only a single document



61
# File 'lib/blacklight/configuration.rb', line 61

property :document_solr_request_handler, default: nil

#document_unique_id_paramSymbol

Returns The solr query parameter used for sending the unique identifiers for one or more documents.

Returns:

  • (Symbol)

    The solr query parameter used for sending the unique identifiers for one or more documents

Since:

  • v5.2.0



73
# File 'lib/blacklight/configuration.rb', line 73

property :document_unique_id_param, default: :ids

#emailBlacklight::Configuration::ViewConfig

Returns:

Since:

  • v7.21.0



233
# File 'lib/blacklight/configuration.rb', line 233

property :email, default: ViewConfig.new

#email_fieldsHash{Symbol=>Blacklight::Configuration::DisplayField}

Returns:



378
# File 'lib/blacklight/configuration.rb', line 378

define_field_access :email_field, Blacklight::Configuration::DisplayField

#enable_search_bar_autofocusBoolean

Returns:

  • (Boolean)

Since:

  • v7.2.0



317
# File 'lib/blacklight/configuration.rb', line 317

property :enable_search_bar_autofocus, default: false

#facet_fieldsHash{Symbol=>Blacklight::Configuration::FacetField}

Returns:



360
# File 'lib/blacklight/configuration.rb', line 360

define_field_access :facet_field, Blacklight::Configuration::FacetField

#facet_paginator_classClass

Class for paginating long lists of facet fields

Returns:

  • (Class)


146
# File 'lib/blacklight/configuration.rb', line 146

property :facet_paginator_class, default: nil

#fetch_many_document_paramsHash

Returns Default values of parameters to send with every multi-document request.

Returns:

  • (Hash)

    Default values of parameters to send with every multi-document request

Since:

  • v7.0.0



84
# File 'lib/blacklight/configuration.rb', line 84

property :fetch_many_document_params, default: {}

#fetch_many_documents_pathString

Returns The url path (relative to the solr base url) to use when requesting multiple documents by id.

Returns:

  • (String)

    The url path (relative to the solr base url) to use when requesting multiple documents by id

Since:

  • v8.4.0



80
# File 'lib/blacklight/configuration.rb', line 80

property :fetch_many_documents_path, default: nil

#filter_search_state_fieldsBoolean

Have SearchState filter out unknown request parameters

Returns:

  • (Boolean)

Since:

  • v8.0.0



334
# File 'lib/blacklight/configuration.rb', line 334

property :filter_search_state_fields, default: false

#http_method:get, :post

Returns HTTP method used for search.

Returns:

  • (:get, :post)

    HTTP method used for search

Since:

  • v5.0.0



49
# File 'lib/blacklight/configuration.rb', line 49

property :http_method, default: :get

#indexBlacklight::Configuration::ViewConfig::Index

General configuration for all views



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/blacklight/configuration.rb', line 171

property :index, default: ViewConfig::Index.new(
  # document presenter class used by helpers and views
  document_presenter_class: nil,
  # component class used to render a document
  document_component: nil,
  # solr field to use to render a document title
  title_field: nil,
  # solr field to use to render format-specific partials
  display_type_field: nil,
  # partials to render for each document(see #render_document_partials)
  partials: [:index_header, :thumbnail, :index],
  document_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
  collection_actions: NestedOpenStructWithHashAccess.new(ToolConfig),
  # what field, if any, to use to render grouped results
  group: false,
  # additional response formats for search results
  respond_to: OpenStructWithHashAccess.new,
  # component class used to render the facet grouping
  facet_group_component: nil,
  # component class used to render search constraints
  constraints_component: nil,
  # component class used to render the search bar
  search_bar_component: nil,
  # pagination parameters to pass to kaminari
  pagination_options: Blacklight::Engine.config.blacklight.default_pagination_options.dup
)

#index_fieldsHash{Symbol=>Blacklight::Configuration::IndexField}

Returns:



363
# File 'lib/blacklight/configuration.rb', line 363

define_field_access :index_field, Blacklight::Configuration::IndexField

#json_solr_pathString

Returns The url path (relative to the solr base url) to use when using Solr’s JSON Query DSL (as with the advanced search).

Returns:

  • (String)

    The url path (relative to the solr base url) to use when using Solr’s JSON Query DSL (as with the advanced search)

Since:

  • v7.34.0



69
# File 'lib/blacklight/configuration.rb', line 69

property :json_solr_path, default: nil

#max_per_pageInteger

Maximum number of results to show per page

Returns:

  • (Integer)


261
# File 'lib/blacklight/configuration.rb', line 261

property :max_per_page, default: 100

Returns:

  • (#partials)

Since:

  • v5.8.0



166
# File 'lib/blacklight/configuration.rb', line 166

property :navbar, default: OpenStructWithHashAccess.new(partials: {})

#per_pageArray<Integer>

Options for the user for number of results to show per page

Returns:

  • (Array<Integer>)


265
# File 'lib/blacklight/configuration.rb', line 265

property :per_page, default: [10, 20, 50, 100]

#raw_endpoint#enabled

Returns:

  • (#enabled)

Since:

  • v7.0.0



302
# File 'lib/blacklight/configuration.rb', line 302

property :raw_endpoint, default: OpenStructWithHashAccess.new(enabled: false)

#repository_classClass

Returns Class for sending and receiving requests from a search index.

Returns:

  • (Class)

    Class for sending and receiving requests from a search index



94
# File 'lib/blacklight/configuration.rb', line 94

property :repository_class, default: nil

#response_modelClass

model that maps index responses to the blacklight response model

Returns:

  • (Class)


113
# File 'lib/blacklight/configuration.rb', line 113

property :response_model, default: nil

#search_builder_classClass

Returns class for converting Blacklight parameters to request parameters for the repository_class.

Returns:

  • (Class)

    class for converting Blacklight parameters to request parameters for the repository_class



101
# File 'lib/blacklight/configuration.rb', line 101

property :search_builder_class, default: nil

#search_fieldsHash{Symbol=>Blacklight::Configuration::SearchField}

Returns:



369
# File 'lib/blacklight/configuration.rb', line 369

define_field_access :search_field, Blacklight::Configuration::SearchField

#search_history_windowInteger

how many searches to save in session history

Returns:

  • (Integer)


277
# File 'lib/blacklight/configuration.rb', line 277

property :search_history_window, default: 100

#search_state_fieldsArray<Symbol>

List the request parameters that compose the SearchState. If you use a plugin that adds to the search state, then you can add the parameters by modifiying this field.

Returns:

  • (Array<Symbol>)

Since:

  • v8.0.0



327
# File 'lib/blacklight/configuration.rb', line 327

property :search_state_fields, default: BASIC_SEARCH_PARAMETERS + ADVANCED_SEARCH_PARAMETERS

#showBlacklight::Configuration::ViewConfig::Show

Additional configuration when displaying a single document



201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/blacklight/configuration.rb', line 201

property :show, default: ViewConfig::Show.new(
  # document presenter class used by helpers and views
  document_presenter_class: nil,
  document_component: nil,
  display_type_field: nil,
  # Default route parameters for 'show' requests.
  # Set this to a hash with additional arguments to merge into the route,
  # or set `controller: :current` to route to the current controller.
  route: nil,
  # partials to render for each document(see #render_document_partials)
  partials: [:show_header, :show],
  document_actions: NestedOpenStructWithHashAccess.new(ToolConfig)
)

#show_fieldsHash{Symbol=>Blacklight::Configuration::ShowField}

Returns:



366
# File 'lib/blacklight/configuration.rb', line 366

define_field_access :show_field, Blacklight::Configuration::ShowField

#smsBlacklight::Configuration::ViewConfig

Returns:

Since:

  • v7.21.0



228
# File 'lib/blacklight/configuration.rb', line 228

property :sms, default: ViewConfig.new

#sms_fieldsHash{Symbol=>Blacklight::Configuration::DisplayField}

Returns:



375
# File 'lib/blacklight/configuration.rb', line 375

define_field_access :sms_field, Blacklight::Configuration::DisplayField

#solr_pathString

Returns The path to send requests to solr.

Returns:

  • (String)

    The path to send requests to solr.



52
# File 'lib/blacklight/configuration.rb', line 52

property :solr_path, default: 'select'

#sort_fieldsHash{Symbol=>Blacklight::Configuration::SortField}

Returns:



372
# File 'lib/blacklight/configuration.rb', line 372

define_field_access :sort_field, Blacklight::Configuration::SortField

#spell_maxInteger

Maxiumum number of spelling suggestions to offer

Returns:

  • (Integer)


256
# File 'lib/blacklight/configuration.rb', line 256

property :spell_max, default: 5

#track_search_sessionBoolean

Returns:

  • (Boolean)

Since:

  • v7.1.0



307
# File 'lib/blacklight/configuration.rb', line 307

property :track_search_session, default: true

#viewHash{Symbol => Blacklight::Configuration::ViewConfig}

Configurations for specific types of index views

Returns:



238
239
240
241
242
243
244
245
246
247
248
# File 'lib/blacklight/configuration.rb', line 238

property :view, default: NestedOpenStructWithHashAccess.new(ViewConfig,
list: {},
atom: {
  if: false, # by default, atom should not show up as an alternative view
  partials: [:document],
  summary_partials: [:index]
},
rss: {
  if: false, # by default, rss should not show up as an alternative view
  partials: [:document]
})

Class Method Details

.default_configuration(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/blacklight/configuration.rb', line 15

def default_configuration(&block)
  @default_configurations ||= []

  if block
    @default_configurations << block

    block.call if @default_configuration_initialized
  end

  @default_configurations
end

.initialize_default_configurationObject



27
28
29
30
# File 'lib/blacklight/configuration.rb', line 27

def initialize_default_configuration
  @default_configurations&.map(&:call)
  @default_configuration_initialized = true
end

.initialized_default_configuration?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/blacklight/configuration.rb', line 32

def initialized_default_configuration?
  @default_configuration_initialized
end

.property(key, default: nil) ⇒ Object



11
12
13
# File 'lib/blacklight/configuration.rb', line 11

def property(key, default: nil)
  default_values[key] = default
end

Instance Method Details

#add_email_field(config_key, options) ⇒ Blacklight::Configuration::DisplayField #add_email_field(config_key, field) ⇒ Blacklight::Configuration::DisplayField #add_email_field(config_key, array) ⇒ Blacklight::Configuration::DisplayField

Overloads:

Parameters:

  • config_key (Symbol)

Returns:

See Also:



378
# File 'lib/blacklight/configuration.rb', line 378

define_field_access :email_field, Blacklight::Configuration::DisplayField

#add_facet_field(config_key, options) ⇒ Blacklight::Configuration::FacetField #add_facet_field(config_key, field) ⇒ Blacklight::Configuration::FacetField #add_facet_field(config_key, array) ⇒ Blacklight::Configuration::FacetField

Overloads:

Parameters:

  • config_key (Symbol)

Returns:

See Also:



360
# File 'lib/blacklight/configuration.rb', line 360

define_field_access :facet_field, Blacklight::Configuration::FacetField

#add_facet_fields_to_solr_request!Object #add_facet_fields_to_solr_request!(field, field, etc) ⇒ Object

Add any configured facet fields to the default solr parameters hash

Overloads:

  • #add_facet_fields_to_solr_request!Object

    add all facet fields to the solr request

  • #add_facet_fields_to_solr_request!(field, field, etc) ⇒ Object

    Parameters:

    • field (Symbol)

      Field names to add to the solr request



462
463
464
465
466
467
468
# File 'lib/blacklight/configuration.rb', line 462

def add_facet_fields_to_solr_request!(*fields)
  if fields.empty?
    self.add_facet_fields_to_solr_request = true
  else
    facet_fields.slice(*fields).each_value { |v| v.include_in_request = true }
  end
end

#add_field_configuration_to_solr_request!Object #add_field_configuration_to_solr_request!(field, field, etc) ⇒ Object

Add any configured facet fields to the default solr parameters hash

Overloads:

  • #add_field_configuration_to_solr_request!Object

    add all index, show, and facet fields to the solr request

  • #add_field_configuration_to_solr_request!(field, field, etc) ⇒ Object

    Parameters:

    • field (Symbol)

      Field names to add to the solr request



475
476
477
478
479
480
481
482
483
# File 'lib/blacklight/configuration.rb', line 475

def add_field_configuration_to_solr_request!(*fields)
  if fields.empty?
    self.add_field_configuration_to_solr_request = true
  else
    index_fields.slice(*fields).each_value { |v| v.include_in_request = true }
    show_fields.slice(*fields).each_value { |v| v.include_in_request = true }
    facet_fields.slice(*fields).each_value { |v| v.include_in_request = true }
  end
end

#add_index_field(config_key, options) ⇒ Blacklight::Configuration::IndexField #add_index_field(config_key, field) ⇒ Blacklight::Configuration::IndexField #add_index_field(config_key, array) ⇒ Blacklight::Configuration::IndexField

Overloads:

Parameters:

  • config_key (Symbol)

Returns:

See Also:



363
# File 'lib/blacklight/configuration.rb', line 363

define_field_access :index_field, Blacklight::Configuration::IndexField

#add_nav_action(name, opts = {}) ⇒ Object

Add a partial to the header navbar

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.



563
564
565
# File 'lib/blacklight/configuration.rb', line 563

def add_nav_action(name, opts = {})
  add_action(navbar.partials, name, opts)
end

#add_results_collection_tool(name, opts = {}) ⇒ Object

Add a tool for the search result list itself

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.



551
552
553
# File 'lib/blacklight/configuration.rb', line 551

def add_results_collection_tool(name, opts = {})
  add_action(index.collection_actions, name, opts)
end

#add_results_document_tool(name, opts = {}) ⇒ Object

Add a partial to the tools for each document in the search results.

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.



557
558
559
# File 'lib/blacklight/configuration.rb', line 557

def add_results_document_tool(name, opts = {})
  add_action(index.document_actions, name, opts)
end

#add_search_field(config_key, options) ⇒ Blacklight::Configuration::SearchField #add_search_field(config_key, field) ⇒ Blacklight::Configuration::SearchField #add_search_field(config_key, array) ⇒ Blacklight::Configuration::SearchField

Overloads:

Parameters:

  • config_key (Symbol)

Returns:

See Also:



369
# File 'lib/blacklight/configuration.rb', line 369

define_field_access :search_field, Blacklight::Configuration::SearchField

#add_show_field(config_key, options) ⇒ Blacklight::Configuration::ShowField #add_show_field(config_key, field) ⇒ Blacklight::Configuration::ShowField #add_show_field(config_key, array) ⇒ Blacklight::Configuration::ShowField

Overloads:

Parameters:

  • config_key (Symbol)

Returns:

See Also:



366
# File 'lib/blacklight/configuration.rb', line 366

define_field_access :show_field, Blacklight::Configuration::ShowField

#add_show_tools_partial(name, opts = {}) ⇒ Object

Add a partial to the tools when rendering a document.

Parameters:

  • name (String)

    the name of the document partial

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :if (Symbol, Proc)

    render this action if the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.

  • :unless (Symbol, Proc)

    render this action unless the method identified by the symbol or the proc evaluates to true. The proc will receive the action configuration and the document or documents for the action.



542
543
544
545
546
# File 'lib/blacklight/configuration.rb', line 542

def add_show_tools_partial(name, opts = {})
  opts[:partial] ||= 'document_action'
  add_action(show.document_actions, name, opts)
  klass && ActionBuilder.new(klass, name, opts).build
end

#add_sms_field(config_key, options) ⇒ Blacklight::Configuration::DisplayField #add_sms_field(config_key, field) ⇒ Blacklight::Configuration::DisplayField #add_sms_field(config_key, array) ⇒ Blacklight::Configuration::DisplayField

Overloads:

Parameters:

  • config_key (Symbol)

Returns:

See Also:



375
# File 'lib/blacklight/configuration.rb', line 375

define_field_access :sms_field, Blacklight::Configuration::DisplayField

#add_sort_field(config_key, options) ⇒ Blacklight::Configuration::SortField #add_sort_field(config_key, field) ⇒ Blacklight::Configuration::SortField #add_sort_field(config_key, array) ⇒ Blacklight::Configuration::SortField

Overloads:

Parameters:

  • config_key (Symbol)

Returns:

See Also:



372
# File 'lib/blacklight/configuration.rb', line 372

define_field_access :sort_field, Blacklight::Configuration::SortField

#build(klass) ⇒ Object Also known as: inheritable_copy

builds a copy for the provided controller class

Parameters:

  • klass (Class)

    configuration host class



496
497
498
499
500
# File 'lib/blacklight/configuration.rb', line 496

def build(klass)
  deep_copy.tap do |conf|
    conf.klass = klass
  end
end

#configure {|config| ... } ⇒ Blacklight::Configuration

DSL helper

Yields:

  • (config)

Yield Parameters:

Returns:



403
404
405
406
# File 'lib/blacklight/configuration.rb', line 403

def configure
  yield self if block_given?
  self
end

#deep_copyObject

Provide a ‘deep copy’ of Blacklight::Configuration that can be modified without effecting the original Blacklight::Configuration instance.

Note: Rails provides ‘#deep_dup`, but it aggressively `#dup`’s class names too, turning them into anonymous class instances.



490
491
492
# File 'lib/blacklight/configuration.rb', line 490

def deep_copy
  deep_transform_values_in_object(self, &method(:_deep_copy))
end

#default_search_fieldBlacklight::Configuration::SearchField

Returns default search field, used for simpler display in history, etc. if not set, defaults to first defined search field



411
412
413
414
# File 'lib/blacklight/configuration.rb', line 411

def default_search_field
  field = super || search_fields.values.find { |f| f.default == true }
  field || search_fields.values.first
end

#default_sort_fieldBlacklight::Configuration::SortField

Returns default sort field, used for simpler display in history, etc. if not set, defaults to first defined sort field



419
420
421
422
# File 'lib/blacklight/configuration.rb', line 419

def default_sort_field
  field = super || sort_fields.values.find { |f| f.default == true }
  field || sort_fields.values.first
end

#default_title_fieldString

Returns:

  • (String)


425
426
427
# File 'lib/blacklight/configuration.rb', line 425

def default_title_field
  document_model.unique_key || 'id'
end

#facet_configuration_for_field(field) ⇒ Blacklight::Configuration::FacetField

Returns Blacklight facet configuration for the solr field.

Parameters:

  • field (String)

    Solr facet name

Returns:



431
432
433
434
435
436
437
438
# File 'lib/blacklight/configuration.rb', line 431

def facet_configuration_for_field(field)
  # short-circuit on the common case, where the solr field name and the blacklight field name are the same.
  return facet_fields[field] if facet_fields[field] && facet_fields[field].field == field

  # Find the facet field configuration for the solr field, or provide a default.
  facet_fields.values.find { |v| v.field.to_s == field.to_s } ||
    FacetField.new(field: field).normalize!
end

#facet_field_names(group = nil) ⇒ Array<String>

Returns a list of the facet field names from the configuration.

Parameters:

  • group (String) (defaults to: nil)

    (nil) a group name of facet fields

Returns:

  • (Array<String>)

    a list of the facet field names from the configuration



442
443
444
# File 'lib/blacklight/configuration.rb', line 442

def facet_field_names(group = nil)
  facet_fields_in_group(group).map(&:field)
end

#facet_fields_in_group(group) ⇒ Array<Blacklight::Configuration::FacetField>

Returns a list of facet fields.

Parameters:

  • group (String)

    (nil) a group name of facet fields

Returns:



448
449
450
# File 'lib/blacklight/configuration.rb', line 448

def facet_fields_in_group(group)
  facet_fields.values.select { |opts| group == opts[:group] }
end

#facet_group_namesArray<String>

Returns a list of facet groups.

Returns:

  • (Array<String>)

    a list of facet groups



453
454
455
# File 'lib/blacklight/configuration.rb', line 453

def facet_group_names
  facet_fields.map { |_facet, opts| opts[:group] }.uniq
end

#for_display_type(display_type, &_block) ⇒ Object

Add a section of config that only applies to documents with a matching display type



569
570
571
572
573
574
575
# File 'lib/blacklight/configuration.rb', line 569

def for_display_type display_type, &_block
  self.fields_for_type ||= {}

  (fields_for_type[display_type] ||= self.class.new).tap do |conf|
    yield(conf) if block_given?
  end
end

#header_componentObject



40
41
42
# File 'lib/blacklight/configuration.rb', line 40

def header_component
  super || Blacklight::HeaderComponent
end

#index_fields_for(document_or_display_types) ⇒ Object

Return a list of fields for the index display that should be used for the provided document. This respects any configuration made using for_display_type



580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
# File 'lib/blacklight/configuration.rb', line 580

def index_fields_for(document_or_display_types)
  display_types = if document_or_display_types.is_a? Blacklight::Document
                    Deprecation.warn self, "Calling index_fields_for with a #{document_or_display_types.class} is deprecated and will be removed in Blacklight 8. Pass the display type instead."
                    document_or_display_types[index.display_type_field || 'format']
                  else
                    document_or_display_types
                  end

  fields = {}.with_indifferent_access

  Array.wrap(display_types).each do |display_type|
    fields = fields.merge(for_display_type(display_type).index_fields)
  end

  fields.merge(index_fields)
end

#locate_search_builder_classObject



106
107
108
# File 'lib/blacklight/configuration.rb', line 106

def locate_search_builder_class
  ::SearchBuilder
end

Returns The destination for the link around the logo in the header.

Returns:

  • (String)

    The destination for the link around the logo in the header



395
396
397
# File 'lib/blacklight/configuration.rb', line 395

def logo_link
  super || Rails.application.routes.url_helpers.root_path
end

#repositoryBlacklight::Repository

Returns:

  • (Blacklight::Repository)


390
391
392
# File 'lib/blacklight/configuration.rb', line 390

def repository
  repository_class.new(self)
end

#show_fields_for(document_or_display_types) ⇒ Object

Return a list of fields for the show page that should be used for the provided document. This respects any configuration made using for_display_type



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
# File 'lib/blacklight/configuration.rb', line 600

def show_fields_for(document_or_display_types)
  display_types = if document_or_display_types.is_a? Blacklight::Document
                    Deprecation.warn self, "Calling show_fields_for with a #{document_or_display_types.class} is deprecated and will be removed in Blacklight 8. Pass the display type instead."
                    document_or_display_types[show.display_type_field || 'format']
                  else
                    document_or_display_types
                  end

  unless display_types.respond_to?(:each)
    Deprecation.warn self, "Calling show_fields_for with a scalar value is deprecated. It must receive an Enumerable."
    display_types = Array.wrap(display_types)
  end
  fields = {}.with_indifferent_access

  display_types.each do |display_type|
    fields = fields.merge(for_display_type(display_type).show_fields)
  end

  fields.merge(show_fields)
end

#view_config(view_type = nil, action_name: :index) ⇒ Blacklight::Configuration::ViewConfig

Get a view configuration for the given view type + action. The effective view configuration is inherited from:

  • the configuration from blacklight_config.view with the key ‘view_type`

  • the configuration from blacklight_config.action_mapping with the key ‘action_name`

  • any parent config for the action map result above

  • the action_mapping default configuration

  • the top-level index/show view configuration

Parameters:

  • view_type (Symbol, #to_sym) (defaults to: nil)

Returns:



513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/blacklight/configuration.rb', line 513

def view_config(view_type = nil, action_name: :index)
  view_type &&= view_type.to_sym
  action_name &&= action_name.to_sym
  action_name ||= :index

  if view_type == :show
    action_name = view_type
    view_type = nil
  end

  @view_config[[view_type, action_name]] ||= begin
    if view_type.nil?
      action_config(action_name)
    else
      base_config = action_config(action_name)
      base_config.merge(view.fetch(view_type, {}))
    end
  end
end