Sha256: 4cb1788d5e4869feb6792b9c7a7b44a5410eea524506cb3c77d4ca9cf47c041b

Contents?: true

Size: 1.81 KB

Versions: 4

Compression:

Stored size: 1.81 KB

Contents

module Dor
class SimpleDublinCoreDs < ActiveFedora::OmDatastream

  set_terminology do |t|
    t.root(:path=>"dc", :xmlns=>"http://www.openarchives.org/OAI/2.0/oai_dc/", :schema=>"http://cosimo.stanford.edu/standards/oai_dc/v2/oai_dc.xsd", :namespace_prefix => 'oai_dc', :index_as => [:not_searchable])
    t.title(     :index_as=>[:displayable, :facetable, :stored_searchable], :xmlns => "http://purl.org/dc/elements/1.1/", :namespace_prefix => 'dc')
    t.creator(   :index_as=>[:displayable, :facetable, :stored_searchable], :xmlns => "http://purl.org/dc/elements/1.1/", :namespace_prefix => 'dc')
    t.identifier(:index_as=>[:displayable, :stored_searchable],             :xmlns => "http://purl.org/dc/elements/1.1/", :namespace_prefix => 'dc')
  end

  def self.xml_template
    builder = Nokogiri::XML::Builder.new do |xml|
      xml.dc(:xmlns=>"http://www.openarchives.org/OAI/2.0/oai_dc/",
        'xmlns:dc'=>'http://purl.org/dc/elements/1.1/') {
          xml['dc'].title
          xml['dc'].creator
          xml['dc'].identifier
      }
    end

    return builder.doc
  end

  def to_solr(solr_doc=Hash.new, *args)
    # There are a whole bunch of namespace-related things that can go
    # wrong with this terminology. Until it's fixed in OM, ignore them all.
    begin
      doc = super solr_doc, *args

      add_solr_value(doc, 'dc_title',   self.title.first,   :string, [:sortable])
      add_solr_value(doc, 'dc_creator', self.creator.first, :string, [:sortable])

      identifiers = {}

      self.identifier.each { |i| ns, val = i.split(":"); identifiers[ns] ||= val }

      identifiers.each do |ns, val|
        add_solr_value(doc, "dc_identifier_#{ns}", val, :string, [:sortable])
      end

      return doc
    rescue Exception => e
      warn "ERROR in SimpleDublinCoreDs to_solr()! #{e}"
      solr_doc
    end
  end
end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dor-services-5.1.0 lib/dor/datastreams/simple_dublin_core_ds.rb
dor-services-5.0.2 lib/dor/datastreams/simple_dublin_core_ds.rb
dor-services-5.0.1 lib/dor/datastreams/simple_dublin_core_ds.rb
dor-services-5.0.0 lib/dor/datastreams/simple_dublin_core_ds.rb