diff --git a/lib/search/models/record/catalog/bib.rb b/lib/search/models/record/catalog/bib.rb index eff241cc..6d77e265 100644 --- a/lib/search/models/record/catalog/bib.rb +++ b/lib/search/models/record/catalog/bib.rb @@ -17,7 +17,7 @@ def title :copy_specific_note, :copyright, :copyright_status_information, :created, :current_publication_frequency, :date_place_of_event, :distributed, :edition, :extended_summary, :finding_aids, :former_publication_frequency, - :funding_information, :in_collection, :language_note, + :funding_information, :language_note, :location_of_originals, :manufactured, :map_scale, :media_format, :note, :numbering, :numbering_notes, :original_version_note, :performers, :physical_description, :place, :playing_time, :preferred_citation, :printer, @@ -52,6 +52,12 @@ def main_author end end + def in_collection + _map_paired_field("in_collection") do |item| + InCollectionItem.new(item) + end + end + def related_title _map_paired_field("related_title") do |item| LinkToItem.new(item) @@ -176,6 +182,18 @@ def paired? end end + class InCollectionItem < Item + def text + base_text = super + base_text.match?(/^[0-9]+$/) ? "Record ID #{base_text}" : base_text + end + + def url + doc_id = @data["search"].first["value"] + "#{S.base_url}/catalog/record/#{doc_id}" + end + end + class LinkToItem < Item include SearchUrl end diff --git a/lib/search/presenters/record/catalog.rb b/lib/search/presenters/record/catalog.rb index 9b628da2..adf881ce 100644 --- a/lib/search/presenters/record/catalog.rb +++ b/lib/search/presenters/record/catalog.rb @@ -218,7 +218,8 @@ def format {uid: :other_titles, field: "Other Titles"}, {uid: :preferred_title, field: "Preferred Title"}, {uid: :previous_title, field: "Previous Title"}, - {uid: :related_title, field: "Related Title"} + {uid: :related_title, field: "Related Title"}, + {uid: :in_collection, field: "In Collection"} ].each do |f| define_method(f[:uid]) do if @record.bib.public_send(f[:uid]).present? @@ -255,7 +256,6 @@ def format {uid: :finding_aids, field: "Indexes/Finding Aids"}, {uid: :former_publication_frequency, field: "Former Publication Frequency"}, {uid: :funding_information, field: "Funding Information"}, - {uid: :in_collection, field: "In Collection"}, {uid: :language_note, field: "Language note"}, {uid: :location_of_originals, field: "Location of Originals"}, {uid: :manufactured, field: "Manufactured"}, diff --git a/spec/factories/catalog_api_record.rb b/spec/factories/catalog_api_record.rb index c27c358b..bbc60e6f 100644 --- a/spec/factories/catalog_api_record.rb +++ b/spec/factories/catalog_api_record.rb @@ -28,7 +28,7 @@ def to_h physical: [] }], ["citation", {tagged: [], citeproc: {}}] - ] + paired_text_fields + title_link_fields + text_fields + author_browse_fields).to_h + ] + paired_text_fields + title_link_fields + text_fields + author_browse_fields + in_collection).to_h end def paired_text_fields @@ -38,7 +38,7 @@ def paired_text_fields "copyright_status_information", "created", "current_publication_frequency", "date_place_of_event", "extended_summary", "finding_aids", "former_publication_frequency", - "funding_information", "in_collection", "language_note", + "funding_information", "language_note", "location_of_originals", "map_scale", "media_format", "note", "numbering", "numbering_notes", "original_version_note", "performers", "physical_description", "place", "playing_time", "preferred_citation", @@ -57,6 +57,10 @@ def title_link_fields end end + def in_collection + [["in_collection", link_field("isn")]] + end + def text_fields ["bookplate", "call_number", "gov_doc_number", "isbn", "issn", "language", "lc_subjects", "oclc", "other_subjects", "new_title_issn", diff --git a/spec/models/record/catalog/bib_spec.rb b/spec/models/record/catalog/bib_spec.rb index 69d3ecd9..52ceddfd 100644 --- a/spec/models/record/catalog/bib_spec.rb +++ b/spec/models/record/catalog/bib_spec.rb @@ -40,7 +40,7 @@ def author_browse_item_expectations(subject) :copy_specific_note, :copyright, :copyright_status_information, :created, :current_publication_frequency, :date_place_of_event, :distributed, :edition, :extended_summary, :finding_aids, :former_publication_frequency, - :funding_information, :in_collection, :language_note, + :funding_information, :language_note, :location_of_originals, :manufactured, :map_scale, :media_format, :note, :numbering, :numbering_notes, :original_version_note, :performers, :physical_description, :place, :playing_time, :preferred_citation, :printer, @@ -96,6 +96,54 @@ def author_browse_item_expectations(subject) end end end + context "#in_collection" do + it "has text and link to full record page" do + # mrio: I don't think this would ever be paired, but we'll handle it anyway + bib_id_transliterated = Faker::Number.number(digits: 10).to_s + bib_id_original = Faker::Number.number(digits: 10).to_s + @data["in_collection"].first["transliterated"]["search"].first["value"] = bib_id_transliterated + @data["in_collection"].first["original"]["search"].first["value"] = bib_id_original + expected = { + transliterated: + { + text: @data["in_collection"].first["transliterated"]["text"] + }, + original: + { + text: @data["in_collection"].first["original"]["text"] + } + } + + my_subject = subject.in_collection.first + expect(my_subject.paired?).to eq(true) + expect(my_subject.transliterated.text).to eq(expected[:transliterated][:text]) + expect(my_subject.transliterated.url) + .to eq("#{S.base_url}/catalog/record/#{bib_id_transliterated}") + + expect(my_subject.original.text).to eq(expected[:original][:text]) + expect(my_subject.original.url) + .to eq("#{S.base_url}/catalog/record/#{bib_id_original}") + end + it "has special text when it's just the record id" do + # mrio: I don't think this would ever be paired, but we'll handle it anyway + bib_id_transliterated = Faker::Number.number(digits: 10).to_s + bib_id_original = Faker::Number.number(digits: 10).to_s + @data["in_collection"].first["transliterated"]["text"] = bib_id_transliterated + @data["in_collection"].first["transliterated"]["search"].first["value"] = bib_id_transliterated + @data["in_collection"].first["original"]["search"].first["value"] = bib_id_original + @data["in_collection"].first["original"]["text"] = bib_id_original + + my_subject = subject.in_collection.first + expect(my_subject.paired?).to eq(true) + expect(my_subject.transliterated.text).to eq("Record ID #{bib_id_transliterated}") + expect(my_subject.transliterated.url) + .to eq("#{S.base_url}/catalog/record/#{bib_id_transliterated}") + + expect(my_subject.original.text).to eq("Record ID #{bib_id_original}") + expect(my_subject.original.url) + .to eq("#{S.base_url}/catalog/record/#{bib_id_original}") + end + end ["main_author", "contributors"].each do |field| context "##{field}" do it "has an author browse result" do diff --git a/spec/presenters/record/catalog_spec.rb b/spec/presenters/record/catalog_spec.rb index fa012e63..3fbfc65f 100644 --- a/spec/presenters/record/catalog_spec.rb +++ b/spec/presenters/record/catalog_spec.rb @@ -21,7 +21,6 @@ finding_aids: "Indexes/Finding Aids", former_publication_frequency: "Former Publication Frequency", funding_information: "Funding Information", - in_collection: "In Collection", language_note: "Language note", location_of_originals: "Location of Originals", manufactured: "Manufactured", @@ -55,7 +54,8 @@ related_title: "Related Title", preferred_title: "Preferred Title", previous_title: "Previous Title", - other_titles: "Other Titles" + other_titles: "Other Titles", + in_collection: "In Collection" } single_string_fields = { contents: "Contents",