class ActiveFedora::Indexing::Inserter

Utilities for adding fields to index documents

def self.create_and_insert_terms(field_name_base, value, index_as, solr_doc)

Parameters:
  • solr_doc (Hash) -- the index doc to add to
  • index_as (Array) -- the index type suffixes
  • value (String) -- the value to insert into the index
  • field_name_base (String) -- the field name
def self.create_and_insert_terms(field_name_base, value, index_as, solr_doc)
  index_as.each do |indexer|
    insert_field(solr_doc, field_name_base, value, indexer)
  end
end

def self.insert_field(doc, name, value, *indexer_args)

@returns [Hash] doc the document that was provided with the new field inserted
@params [Array,Hash] indexer_args the arguments that find the indexer
@params [String,Date,Array] value the value (or array of values) to be inserted
@params [String] name the name of the field (without the suffix)
@params [Hash] doc the hash to insert the value into
def self.insert_field(doc, name, value, *indexer_args)
  # adding defaults indexer
  indexer_args = [:stored_searchable] if indexer_args.empty?
  ActiveFedora.index_field_mapper.solr_names_and_values(name, value, indexer_args).each do |k, v|
    doc[k] ||= []
    if v.is_a? Array
      doc[k] += v
    else
      doc[k] = v
    end
  end
  doc
end