Skip to content

Commit

Permalink
Merge pull request #122 from mlibrary/remediated-subject-headings
Browse files Browse the repository at this point in the history
handles SeeInstead xref
  • Loading branch information
niquerio authored Aug 19, 2024
2 parents 340acbd + c042854 commit 587c156
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
29 changes: 23 additions & 6 deletions lib/models/subject_item.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class SubjectItem
attr_reader :browse_doc
def self.for(browse_doc:, exact_match:)
if browse_doc.key?("broader") || browse_doc.key?("narrower") || browse_doc.key?("see_also")
if ["broader", "narrower", "see_also", "see_instead"]
.any? { |xref_kind| browse_doc.key?(xref_kind) }
SubjectItemWithCrossReferences.new(browse_doc: browse_doc, exact_match: exact_match)
else
SubjectItem.new(browse_doc: browse_doc, exact_match: exact_match)
Expand Down Expand Up @@ -66,11 +67,13 @@ def has_cross_references?
end

def cross_references
# see_instead because this still needs to be changed in solr
broader = BroaderTerms.new(@browse_doc["broader"])
narrower = NarrowerTerms.new(@browse_doc["narrower"])
see_also = SeeAlsoTerms.new(@browse_doc["see_also"])
OpenStruct.new(broader: broader, narrower: narrower, see_also: see_also)
xrefs = {}
[:broader, :narrower, :see_also, :see_instead].each do |xref|
# get the terms class from the xref name (example: BroaderTerms)
terms_klass = Module.const_get "#{xref.to_s.split("_").collect(&:capitalize).join}Terms"
xrefs[xref] = terms_klass.new(@browse_doc[xref.to_s])
end
OpenStruct.new(**xrefs)
end
end

Expand Down Expand Up @@ -148,6 +151,20 @@ def summary_text_open
end
end

class SeeInsteadTerms < SubjectItemCrossReferences
def text
"See instead"
end

def summary_text_closed
summary_text(true, "see instead")
end

def summary_text_open
summary_text(false, "see instead")
end
end

class SubjectItemCrossReference
attr_reader :subject, :count
def initialize(subject)
Expand Down
12 changes: 10 additions & 2 deletions spec/fixtures/subject_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
"browse_field":"subject",
"json":"{\"id\":\"http://id.loc.gov/authorities/subjects/sh85000887\",\"subject\":\"Adivasis\",\"narrower\":{},\"broader\":{},\"see_also\":{\"http://id.loc.gov/authorities/subjects/sh85090174\":{\"id\":\"http://id.loc.gov/authorities/subjects/sh85090174\",\"label\":\"Indigenous peoples\",\"count\":441,\"match_text\":\"indigenous peoples\",\"json_class\":\"AuthorityBrowse::GenericXRef\"}},\"incoming_see_also\":null}",
"_version_":1757646983890206728,
"date_of_index":"2023-02-12T00:00:00Z"}
]
"date_of_index":"2023-02-12T00:00:00Z"},
{
"id":"illegal aliens\u001fsubject",
"loc_id":"http://id.loc.gov/authorities/subjects/sh85003553",
"browse_field":"subject",
"term":"Illegal aliens",
"count":0,
"date_of_index":"2024-05-22T00:00:00Z",
"see_instead":["Undocumented immigrants||250"],
"_version_":1799776250073448465}]
}}
32 changes: 32 additions & 0 deletions spec/models/subject_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,36 @@
expect(see_also.first.url).to include("subject?query=")
end
end
context "#cross_references.see_instead" do
before(:each) do
@params = {
browse_doc: @items[2],
exact_match: false
}
end
subject do
described_class.new(**@params)
end
let :see_instead do
subject.cross_references.see_instead.leading
end
it "has at least one cross reference of 'see_instead'" do
expect(see_instead).not_to be_nil
end
it "has a false 'heading_link?'" do
expect(see_instead.first.heading_link?).to eq(false)
end
it "has a subject_display" do
expect(see_instead.first.subject_display).to eq("Undocumented immigrants")
end
it "has a count" do
expect(see_instead.first.count).to eq("250")
end
it "displays records" do
expect(see_instead.first.record_text).to eq("250 records")
end
it "has a url that's a subject query" do
expect(see_instead.first.url).to include("subject?query=")
end
end
end

0 comments on commit 587c156

Please sign in to comment.