Skip to content

Commit

Permalink
Index direct_content_warning_ssm and use it for Figgy.
Browse files Browse the repository at this point in the history
This will make it so everything displays inherited content warnings, but
only things with content warnings on the component itself will display
it in the viewer.

Closes #1321
  • Loading branch information
tpendragon authored and hackartisan committed Nov 6, 2023
1 parent 17e55d0 commit c5cd202
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ def pulfalight_attributes
end

def content_warning
field_with_headings("scopecontent_ssim")["Content Warning"]
fetch("direct_content_warning_ssm", [])
end

def arclight_attributes
Expand Down
9 changes: 5 additions & 4 deletions lib/pulfalight/traject/ead2_component_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@

# For scope & contents, inherit ONLY content warning.
if selector == "scopecontent"
context.output_hash["direct_content_warning_ssm"] = content["Content Warning"]
parent = settings[:parent] || settings[:root]
parent_values = Array.wrap(parent.output_hash["#{selector}_combined_tsm"].clone)
# parent values is an array containing one stringified JSON hash
Expand All @@ -573,10 +574,10 @@
::JSON.parse(parent_value).slice("Content Warning")
end.reduce({}, :merge)

content.reverse_merge!(parent_warning)
if content.present?
accumulator.append(::JSON.dump(content))
scope_values = content.values.flatten
new_content = content.reverse_merge(parent_warning)
if new_content.present?
accumulator.append(::JSON.dump(new_content))
scope_values = new_content.values.flatten
context.output_hash["scopecontent_ssm"] = scope_values
end

Expand Down
3 changes: 2 additions & 1 deletion lib/pulfalight/traject/ead2_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
end
to_field "#{selector}_heading_ssm", extract_xpath("/ead/archdesc/#{selector}/head")
to_field "#{selector}_teim", extract_xpath("/ead/archdesc/#{selector}/*[local-name()!='head']")
to_field "#{selector}_combined_tsm", extract_xpath("/ead/archdesc/#{selector}", to_text: false) do |_record, accumulator|
to_field "#{selector}_combined_tsm", extract_xpath("/ead/archdesc/#{selector}", to_text: false) do |_record, accumulator, context|
content = accumulator.each_with_object({}) do |element, hsh|
header = element.xpath("./head")[0].text || "Unknown"
values = element.xpath("./p").map do |el|
Expand All @@ -316,6 +316,7 @@
hsh[header].concat values
end
accumulator.clear
context.output_hash["direct_content_warning_ssm"] = content["Content Warning"] if selector == "scopecontent"
accumulator << ::JSON.dump(content)
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/features/traject/ead2_indexing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,25 @@ def all_components(result)
# Ensure it's inheriting from its parent.
expect(component["scopecontent_combined_tsm"][0]).not_to eq "{}"
expect(component["scopecontent_ssm"][0]).to include "Many of the photographs"
expect(component["direct_content_warning_ssm"]).to be_blank
json = JSON.parse(component["scopecontent_combined_tsm"][0])
expect(json["Content Warning"]).not_to be_blank
# Never inherit Scope & Contents
expect(json["Scope and Contents"]).to be_blank
end
end

context "and its component does" do
let(:fixture_path) do
Rails.root.join("spec", "fixtures", "aspace", "generated", "mss", "C1372.processed.EAD.xml")
end
it "indexes a direct_content_warning" do
component = find_component(result, "C1372_c47202-68234")

expect(component["direct_content_warning_ssm"]).not_to be_blank
end
end

context "when child had a non-warning scopecontent note" do
let(:fixture_path) do
Rails.root.join("spec", "fixtures", "aspace", "generated", "mss", "WC064.processed.EAD.xml")
Expand All @@ -492,6 +504,8 @@ def all_components(result)
# Ensure it's inheriting from its parent.
expect(component["scopecontent_combined_tsm"][0]).not_to eq "{}"
expect(component["scopecontent_ssm"][0]).to include "harmful descriptions"
expect(component["direct_content_warning_ssm"]).to be_blank
expect(result["direct_content_warning_ssm"]).not_to be_blank
json = JSON.parse(component["scopecontent_combined_tsm"][0])
expect(json["Content Warning"]).not_to be_blank
end
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/aspace/generated/mss/TC040.processed.EAD.xml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,6 @@ In 2022, restrictions on glass-plate negatives were lifted as part of a restrict
<genreform source="aat">Scrapbooks.</genreform>
<corpname authfilenumber="https://viaf.org/viaf/125749916" source="viaf">Barnum and Bailey</corpname>
</controlaccess>
<dsc><c id="aspace_TC040_c00001" level="series"><did><unittitle>Series 1: Photographs</unittitle><unitid type="aspace_uri">/repositories/5/archival_objects/794653</unitid><physdesc altrender="whole"><extent altrender="materialtype spaceoccupied">16 boxes</extent></physdesc><physdesc altrender="whole"><extent altrender="materialtype spaceoccupied">8 items</extent></physdesc><unitdate datechar="creation" normal="1854/1903" type="inclusive">1854-1903</unitdate></did><scopecontent id="aspace_a9778d068d60b45daedd434b07a10e96"><head>Scope and Contents</head><p>Consists of photographs of exotica, performers, animal acts, "freaks," and equipment used by the circus.</p></scopecontent><arrangement id="aspace_5173864d18a660e2a8ad8200f141f51d"><head>Arrangement</head><p>Arranged by subject of photograph.</p></arrangement><scopecontent id="aspace_54e83256538dbcf23faa37b3e330ceca"><head>Content Warning</head><p>Many of the photographs in this series contain dehumanizing and harmful descriptions using racist, colonialist, and ableist language. In the majority of cases, the descriptions of people have been transcribed from the photographs themselves. Some of the photographs have been stamped with titles (likely by the original photographic studio); other titles are handwritten. In cases where photographs have no title, descriptions derive from a typewritten inventory of the collection that may have been provided by the donor, or may have been created by an archivist.</p></scopecontent><c id="aspace_TC040_c00002" level="file"><did><unittitle>Exotica</unittitle><unitid type="aspace_uri">/repositories/5/archival_objects/794656</unitid><physdesc altrender="whole"><extent altrender="materialtype spaceoccupied">4 boxes</extent></physdesc><unitdate datechar="creation" normal="1878-01-01/1900-11-30" type="inclusive">1878-1900 November</unitdate></did></c></c></dsc>
<dsc><c id="aspace_TC040_c00001" level="series"><did><unittitle>Series 1: Photographs</unittitle><unitid type="aspace_uri">/repositories/5/archival_objects/794653</unitid><physdesc altrender="whole"><extent altrender="materialtype spaceoccupied">16 boxes</extent></physdesc><physdesc altrender="whole"><extent altrender="materialtype spaceoccupied">8 items</extent></physdesc><unitdate datechar="creation" normal="1854/1903" type="inclusive">1854-1903</unitdate></did><scopecontent id="aspace_a9778d068d60b45daedd434b07a10e96"><head>Scope and Contents</head><p>Consists of photographs of exotica, performers, animal acts, "freaks," and equipment used by the circus.</p></scopecontent><arrangement id="aspace_5173864d18a660e2a8ad8200f141f51d"><head>Arrangement</head><p>Arranged by subject of photograph.</p></arrangement><scopecontent id="aspace_54e83256538dbcf23faa37b3e330ceca"><head>Content Warning</head><p>Many of the photographs in this series contain dehumanizing and harmful descriptions using racist, colonialist, and ableist language. In the majority of cases, the descriptions of people have been transcribed from the photographs themselves. Some of the photographs have been stamped with titles (likely by the original photographic studio); other titles are handwritten. In cases where photographs have no title, descriptions derive from a typewritten inventory of the collection that may have been provided by the donor, or may have been created by an archivist.</p></scopecontent><c id="aspace_TC040_c00002" level="file"><did><unittitle>Exotica</unittitle><unitid type="aspace_uri">/repositories/5/archival_objects/794656</unitid><physdesc altrender="whole"><extent altrender="materialtype spaceoccupied">4 boxes</extent></physdesc><unitdate datechar="creation" normal="1878-01-01/1900-11-30" type="inclusive">1878-1900 November</unitdate></did><c id="aspace_TC040_c00034" level="file"><did><unittitle>Elephant, with native rider, lifting wood beam</unittitle><unitid type="aspace_uri">/repositories/5/archival_objects/794749</unitid><physdesc altrender="whole"><extent altrender="materialtype spaceoccupied">1 item</extent></physdesc><unitdate calendar="gregorian" datechar="creation" era="ce">dates not examined</unitdate><container altrender="scamss" encodinganalog="NBox" id="aspace_385e5c2e38e14b44d8e913b372b85783" label="Mixed Materials [32101080822248]" type="box">1</container><container id="aspace_c1e3cedf967fb62aa797e0357fa1eab4" parent="aspace_385e5c2e38e14b44d8e913b372b85783" type="item">44</container><dao xlink:actuate="onRequest" xlink:href="https://figgy.princeton.edu/concern/scanned_resources/65c2c5dd-5d8a-4dda-8034-7f711e295a0a/manifest" xlink:role="https://iiif.io/api/presentation/2.1/" xlink:show="new" xlink:title="View digital content" xlink:type="simple"><daodesc><p>View digital content</p></daodesc></dao></did></c></c></c></dsc>
</archdesc>
</ead>
6 changes: 6 additions & 0 deletions spec/requests/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@
json_body = JSON.parse(response.body)
expect(json_body["content_warning"]).to eq ['The "Revolution in China" album contains photographs of dead bodies.']
end
it "doesn't render it for content warnings inherited from the series" do
get "/catalog/TC040_c00034.json"
json_body = JSON.parse(response.body)

expect(json_body["content_warning"]).to be_blank
end
end
context "for a collection" do
it "renders sufficient JSON for Figgy to use" do
Expand Down

0 comments on commit c5cd202

Please sign in to comment.