Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/search/models/record/catalog/bib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/search/presenters/record/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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"},
Expand Down
8 changes: 6 additions & 2 deletions spec/factories/catalog_api_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
Expand All @@ -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",
Expand Down
50 changes: 49 additions & 1 deletion spec/models/record/catalog/bib_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/presenters/record/catalog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading