Module: Arclight::SharedIndexingBehavior

Included in:
CustomComponent, CustomDocument
Defined in:
lib/arclight/shared_indexing_behavior.rb

Overview

A mixin intended to share indexing behavior between the CustomDocument and CustomComponent classes

Instance Method Summary collapse

Instance Method Details

#add_date_ranges(solr_doc) ⇒ Object



81
82
83
# File 'lib/arclight/shared_indexing_behavior.rb', line 81

def add_date_ranges(solr_doc)
  Solrizer.insert_field(solr_doc, 'date_range', unitdate_for_range.years, :facetable)
end

#add_digital_content(prefix:, solr_doc:) ⇒ Object



66
67
68
69
70
71
# File 'lib/arclight/shared_indexing_behavior.rb', line 66

def add_digital_content(prefix:, solr_doc:)
  dao = ng_xml.xpath("#{prefix}/dao").to_a
  return if dao.blank?
  field_name = Solrizer.solr_name('digital_objects', :displayable)
  solr_doc[field_name] = digital_objects(dao)
end

#add_normalized_title(solr_doc) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/arclight/shared_indexing_behavior.rb', line 85

def add_normalized_title(solr_doc)
  dates = Arclight::NormalizedDate.new(unitdate_inclusive.first, unitdate_bulk.first, unitdate_other.first).to_s
  title = Arclight::NormalizedTitle.new(solr_doc['title_ssm'].try(:first), dates).to_s
  solr_doc['normalized_title_ssm'] = [title]
  solr_doc['normalized_date_ssm'] = [dates]
  title
end

#clean_facets_array(facets_array) ⇒ Object

Return a cleaned array of facets without marc subfields

E.g. clean_facets_array(

  ['FacetValue1 |z FacetValue2','FacetValue3']
) => ['FacetValue1 -- FacetValue2', 'FacetValue3']


34
35
36
# File 'lib/arclight/shared_indexing_behavior.rb', line 34

def clean_facets_array(facets_array)
  Array(facets_array).map { |text| fix_subfield_demarcators(text) }.compact.uniq
end

#digital_objects(objects) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/arclight/shared_indexing_behavior.rb', line 73

def digital_objects(objects)
  objects.map do |dao|
    label = dao.attributes['title'].try(:value) || dao.xpath('daodesc/p').try(:text)
    href = (dao.attributes['href'] || dao.attributes['xlink:href']).try(:value)
    Arclight::DigitalObject.new(label: label, href: href).to_json
  end
end

#fix_subfield_demarcators(value) ⇒ Object

Replace MARC style subfield demarcators

Usage: fix_subfield_demarcators(“Subject 1 |z Sub-Subject 2”) => “Subject 1 – Sub-Subject 2”



41
42
43
# File 'lib/arclight/shared_indexing_behavior.rb', line 41

def fix_subfield_demarcators(value)
  value.gsub(/\|\w{1}/, '--')
end

#names_array(elements, parent:) ⇒ Object



23
24
25
26
27
# File 'lib/arclight/shared_indexing_behavior.rb', line 23

def names_array(elements, parent:)
  xpath_elements = elements.map { |el| "local-name()='#{el}'" }.join(' or ')
  names = search("//#{parent}/controlaccess/*[#{xpath_elements}]").to_a
  clean_facets_array(names.flatten.map(&:text))
end

#online_content?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/arclight/shared_indexing_behavior.rb', line 93

def online_content?
  search('//dao[@href]').present?
end

#repository_as_configured(repository) ⇒ Object

If a repository slug is provided via an environment variable ‘REPOSITORY_ID`, then use that to lookup the name rather than the parsed out name from the EAD

Parameters:

  • `repository` (String)

    the default repository name



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/arclight/shared_indexing_behavior.rb', line 53

def repository_as_configured(repository)
  slug = ENV['REPOSITORY_ID']
  if slug.present?
    begin
      Arclight::Repository.find_by(slug: slug).name
    rescue => e
      raise "The repository slug '#{slug}' was given but it is not found in the Repository configuration data: #{e}"
    end
  else
    repository
  end
end

#search(path) ⇒ Object

Wrap OM’s find_by_xpath for convenience



46
47
48
# File 'lib/arclight/shared_indexing_behavior.rb', line 46

def search(path)
  find_by_xpath(path) # rubocop:disable DynamicFindBy
end

#subjects_array(elements, parent:) ⇒ Object



17
18
19
20
21
# File 'lib/arclight/shared_indexing_behavior.rb', line 17

def subjects_array(elements, parent:)
  xpath_elements = elements.map { |el| "local-name()='#{el}'" }.join(' or ')
  subjects = search("//#{parent}/controlaccess/*[#{xpath_elements}]").to_a
  clean_facets_array(subjects.flatten.map(&:text))
end

#unitdate_for_rangeYearRange

Returns all of the years between the given years.

Returns:

  • (YearRange)

    all of the years between the given years

See Also:



10
11
12
13
14
15
# File 'lib/arclight/shared_indexing_behavior.rb', line 10

def unitdate_for_range
  range = YearRange.new
  return range if normal_unit_dates.blank?
  range << range.parse_ranges(normal_unit_dates)
  range
end