Module: IiifPrintHelper

Defined in:
app/helpers/iiif_print_helper.rb

Instance Method Summary collapse

Instance Method Details

#highlight_matches(document, hl_fl, hl_tag) ⇒ String

return the matching highlighted terms from Solr highlight field

Parameters:

  • document (SolrDocument)
  • hl_fl (String)

    the name of the Solr field with highlights

  • hl_tag (String)

    the HTML element name used for marking highlights configured in Solr as hl.tag.pre value

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/iiif_print_helper.rb', line 30

def highlight_matches(document, hl_fl, hl_tag)
  hl_matches = []
  # regex: find all chars between hl_tag, but NOT other <element>
  regex = /<#{hl_tag}>[^<>]+<\/#{hl_tag}>/
  hls = document.highlight_field(hl_fl)
  return nil if hls.blank?
  hls.each do |hl|
    matches = hl.scan(regex)
    matches.each do |match|
      hl_matches << match.gsub(/<[\/]*#{hl_tag}>/, '').downcase
    end
  end
  hl_matches.uniq.sort.join(' ')
end

#iiif_search_anchor(query_params_hash) ⇒ String

create link anchor to be read by UniversalViewer in order to show keyword search

Parameters:

  • query_params_hash (Hash)

    current_search_session.query_params

Returns:

  • (String)

    or [nil] anchor



7
8
9
10
11
# File 'app/helpers/iiif_print_helper.rb', line 7

def iiif_search_anchor(query_params_hash)
  query = search_query(query_params_hash)
  return nil if query.blank?
  "?h=#{query}"
end

#render_ocr_snippets(options = {}) ⇒ String

print the ocr snippets. if more than one, separate with <br/>

rubocop:disable Rails/OutputSafety

Parameters:

  • options (Hash) (defaults to: {})

    options hash provided by Blacklight

Returns:

  • (String)

    snippets HTML to be rendered



51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/helpers/iiif_print_helper.rb', line 51

def render_ocr_snippets(options = {})
  snippets = options[:value]
  snippets_content = [('div',
                                  "... #{snippets.first} ...".html_safe,
                                  class: 'ocr_snippet first_snippet')]
  if snippets.length > 1
    snippets_content << render(partial: 'catalog/snippets_more',
                               locals: { snippets: snippets.drop(1),
                                         options: options })
  end
  snippets_content.join("\n").html_safe
end

#search_query(query_params_hash) ⇒ String

get the query, which may be in a different object,

depending if regular search or newspapers_search was run

Parameters:

  • query_params_hash (Hash)

    current_search_session.query_params

Returns:

  • (String)

    or [nil] query



18
19
20
# File 'app/helpers/iiif_print_helper.rb', line 18

def search_query(query_params_hash)
  query_params_hash[:q] || query_params_hash[:all_fields]
end