Module: Blacklight::Document::SemanticFields

Extended by:
ActiveSupport::Concern
Included in:
Blacklight::Document
Defined in:
app/models/concerns/blacklight/document/semantic_fields.rb

Instance Method Summary collapse

Instance Method Details

#to_semantic_valuesObject

Returns a hash keyed by semantic tokens, value is an array of strings. (Array to handle multi-value fields). If no value(s) available, empty array is returned.

Default implementation here uses field_semantics to just take values from Solr stored fields. Extensions can over-ride this method to provide better/different lookup, but extensions should call super and modify hash returned, to avoid unintentionally erasing values provided by other extensions.



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/concerns/blacklight/document/semantic_fields.rb', line 33

def to_semantic_values
  @semantic_value_hash ||= self.class.field_semantics.each_with_object(Hash.new { |hash, key| hash[key] = [] }) do |(key, field_names), hash|
    ##
    # Handles single string field_name or an array of field_names
    value = Array.wrap(field_names).map { |field_name| self[field_name] }.flatten.compact

    # Make single and multi-values all arrays, so clients
    # don't have to know.
    hash[key] = value unless value.empty?
  end

  @semantic_value_hash ||= {}
end