module Krikri::SearchResultsHelperBehavior
This module helps controllers that display results from a querying the search index.
Public Instance Methods
link_to_document(document, field_or_opts = nil, opts = {})
click to toggle source
Override method in Blacklight::UrlHelperBehavior.
# File lib/krikri/search_results_helper_behavior.rb, line 12 def link_to_document(document, field_or_opts = nil, opts = {}) link_to field_or_opts, url_for_document(document, { :provider => params[:provider] }) end
render_bookmarks_control?()
click to toggle source
Disable bookmarks.
# File lib/krikri/search_results_helper_behavior.rb, line 18 def render_bookmarks_control? false end
render_enriched_record(document)
click to toggle source
Render enriched record for view @param [Krikri::SearchIndexDocument] @return [String]
# File lib/krikri/search_results_helper_behavior.rb, line 25 def render_enriched_record(document) agg = document.aggregation return error_msg('Aggregation not found.') unless agg.present? JSON.pretty_generate(agg.to_jsonld['@graph']) end
render_original_record(document)
click to toggle source
Render original record for view @param [Krikri::SearchIndexDocument] @return [String]
# File lib/krikri/search_results_helper_behavior.rb, line 34 def render_original_record(document) agg = document.aggregation return error_msg('Aggregation not found.') unless agg.present? begin original_record = agg.original_record rescue StandardError => e logger.error e.message return error_msg(e.message) end return error_msg('Original record not found.') unless original_record.present? prettify_string(original_record.to_s, original_record.content_type) end
render_thumbnail_tag(document, image_options = {}, url_options = {})
click to toggle source
Override method in Blacklight::CatalogHelperBehavior.
# File lib/krikri/search_results_helper_behavior.rb, line 7 def render_thumbnail_tag(document, image_options = {}, url_options = {}) link_to image_tag(thumbnail_url(document)), url_for_document(document) end
Private Instance Methods
error_msg(message = '')
click to toggle source
# File lib/krikri/search_results_helper_behavior.rb, line 74 def error_msg(message = '') "There was a problem getting the record.\n\n#{message}" end
prettify_json_string(string)
click to toggle source
# File lib/krikri/search_results_helper_behavior.rb, line 58 def prettify_json_string(string) begin return JSON.pretty_generate(JSON.parse(string)) rescue JSON::ParserError return string end end
prettify_string(string, mime_type)
click to toggle source
# File lib/krikri/search_results_helper_behavior.rb, line 52 def prettify_string(string, mime_type) string = prettify_json_string(string) if mime_type.include? 'json' string = prettify_xml_string(string) if mime_type.include? 'xml' string end
prettify_xml_string(string)
click to toggle source
# File lib/krikri/search_results_helper_behavior.rb, line 66 def prettify_xml_string(string) if Nokogiri.XML(string).errors.empty? doc = Nokogiri.XML(string) { |c| c.noblanks } return doc.to_xml(indent: 2) end string end