Module: IiifPrintHelper

Includes:
IiifPrint::IiifPrintHelperBehavior
Defined in:
app/helpers/iiif_print_helper.rb,
lib/generators/iiif_print/templates/helpers/iiif_print_helper.rb

Instance Method Summary collapse

Methods included from IiifPrint::IiifPrintHelperBehavior

#render_ocr_snippets

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

#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