Module: IiifPrintHelper
- Defined in:
- app/helpers/iiif_print_helper.rb
Instance Method Summary collapse
-
#highlight_matches(document, hl_fl, hl_tag) ⇒ String
return the matching highlighted terms from Solr highlight field.
-
#iiif_search_anchor(query_params_hash) ⇒ String
create link anchor to be read by UniversalViewer in order to show keyword search.
-
#render_ocr_snippets(options = {}) ⇒ String
print the ocr snippets.
-
#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.
Instance Method Details
#highlight_matches(document, hl_fl, hl_tag) ⇒ String
return the matching highlighted terms from Solr highlight field
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
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
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( = {}) snippets = [:value] snippets_content = [content_tag('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: }) 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
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 |