Module: Blacklight::Configuration::Fields

Extended by:
ActiveSupport::Concern
Included in:
Blacklight::Configuration
Defined in:
lib/blacklight/configuration/fields.rb

Overview

This mixin provides Blacklight::Configuration with generic solr fields configuration

Instance Method Summary collapse

Instance Method Details

#add_blacklight_field(config_key, field_key) ⇒ Object #add_blacklight_field(config_key) ⇒ Object #add_blacklight_field(config_key, options) ⇒ Object #add_blacklight_field(config_key, field) ⇒ Object #add_blacklight_field(config_key, fields) ⇒ Object

Add a solr field configuration to the given configuration key

The recommended and strongly encouraged format is a field name, configuration pair, e.g.:

add_blacklight_field :index_field, 'format', :label => 'Format'

Alternative formats include:

  • a field name and block format:

  • a plain block:

  • a configuration hash:

  • a Field instance:

  • an array of hashes:

Overloads:

  • #add_blacklight_field(config_key, field_key) ⇒ Object

    Parameters:

    • config_key (Symbol)
    • field_key (Symbol, String)

      add_blacklight_field :index_field, ‘format’ do |field|

      field.label = 'Format'
      

      end

  • #add_blacklight_field(config_key) ⇒ Object

    Parameters:

    • config_key (Symbol)

      add_blacklight_field :index_field do |field|

      field.field = 'format'
      field.label = 'Format'
      

      end

  • #add_blacklight_field(config_key, options) ⇒ Object

    Parameters:

    • config_key (Symbol)
    • options (Hash)

      add_blacklight_field :index_field, :field => ‘format’, :label => ‘Format’

  • #add_blacklight_field(config_key, field) ⇒ Object

    Parameters:

    • config_key (Symbol)
    • field (Blacklight::Configuration::Field)

      add_blacklight_field :index_field, IndexField.new(:field => ‘format’, :label => ‘Format’)

  • #add_blacklight_field(config_key, fields) ⇒ Object

    Parameters:

    • config_key (Symbol)
    • fields (Array<Blacklight::Configuration::Field, Hash>)

      add_blacklight_field :index_field, [{ :field => ‘format’, :label => ‘Format’ }, IndexField.new(:field => ‘date’, :label => ‘Date’)]



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
# File 'lib/blacklight/configuration/fields.rb', line 84

def add_blacklight_field config_key, *args, &block
  field_config = case args.first
                 when String
                   field_config_from_key_and_hash(config_key, *args)
                 when Symbol
                   args[0] = args[0].to_s
                   field_config_from_key_and_hash(config_key, *args)
                 when Array
                   field_config_from_array(config_key, *args, &block)
                   return # we've iterated over the array above.
                 else
                   field_config_from_field_or_hash(config_key, *args)
                 end

  if (field_config.field || field_config.key).to_s =~ /\*/
    field_config.match = Regexp.new("^#{(field_config.field || field_config.key).to_s.gsub('*', '.+')}$")
  end

  # look up any dynamic fields
  if field_config.match
    handle_matching_fields(config_key, field_config, &block)
    return
  end

  if block_given?
    yield field_config
  end

  field_config.normalize!(self)
  field_config.validate!

  raise "A #{config_key} with the key #{field_config.key} already exists." if self[config_key.pluralize][field_config.key].present?

  self[config_key.pluralize][field_config.key] = field_config
end