Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# only relevant pieces of this partial
<% content_for :sidebar do %>
<%= xslt 'catalog/_show_partials/_ead/show_sidebar.xsl', @document[:xml_display] %>
<% if @document['subject'] %>
<h4>Subjects</h4>
<ul class="subjects">
<% @document['subject'].sort.each do |subject| %>
<li>
<%= link_to subject, catalog_index_path('f[subject_facet][]' => subject) %>
</li>
<% end %>
</ul>
<% end %>
<% end %>
<%= xslt('catalog/_show_partials/_ead/show.xsl', @document[:xml_display]) %>
# performs an XSLT transform given a path to a stylesheet and a document
def xslt(stylesheet_file_path, document, params={})
require 'nokogiri'
document = Nokogiri::XML(document)
stylesheet_file = render(stylesheet_file_path)
stylesheet = Nokogiri::XSLT(stylesheet_file)
stylesheet.apply_to(Nokogiri::XML(document.to_xml), params)
end
Blacklight.configure(:shared) do |config|
SolrDocument.marc_source_field = :marc_display
SolrDocument.marc_format_type = :marcxml
SolrDocument.ead_source_field = :xml_display
# rest of the configuration
desc "index a directory of ead files"
task :ead_dir=>:environment do
input_file = ENV['FILE']
if input_file =~ /\*/
files = Dir[input_file].collect
else
files = [input_file]
end
files.each_with_index do |f,index|
puts "indexing #{f}"
ENV['FILE'] = f
Rake::Task["solr:index:ead"].invoke
Rake::Task["solr:index:ead"].reenable
end
end
desc "Index an EAD file at FILE=<location-of-file>. expects a glob"
task :ead=>:environment do
require 'nokogiri'
raw = File.read(fetch_env_file)
# remove the default namespace,
# otherwise every query needs a "default:" prefix,
# and a namespace option must be set
# NCSU is using Archivists' Toolkit to create and export EADs
raw.gsub!(/xmlns=".*"/, '')
xml = Nokogiri::XML(raw)
# We want to indicate in the views whether there is
# associated digital content available for a faid
dao_value = xml.xpath('//dao').empty? ? false : true
#gather subject fields splitting on --
subject_fields = ['corpname','famname','occupation','persname', 'subject']
subject = subject_fields.map do |field|
xml.xpath('/ead/archdesc/controlaccess/' + field).map do |field_value|
field_value.text.split('--').map do |value|
value.strip.sub(/\.$/, '')
end
end
end
solr_doc = {
:format_code => 'ead',
:type => 'Collection Guide',
:format_facet => 'EAD',
#:title_t => xml.at('//archdesc[@level="collection"]/did/unittitle').text,
:title => xml.at('//eadheader/filedesc/titlestmt/titleproper').text,
:institution_t => xml.at('//publicationstmt/publisher').text,
#:language_facet => xml.at('//profiledesc/langusage/language').text.gsub(/\.$/, ''),
:ead_filename_s => xml.at('//eadheader/eadid').text,
:id => xml.at('/ead/eadheader/eadid').text.gsub(/\.xml/, ''),
:xml_display => xml.to_xml,
:text => xml.text,
:dao_b => dao_value,
:subject => subject.flatten.uniq
}
response = Blacklight.solr.add solr_doc
require 'pp'; pp response
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment