From 31213f407a19214adac5ee9b31822fde4d211c98 Mon Sep 17 00:00:00 2001 From: Chris Colvard Date: Wed, 5 Jun 2024 15:39:04 -0400 Subject: [PATCH] Index avalon_resource_type the same as it is stored in fedora (#5846) Shift titleization into front end through a helper method utilized by the Blacklight facet. Resolves #5836 --- app/controllers/catalog_controller.rb | 2 +- app/helpers/application_helper.rb | 4 ++++ app/models/media_object.rb | 2 +- spec/helpers/application_helper_spec.rb | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 8fd86e5493..948342619a 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -80,7 +80,7 @@ class CatalogController < ApplicationController # # :show may be set to false if you don't want the facet to be drawn in the # facet bar - config.add_facet_field 'avalon_resource_type_ssim', label: 'Format', limit: 5, collapse: false + config.add_facet_field 'avalon_resource_type_ssim', label: 'Format', limit: 5, collapse: false, helper_method: :titleize config.add_facet_field 'creator_ssim', label: 'Main contributor', limit: 5 config.add_facet_field 'date_sim', label: 'Date', limit: 5 config.add_facet_field 'genre_ssim', label: 'Genres', limit: 5 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a5f1419f36..2c9debd60b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -226,6 +226,10 @@ def truncate_center label, output_label_length, end_length = 0 omission: "...#{label.last(end_length)}") end + def titleize value + value.is_a?(Array) ? value.map(&:titleize) : value.titleize + end + def master_file_meta_properties( m ) formatted_duration = m.duration ? Time.new(m.duration.to_i / 1000).iso8601 : '' item_type = m.is_video? ? 'http://schema.org/VideoObject' : 'http://schema.org/AudioObject' diff --git a/app/models/media_object.rb b/app/models/media_object.rb index 668efa0009..ac46a9f6d0 100644 --- a/app/models/media_object.rb +++ b/app/models/media_object.rb @@ -318,7 +318,7 @@ def to_solr(include_child_fields: false) solr_doc["title_ssort"] = self.title solr_doc["creator_ssort"] = Array(self.creator).join(', ') solr_doc["date_ingested_ssim"] = self.create_date.strftime "%F" if self.create_date.present? - solr_doc['avalon_resource_type_ssim'] = self.avalon_resource_type.map(&:titleize) + solr_doc['avalon_resource_type_ssim'] = self.avalon_resource_type solr_doc['identifier_ssim'] = self.identifier.map(&:downcase) solr_doc['note_ssm'] = self.note.collect { |n| n.to_json } solr_doc['other_identifier_ssm'] = self.other_identifier.collect { |oi| oi.to_json } diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index e09724ed26..2de1ba4286 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -87,6 +87,15 @@ end end + describe "#titleize" do + it "titleizes a string" do + expect(helper.titleize("lower case phrase")).to eq "Lower Case Phrase" + end + it "titleizes an array of strings" do + expect(helper.titleize(["ant", "adam ant", "tic tac toe"])).to eq ["Ant", "Adam Ant", "Tic Tac Toe"] + end + end + describe "#truncate_center" do it "should return empty string if empty string received" do expect(helper.truncate_center("", 5)).to eq ""