Skip to content

Commit

Permalink
Index avalon_resource_type the same as it is stored in fedora (#5846)
Browse files Browse the repository at this point in the history
Shift titleization into front end through a helper method utilized by the Blacklight facet.

Resolves #5836
  • Loading branch information
cjcolvar authored Jun 5, 2024
1 parent 6e0a08c commit 31213f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion app/models/media_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down

0 comments on commit 31213f4

Please sign in to comment.