Skip to content

Commit

Permalink
index relatedItem[@otherType='project']/title into a facetable field …
Browse files Browse the repository at this point in the history
…(DLC-1141)
  • Loading branch information
barmintor committed Jul 24, 2024
1 parent 23df680 commit 9ef0906
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/dcv/configurators/dcv_blacklight_configurator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def self.configure_sort_fields(config)
# solr fields to be displayed in the index (search results) view
# The ordering of the field names is the order of the display
def self.configure_index_fields(config)
#config.add_index_field 'title_display_ssm', :label => 'Title'
config.add_index_field 'lib_repo_long_ssim', :label => 'Library Location'
config.add_index_field 'primary_name_ssm', label: 'Name', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_index_field 'rel_other_project_ssim', :label => 'Project'
config.add_index_field 'lib_repo_long_ssim', :label => 'Library Location'
config.add_index_field 'location_sublocation_ssm', :label => 'Department'
config.add_index_field 'lib_collection_ssm', label: 'Collection Name', helper_method: :display_composite_archival_context
config.add_index_field 'lib_date_textual_ssm', :label => 'Date'
Expand All @@ -113,6 +113,7 @@ def self.configure_index_fields(config)
def self.configure_show_fields(config)
configure_file_show_fields(config)
config.add_show_field 'lib_name_ssm', label: 'Name', link_to_search: 'lib_name_sim', helper_method: :display_non_copyright_names_with_roles, if: :has_non_copyright_names?
config.add_show_field 'rel_other_project_ssim', :label => 'Project'
config.add_show_field 'title_display_ssm', label: 'Title'
config.add_show_field 'alternative_title_ssm', :label => 'Other Titles'
config.add_show_field 'abstract_ssm', label: 'Abstract', helper_method: :expandable_past_400, iiif: false
Expand Down
16 changes: 16 additions & 0 deletions lib/dcv/solr/document_adapter/mods_xml/fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,9 @@ def to_solr(solr_doc={})
solr_doc['reading_room_ssim'] = reading_room_locations

solr_doc.merge!(iiif_properties(mods))
othertype_fields = othertype_relations(mods)
solr_doc.merge!(othertype_fields)
solr_doc["all_text_teim"] += othertype_fields.values.flatten
solr_doc
end

Expand Down Expand Up @@ -730,5 +733,18 @@ def key_date_year_bounds(start_date, end_date)
return KEY_DATE_EMPTY_BOUNDS if (end_year && start_year) && end_year.to_i < start_year.to_i
[start_year, end_year]
end

# Create a map of field names to value arrays for relatedItem[@otherType]
# @param node [Nokogiri::XML::Node] search context
# @return [Hash<String, Array<String>] map of field name strings to value string arrays
def othertype_relations(node)
field_values = {}
mods.xpath("./mods:relatedItem[@otherType]/mods:titleInfo", MODS_NS).each do |title|
field_name = title.parent['otherType'].downcase.split(/[^a-z]+/).compact.join('_')
field_name = "rel_other_#{field_name}_ssim"
(field_values[field_name] ||= []) << title.text.strip
end
field_values
end
end
end
5 changes: 5 additions & 0 deletions spec/fixtures/mods/mods-relateditem-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@
</titleInfo>
<identifier type="uri">info:hyacinth.library.columbia.edu/projects/customer_orders</identifier>
</relatedItem>
<relatedItem otherType="project" otherTypeAuth="local" otherTypeURI="http://id.library.columbia.edu/term/6e2483cf-b669-4630-a033-3ec05e78c2cd">
<titleInfo>
<title>Project 2508: Edna Gladney house (Fort Worth, Texas). Scheme 2, Unbuilt Project</mods:title>
</titleInfo>
</relatedItem>
</mods>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'rails_helper'

describe Dcv::Solr::DocumentAdapter::ModsXml, type: :unit do
let(:xml_src) { fixture(File.join("mods", "mods-all.xml")) }
let(:ng_xml) { Nokogiri::XML(xml_src.read) }
let(:adapter) { described_class.new(ng_xml) }
let(:solr_doc) { adapter.to_solr }
let(:all_text) { solr_doc['all_text_teim'] }
let(:all_text_joined) { all_text.join(' ') }

describe ".to_solr" do
subject {
solr_doc
}
context "has otherType project cataloged" do
let(:xml_src) { fixture( File.join("mods", "mods-relateditem-project.xml") ) }
let(:project_label) { 'Project 2508: Edna Gladney house (Fort Worth, Texas). Scheme 2, Unbuilt Project' }
it "should extract project labels" do
expect(subject["rel_other_project_ssim"]).to eq([project_label])
end
end
end
end

0 comments on commit 9ef0906

Please sign in to comment.