Sha256: 6b06d3219c660733e11db69e2dc4f80993ff8c8184f48d41a69ebf514ff218e4

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

require 'rexml/document'
require "nokogiri"
require 'yaml'

# Solrizer::Fedora::Extractor provides Fedora-specific extractor behaviors
# This module is automatically mixed into Solrizer::Extractor when you load the solrizer-fedora gem into an application.  This is carried out in solrizer/fedora.rb 
module Solrizer::Fedora::Extractor

  #
  # Extracts content-model and hydra-type from RELS-EXT datastream
  #
  def extract_rels_ext( text, solr_doc=Hash.new )
    # TODO: only read in this file once
    
    if defined?(Rails.root.to_s)
      config_path = File.join(Rails.root.to_s, "config","hydra_types.yml")
      config_path = nil unless File.exist?(config_path)
    end
    unless config_path
      config_path = File.join(File.dirname(__FILE__), "..", "..", "..", "config","hydra_types.yml")
    end
    
    
    map = YAML.load(File.open(config_path))
    
    doc = Nokogiri::XML(text)
    doc.xpath( '//foo:hasModel', 'foo' => 'info:fedora/fedora-system:def/model#' ).each do |element|
      cmodel = element.attributes['resource'].to_s
      ::Solrizer::Extractor.insert_solr_field_value(solr_doc,  :cmodel_t, cmodel )
      
      if map.has_key?(cmodel)
        ::Solrizer::Extractor.insert_solr_field_value(solr_doc, :hydra_type_t, map[cmodel] )
      end
    end

    return solr_doc
  end
  
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
solrizer-fedora-3.0.0.pre1 lib/solrizer/fedora/extractor.rb
solrizer-fedora-2.3.1 lib/solrizer/fedora/extractor.rb
solrizer-fedora-2.3.0 lib/solrizer/fedora/extractor.rb
solrizer-fedora-2.2.0 lib/solrizer/fedora/extractor.rb
solrizer-fedora-2.1.0 lib/solrizer/fedora/extractor.rb
solrizer-fedora-2.0.0 lib/solrizer/fedora/extractor.rb
solrizer-fedora-2.0.0.rc2 lib/solrizer/fedora/extractor.rb
solrizer-fedora-2.0.0.rc1 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.2.5 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.2.4 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.2.3 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.2.2 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.2.1 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.2.0 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.1.3 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.1.2 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.1.1 lib/solrizer/fedora/extractor.rb
solrizer-fedora-1.1.0 lib/solrizer/fedora/extractor.rb