Class: Blacklight::Configuration
- Inherits:
-
OpenStructWithHashAccess
- Object
- OpenStruct
- OpenStructWithHashAccess
- Blacklight::Configuration
- 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, FacetField, Field, NullField, SearchField, SortField, ToolConfig, ViewConfig
Class Method Summary collapse
Instance Method Summary collapse
-
#add_facet_fields_to_solr_request!(*fields) ⇒ Object
Add any configured facet fields to the default solr parameters hash.
-
#add_field_configuration_to_solr_request!(*fields) ⇒ Object
Add any configured facet fields to the default solr parameters hash.
-
#add_nav_action(name, opts = {}) ⇒ Object
Add a partial to the header navbar.
-
#add_results_collection_tool(name, opts = {}) ⇒ Object
Add a tool for the search result list itself.
-
#add_results_document_tool(name, opts = {}) ⇒ Object
Add a partial to the tools for each document in the search results.
-
#add_show_tools_partial(name, opts = {}) ⇒ Object
Add a partial to the tools when rendering a document.
-
#configure {|_self| ... } ⇒ Object
DSL helper.
- #connection_config ⇒ Object
-
#deep_copy ⇒ Object
(also: #inheritable_copy)
Provide a 'deep copy' of Blacklight::Configuration that can be modified without effecting the original Blacklight::Configuration instance.
- #default_per_page ⇒ Object
-
#default_search_field ⇒ Object
Returns default search field, used for simpler display in history, etc.
-
#default_sort_field ⇒ Object
Returns default sort field, used for simpler display in history, etc.
- #default_title_field ⇒ Object
- #document_model ⇒ Object
-
#document_model=(*args) ⇒ Object
only here to support alias_method.
- #document_presenter_class ⇒ Object deprecated Deprecated.
- #document_presenter_class=(klass) ⇒ Object deprecated Deprecated.
-
#facet_configuration_for_field(field) ⇒ Blacklight::Configuration::FacetField
Blacklight facet configuration for the solr field.
- #facet_paginator_class ⇒ Object
-
#initialize(hash = {}) {|_self| ... } ⇒ Configuration
constructor
A new instance of Configuration.
- #locate_search_builder_class ⇒ Object
- #repository_class ⇒ Object
- #response_model ⇒ Object
- #response_model=(*args) ⇒ Object
- #search_builder_class ⇒ Object
-
#view_config(view_type) ⇒ Object
Get a view configuration for the given view type including default values from the index configuration.
Methods included from Fields
#add_blacklight_field, #field_config_from_array, #field_config_from_field_or_hash, #field_config_from_key_and_hash, #handle_matching_fields, #hash_arg_to_config, #reflected_fields
Methods inherited from OpenStructWithHashAccess
#deep_dup, #merge, #merge!, #select, #sort_by, #sort_by!, #to_h
Constructor Details
#initialize(hash = {}) {|_self| ... } ⇒ Configuration
Returns a new instance of Configuration.
173 174 175 176 |
# File 'lib/blacklight/configuration.rb', line 173 def initialize(hash = {}) super(self.class.default_values.deep_dup.merge(hash)) yield(self) if block_given? end |
Class Method Details
.default_values ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/blacklight/configuration.rb', line 26 def default_values @default_values ||= begin { ## # === Search request configuration ## # HTTP method to use when making requests to solr; valid # values are :get and :post. http_method: :get, # The path to send requests to solr. solr_path: 'select', # Default values of parameters to send with every search request default_solr_params: {}, ## # === Single document request configuration ## # The solr request handler to use when requesting only a single document document_solr_request_handler: 'document', # THe path to send single document requests to solr document_solr_path: nil, document_unique_id_param: :id, # Default values of parameters to send when requesting a single document default_document_solr_params: { ## Blacklight provides these settings in the /document request handler ## by default, we just ask for all fields. #fl: '*', ## this is a fancy way to say "find the document by id using ## the value in the id query parameter" #q: "{!term f=#{unique_key} v=$id}", ## disable features we don't need #facet: false, #rows: 1 }, document_pagination_params: {}, fetch_many_document_params: nil, ## # == Response models ## Class for sending and receiving requests from a search index repository_class: nil, ## Class for converting Blacklight parameters to request parameters for the repository_class search_builder_class: nil, # model that maps index responses to the blacklight response model response_model: nil, # the model to use for each response document document_model: nil, # document presenter class used by helpers and views document_presenter_class: nil, # deprecated # Class for paginating long lists of facet fields facet_paginator_class: nil, # repository connection configuration connection_config: nil, ## # == Blacklight view configuration ## navbar: OpenStructWithHashAccess.new(partials: { }), # General configuration for all views index: ViewConfig::Index.new( # document presenter class used by helpers and views document_presenter_class: 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: 'format', # 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 ), # Additional configuration when displaying a single document show: ViewConfig::Show.new( # document presenter class used by helpers and views document_presenter_class: 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) ), # Configurations for specific types of index views view: NestedOpenStructWithHashAccess.new(ViewConfig, 'list', atom: { if: false, # by default, atom should not show up as an alternative view partials: [:document] }, rss: { if: false, # by default, rss should not show up as an alternative view partials: [:document] }), # # These fields are created and managed below by `defined_field_access` # facet_fields # index_fields # show_fields # sort_fields # search_fields ## # === Blacklight behavior configuration ## # Maxiumum number of spelling suggestions to offer spell_max: 5, # Maximum number of results to show per page max_per_page: 100, # Options for the user for number of results to show per page per_page: [10, 20, 50, 100], default_per_page: nil, # how many searches to save in session history search_history_window: 100, default_facet_limit: 10, default_more_limit: 20, # proc for determining whether the session is a crawler/bot # ex.: crawler_detector: lambda { |req| req.env['HTTP_USER_AGENT'] =~ /bot/ } crawler_detector: nil, autocomplete_suggester: 'mySuggester' } end end |
Instance Method Details
#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
272 273 274 275 276 277 278 |
# File 'lib/blacklight/configuration.rb', line 272 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 { |_k, 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
286 287 288 289 290 291 292 293 294 |
# File 'lib/blacklight/configuration.rb', line 286 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 { |_k, v| v.include_in_request = true } show_fields.slice(*fields).each { |_k, v| v.include_in_request = true } facet_fields.slice(*fields).each { |_k, v| v.include_in_request = true } end end |
#add_nav_action(name, opts = {}) ⇒ Object
Add a partial to the header navbar
351 352 353 |
# File 'lib/blacklight/configuration.rb', line 351 def add_nav_action(name, opts = {}) add_action(.partials, name, opts) end |
#add_results_collection_tool(name, opts = {}) ⇒ Object
Add a tool for the search result list itself
339 340 341 |
# File 'lib/blacklight/configuration.rb', line 339 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.
345 346 347 |
# File 'lib/blacklight/configuration.rb', line 345 def add_results_document_tool(name, opts = {}) add_action(index.document_actions, name, opts) end |
#add_show_tools_partial(name, opts = {}) ⇒ Object
Add a partial to the tools when rendering a document.
331 332 333 334 |
# File 'lib/blacklight/configuration.rb', line 331 def add_show_tools_partial(name, opts = {}) opts[:partial] ||= 'document_action' add_action(show.document_actions, name, opts) end |
#configure {|_self| ... } ⇒ Object
DSL helper
231 232 233 234 |
# File 'lib/blacklight/configuration.rb', line 231 def configure yield self if block_given? self end |
#connection_config ⇒ Object
210 211 212 |
# File 'lib/blacklight/configuration.rb', line 210 def connection_config super || Blacklight.connection_config end |
#deep_copy ⇒ Object Also known as: inheritable_copy
Provide a 'deep copy' of Blacklight::Configuration that can be modified without effecting the original Blacklight::Configuration instance.
Rails 4.x provides `#deep_dup`, but it aggressively `#dup`'s class names too. These model names should not be `#dup`'ed or we might break ActiveModel::Naming.
301 302 303 304 305 306 307 308 |
# File 'lib/blacklight/configuration.rb', line 301 def deep_copy deep_dup.tap do |copy| %w(repository_class response_model document_model document_presenter_class search_builder_class facet_paginator_class).each do |klass| # Don't copy if nil, so as not to prematurely autoload default classes copy.send("#{klass}=", send(klass)) unless fetch(klass.to_sym, nil).nil? end end end |
#default_per_page ⇒ Object
226 227 228 |
# File 'lib/blacklight/configuration.rb', line 226 def default_per_page super || per_page.first end |
#default_search_field ⇒ Object
Returns default search field, used for simpler display in history, etc. if not set, defaults to first defined search field
238 239 240 241 242 |
# File 'lib/blacklight/configuration.rb', line 238 def default_search_field field = super field ||= search_fields.values.find { |f| f.default == true } field || search_fields.values.first end |
#default_sort_field ⇒ Object
Returns default sort field, used for simpler display in history, etc. if not set, defaults to first defined sort field
246 247 248 249 250 |
# File 'lib/blacklight/configuration.rb', line 246 def default_sort_field field = super field ||= sort_fields.values.find { |f| f.default == true } field || sort_fields.values.first end |
#default_title_field ⇒ Object
252 253 254 |
# File 'lib/blacklight/configuration.rb', line 252 def default_title_field document_model.unique_key || 'id' end |
#document_model ⇒ Object
178 179 180 |
# File 'lib/blacklight/configuration.rb', line 178 def document_model super || ::SolrDocument end |
#document_model=(*args) ⇒ Object
only here to support alias_method
183 184 185 |
# File 'lib/blacklight/configuration.rb', line 183 def document_model=(*args) super end |
#document_presenter_class ⇒ Object
192 193 194 |
# File 'lib/blacklight/configuration.rb', line 192 def document_presenter_class super || Blacklight::DocumentPresenter end |
#document_presenter_class=(klass) ⇒ Object
197 198 199 |
# File 'lib/blacklight/configuration.rb', line 197 def document_presenter_class=(klass) super end |
#facet_configuration_for_field(field) ⇒ Blacklight::Configuration::FacetField
Returns Blacklight facet configuration for the solr field.
258 259 260 261 262 263 264 265 |
# File 'lib/blacklight/configuration.rb', line 258 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_paginator_class ⇒ Object
222 223 224 |
# File 'lib/blacklight/configuration.rb', line 222 def facet_paginator_class super || Blacklight::Solr::FacetPaginator end |
#locate_search_builder_class ⇒ Object
218 219 220 |
# File 'lib/blacklight/configuration.rb', line 218 def locate_search_builder_class ::SearchBuilder end |
#repository_class ⇒ Object
206 207 208 |
# File 'lib/blacklight/configuration.rb', line 206 def repository_class super || Blacklight::Solr::Repository end |
#response_model ⇒ Object
187 188 189 |
# File 'lib/blacklight/configuration.rb', line 187 def response_model super || Blacklight::Solr::Response end |
#response_model=(*args) ⇒ Object
202 203 204 |
# File 'lib/blacklight/configuration.rb', line 202 def response_model=(*args) super end |
#search_builder_class ⇒ Object
214 215 216 |
# File 'lib/blacklight/configuration.rb', line 214 def search_builder_class super || locate_search_builder_class end |
#view_config(view_type) ⇒ Object
Get a view configuration for the given view type including default values from the index configuration
314 315 316 317 318 319 320 |
# File 'lib/blacklight/configuration.rb', line 314 def view_config(view_type) if view_type == :show self.index.merge self.show else self.index.merge view.fetch(view_type, {}) end end |