From d533bfcca94727f6734d714bf9417b1c8cd8dcd7 Mon Sep 17 00:00:00 2001 From: Mason Ballengee Date: Fri, 13 Sep 2024 11:17:03 -0400 Subject: [PATCH] WIP - Improve thumbnail load times IndexedFiles must be reindexed for this work to have an effect. Without reindexing all thumbnails will display as the missing content icon. Improvements needed: - Populate with icon data instead of `asset_path` when item is missing thumbnail - Move thumbnail logic out of termfreq method and into its own method - This work probably needs an explicit fallback for when a video is missing a thumbnail or `content_ss` is otherwise unable to be pulled from solr. Investigation needed: - Does this affect overall search load times? Need to test with larger datasets. --- app/helpers/application_helper.rb | 11 ++++++++--- app/models/indexed_file.rb | 3 ++- app/models/search_builder.rb | 10 +++++++++- app/views/catalog/_thumbnail_media_object.html.erb | 8 ++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 789d996260..3f3517dc56 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -66,7 +66,7 @@ def image_for(document) if master_file_id if video_count > 0 - thumbnail_master_file_path(master_file_id) + document["sections"][:docs].first["thumbnail"][:docs].first["content_ss"] elsif audio_count > 0 asset_path('audio_icon.png') else @@ -86,9 +86,14 @@ def image_for(document) end def avalon_image_tag(document, image_options) - image_url = image_for(document) + image = image_for(document) link_to(media_object_path(document[:id]), {class: 'result-thumbnail'}) do - image_url.present? ? image_tag(image_url) : image_tag('no_icon.png') + return image_tag('no_icon.png') unless image.present? + if image.start_with?(root_url) + image_tag(image) + else + image_tag("data:image/jpg;base64,#{image}") + end end end diff --git a/app/models/indexed_file.rb b/app/models/indexed_file.rb index 4b4334effd..d39adeee55 100644 --- a/app/models/indexed_file.rb +++ b/app/models/indexed_file.rb @@ -26,10 +26,11 @@ def to_solr(solr_doc = {}, opts = {}) return solr_doc unless opts[:external_index] solr_doc.tap do |doc| doc[:id] = id + doc[:isPartOf_ssi] = id.gsub(/\/.*/, '') doc[:has_model_ssim] = self.class.name doc[:uri_ss] = uri.to_s doc[:mime_type_ss] = mime_type - doc[:original_name_ss] = original_name + doc[:original_name_ssi] = original_name doc[:size_is] = content.present? ? content.size : 0 doc[:'empty?_bs'] = content.blank? if index_content? diff --git a/app/models/search_builder.rb b/app/models/search_builder.rb index 6b02d50579..7d4550a8f2 100644 --- a/app/models/search_builder.rb +++ b/app/models/search_builder.rb @@ -65,7 +65,7 @@ def term_frequency_counts(solr_parameters) transcripts_present = SupplementalFile.with_tag('transcript').any? # List of fields for displaying on search results (Blacklight index fields) - fl = ['id', 'has_model_ssim', 'title_tesi', 'date_issued_ssi', 'creator_ssim', 'abstract_ssi', 'duration_ssi', 'section_id_ssim', 'avalon_resource_type_ssim'] + fl = ['id', 'has_model_ssim', 'title_tesi', 'date_issued_ssi', 'creator_ssim', 'abstract_ssi', 'duration_ssi', 'section_id_ssim', 'avalon_resource_type_ssim', 'content_ss'] # Add a field for matching child sections fl << "sections:[subquery]" @@ -81,11 +81,19 @@ def term_frequency_counts(solr_parameters) fl << "metadata_tf_#{i}:termfreq(mods_tesim,#{RSolr.solr_escape(term)})" fl << "structure_tf_#{i}:termfreq(section_label_tesim,#{RSolr.solr_escape(term)})" fl << "transcript_tf_#{i}" if transcripts_present + fl << "thumbnail" sections_fl << "transcript_tf_#{i}" if transcripts_present transcripts_fl << "transcript_tf_#{i}:termfreq(transcript_tsim,#{RSolr.solr_escape(term)})" if transcripts_present + sections_fl << "thumbnail:[subquery]" end solr_parameters[:fl] = fl.join(',') + solr_parameters["sections.thumbnail.q"] = "{!terms f=isPartOf_ssi v=$row.id}{!join to=id from=isPartOf_ssim}" + solr_parameters["sections.thumbnail.fq"] = "original_name_ssi:thumbnail.jpg" + solr_parameters["sections.thumbnail.defType"] = "lucene" + solr_parameters["sections.thumbnail.rows"] = 1 + solr_parameters["sections.thumbnail.fl"] = "content_ss" + return solr_parameters unless transcripts_present sections_fl << "transcripts:[subquery]" solr_parameters["sections.fl"] = sections_fl.join(',') diff --git a/app/views/catalog/_thumbnail_media_object.html.erb b/app/views/catalog/_thumbnail_media_object.html.erb index 7c91659b6d..90f91270c7 100644 --- a/app/views/catalog/_thumbnail_media_object.html.erb +++ b/app/views/catalog/_thumbnail_media_object.html.erb @@ -15,9 +15,13 @@ Unless required by applicable law or agreed to in writing, software distributed %>
- <% if image_url = image_for(document) %> + <% if image = image_for(document) %> <%= link_to(media_object_path(document[:id]), aria: { hidden: 'true'}, tabindex: -1, class: 'result-thumbnail') do %> - <%= image_tag( image_url, alt: "" ) %> + <% if image.start_with?(root_url) %> + <%= image_tag( image, alt: "") %> + <% else %> + <%= image_tag( "data:image/jpg;base64,#{image}", alt: "" ) %> + <% end %> <% end %> <% else %> <%= image_tag 'no_icon.png', alt: "", class: 'result-thumbnail no-icon' %>