Class: ActiveFedora::Indexing::Inserter

Inherits:
Object
  • Object
show all
Defined in:
lib/active_fedora/indexing/inserter.rb

Overview

Utilities for adding fields to index documents

Class Method Summary collapse

Class Method Details

.create_and_insert_terms(field_name_base, value, index_as, solr_doc) ⇒ Object

@example:

solr_doc = {}
create_and_insert_terms('title', 'War and Peace', [:displayable, :searchable], solr_doc)
solr_doc
# => {"title_ssm"=>["War and Peace"], "title_teim"=>["War and Peace"]}

Parameters:

  • field_name_base (String)

    the field name

  • value (String)

    the value to insert into the index

  • index_as (Array<Symbol>)

    the index type suffixes

  • solr_doc (Hash)

    the index doc to add to



14
15
16
17
18
# File 'lib/active_fedora/indexing/inserter.rb', line 14

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

.insert_field(doc, name, value, *indexer_args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_fedora/indexing/inserter.rb', line 25

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