Skip to content

Commit

Permalink
starting on switch to using OM::Terminologies and relying on Solrizer…
Browse files Browse the repository at this point in the history
… to provide solr mappings. Putting on hold to merge Rick's updates
  • Loading branch information
flyingzumwalt committed Sep 11, 2010
1 parent 0fb0496 commit ceb6a3c
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 209 deletions.
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ begin
gem.add_dependency('mime-types', '>= 1.16')
gem.add_dependency('multipart-post')
gem.add_dependency('nokogiri')
gem.add_dependency('om', '>= 0.1.9')
# gem.add_dependency('om', '>= 0.1.9')
gem.add_dependency('om', '>= 1.0')
# gem.add_dependency('yaml')

gem.add_development_dependency "rspec", ">= 1.2.9"
Expand Down
16 changes: 10 additions & 6 deletions lib/active_fedora/nokogiri_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class ActiveFedora::NokogiriDatastream < ActiveFedora::Datastream

include ActiveFedora::MetadataDatastreamHelper
include OM::XML
include OM::XML::Document
# extend(OM::XML::Container::ClassMethods)

attr_accessor :ng_xml
Expand Down Expand Up @@ -128,24 +128,28 @@ def solrize_node(node, accessor_pointer, solr_doc = Solr::Document.new)
end

def update_indexed_attributes(params={}, opts={})
if self.class.terminology.nil?
raise "No terminology is set for this NokogiriDatastream class. Cannot perform update_indexed_attributes"
end
# remove any fields from params that this datastream doesn't recognize
params.delete_if do |field_key,new_values|
if field_key.kind_of?(String)
params.delete_if do |term_pointer,new_values|
if term_pointer.kind_of?(String)
true
else
self.class.accessor_xpath(*OM.destringify(field_key) ).nil?
!self.class.terminology.has_term?(*OM.destringify(term_pointer))
# self.class.accessor_xpath(*OM.destringify(field_key) ).nil?
end
end
result = {}
unless params.empty?
result = update_properties( params )
result = update_values( params )
self.dirty = true
end
return result
end

def get_values(field_key,default=[])
property_values(*field_key)
term_values(*field_key)
end

end
21 changes: 0 additions & 21 deletions lib/active_fedora/solr_mapper.rb

This file was deleted.

36 changes: 2 additions & 34 deletions lib/active_fedora/solr_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.reify_solr_results(solr_result)
end
results = []
solr_result.hits.each do |hit|
model_value = hit[ActiveFedora::SolrMapper.solr_name("active_fedora_model", :symbol)].first
model_value = hit[Solrizer::SolrMapper.solr_name("active_fedora_model", :symbol)].first
if model_value.include?("::")
classname = eval(model_value)
else
Expand All @@ -53,41 +53,9 @@ def self.escape_uri_for_query(uri)
return uri.gsub(/(:)/, '\\:')
end

def self.mappings
@@mappings
end
def self.mappings=(mappings)
@@mappings = mappings
end

def self.logger
@logger ||= defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT)
end

# Loads solr mappings from yml file.
# @config_path This is the path to the directory where your mappings file is stored. @default "RAILS_ROOT/config/solr_mappings.yml"
# @mappings_file This is the filename for your solr mappings YAML file. @default solr_mappings.yml
def self.load_mappings( config_path=nil )

if config_path.nil?
if defined?(RAILS_ROOT)
config_path = File.join(RAILS_ROOT, "config", "solr_mappings.yml")
end
# Default to using the config file within the gem
if !File.exist?(config_path.to_s)
config_path = File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings.yml")
end
end

logger.info("FEDORA: loading SolrService mappings from #{File.expand_path(config_path)}")

@@mappings = YAML::load(File.open(config_path))

mappings["id"] = "id" unless mappings["id"]
end

self.load_mappings

end

class SolrNotInitialized < StandardError;end
end
151 changes: 57 additions & 94 deletions lib/hydra/sample_mods_datastream.rb
Original file line number Diff line number Diff line change
@@ -1,100 +1,63 @@
require "hydra"
module Hydra
class Hydra::SampleModsDatastream < ActiveFedora::NokogiriDatastream

# have to call this in order to set namespace & schema
root_property :mods, "mods", "http://www.loc.gov/mods/v3", :attributes=>["id", "version"], :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"

property :title_info, :path=>"titleInfo",
:convenience_methods => {
:main_title => {:path=>"title"},
:language => {:path=>{:attribute=>"lang"}},
}
property :abstract, :path=>"abstract"
property :topic_tag, :path=>'subject',:default_content_path => "topic"

property :name_, :path=>"name",
:attributes=>[:xlink, :lang, "xml:lang", :script, :transliteration, {:type=>["personal", "enumerated", "corporate"]} ],
:subelements=>["namePart", "displayForm", "affiliation", :role, "description"],
:default_content_path => "namePart",
:convenience_methods => {
:date => {:path=>"namePart", :attributes=>{:type=>"date"}},
:family_name => {:path=>"namePart", :attributes=>{:type=>"family"}},
:first_name => {:path=>"namePart", :attributes=>{:type=>"given"}},
:terms_of_address => {:path=>"namePart", :attributes=>{:type=>"termsOfAddress"}}
}

property :person, :variant_of=>:name_, :attributes=>{:type=>"personal"}
property :organizaton, :variant_of=>:name_, :attributes=>{:type=>"institutional"}
property :conference, :variant_of=>:name_, :attributes=>{:type=>"conference"}

property :role, :path=>"role",
:parents=>[:name_],
:convenience_methods => {
:text => {:path=>"roleTerm", :attributes=>{:type=>"text"}},
:code => {:path=>"roleTerm", :attributes=>{:type=>"code"}},
}

property :journal, :path=>'relatedItem', :attributes=>{:type=>"host"},
:subelements=>[:title_info, :origin_info, :issue],
:convenience_methods => {
:issn => {:path=>"identifier", :attributes=>{:type=>"issn"}},
}

property :origin_info, :path=>'originInfo',
:subelements=>["publisher","dateIssued"]

property :issue, :path=>'part',
:subelements=>[:start_page, :end_page],
:convenience_methods => {
:volume => {:path=>"detail", :attributes=>{:type=>"volume"}},
:level => {:path=>"detail", :attributes=>{:type=>"level"}},
:publication_date => {:path=>"date"}
}
property :start_page, :path=>"extent", :attributes=>{:unit=>"pages"}, :default_content_path => "start"
property :end_page, :path=>"extent", :attributes=>{:unit=>"pages"}, :default_content_path => "end"

generate_accessors_from_properties
# accessor :title_info, :relative_xpath=>'oxns:titleInfo', :children=>[
# {:main_title=>{:relative_xpath=>'oxns:title'}},
# {:language =>{:relative_xpath=>{:attribute=>"lang"} }}
# ]
# accessor :abstract
# accessor :topic_tag, :relative_xpath=>'oxns:subject/oxns:topic'
# accessor :person, :relative_xpath=>'oxns:name[@type="personal"]', :children=>[
# {:last_name=>{:relative_xpath=>'oxns:namePart[@type="family"]'}},
# {:first_name=>{:relative_xpath=>'oxns:namePart[@type="given"]'}},
# {:institution=>{:relative_xpath=>'oxns:affiliation'}},
# {:role=>{:children=>[
# {:text=>{:relative_xpath=>'oxns:roleTerm[@type="text"]'}},
# {:code=>{:relative_xpath=>'oxns:roleTerm[@type="code"]'}}
# ]}}
# ]
# accessor :organization, :relative_xpath=>'oxns:name[@type="institutional"]', :children=>[
# {:role=>{:children=>[
# {:text=>{:relative_xpath=>'oxns:roleTerm[@type="text"]'}},
# {:code=>{:relative_xpath=>'oxns:roleTerm[@type="code"]'}}
# ]}}
# ]
# accessor :conference, :relative_xpath=>'oxns:name[@type="conference"]', :children=>[
# {:role=>{:children=>[
# {:text=>{:relative_xpath=>'oxns:roleTerm[@type="text"]'}},
# {:code=>{:relative_xpath=>'oxns:roleTerm[@type="code"]'}}
# ]}}
# ]
# accessor :journal, :relative_xpath=>'oxns:relatedItem[@type="host"]', :children=>[
# {:title=>{:relative_xpath=>'oxns:titleInfo/oxns:title'}},
# {:publisher=>{:relative_xpath=>'oxns:originInfo/oxns:publisher'}},
# {:issn=>{:relative_xpath=>'oxns:identifier[@type="issn"]'}},
# {:date_issued=>{:relative_xpath=>'oxns:originInfo/oxns:dateIssued'}},
# {:issue => {:relative_xpath=>"oxns:part", :children=>[
# {:volume=>{:relative_xpath=>'oxns:detail[@type="volume"]'}},
# {:level=>{:relative_xpath=>'oxns:detail[@type="level"]'}},
# {:start_page=>{:relative_xpath=>'oxns:extent[@unit="pages"]/oxns:start'}},
# {:end_page=>{:relative_xpath=>'oxns:extent[@unit="pages"]/oxns:end'}},
# {:publication_date=>{:relative_xpath=>'oxns:date'}}
# ]}}
# ]

set_terminology do |t|
t.root(:path=>"mods", :xmlns=>"http://www.loc.gov/mods/v3", :schema=>"http://www.loc.gov/standards/mods/v3/mods-3-2.xsd")

t.title_info(:path=>"titleInfo") {
t.main_title(:path=>"title", :label=>"title")
t.language(:path=>{:attribute=>"lang"})
}
t.abstract
t.topic_tag(:path=>"subject", :default_content_path=>"topic")
# This is a mods:name. The underscore is purely to avoid namespace conflicts.
t.name_ {
# this is a namepart
t.namePart(:index_as=>[:searchable, :displayable, :facetable, :sortable], :required=>:true, :type=>:string, :label=>"generic name")
# affiliations are great
t.affiliation
t.displayForm
t.role(:ref=>[:role])
t.description
t.date(:path=>"namePart", :attributes=>{:type=>"date"})
t.last_name(:path=>"namePart", :attributes=>{:type=>"family"})
t.first_name(:path=>"namePart", :attributes=>{:type=>"given"}, :label=>"first name")
t.terms_of_address(:path=>"namePart", :attributes=>{:type=>"termsOfAddress"})
}
# lookup :person, :first_name
t.person(:ref=>:name, :attributes=>{:type=>"personal"})
t.organizaton(:ref=>:name, :attributes=>{:type=>"institutional"})
t.conference(:ref=>:name, :attributes=>{:type=>"conference"})

t.role {
t.text(:path=>"roleTerm",:attributes=>{:type=>"text"})
t.code(:path=>"roleTerm",:attributes=>{:type=>"code"})
}
t.journal(:path=>'relatedItem', :attributes=>{:type=>"host"}) {
t.title_info
t.origin_info(:path=>"originInfo") {
t.publisher
t.date_issued(:path=>"dateIssued")
}
t.issn(:path=>"identifier", :attributes=>{:type=>"issn"})
t.issue(:path=>"part") {
t.volume(:path=>"detail", :attributes=>{:type=>"volume"}, :default_content_path=>"number")
t.level(:path=>"detail", :attributes=>{:type=>"number"}, :default_content_path=>"number")
t.extent
t.pages(:path=>"extent", :attributes=>{:type=>"pages"}) {
t.start
t.end
}
t.publication_date(:path=>"date")
}
}

end

# Changes from OM::Properties implementation
# renamed family_name => last_name
# start_page & end_page now accessible as [:journal, :issue, :pages, :start] (etc.)

end
end
Loading

0 comments on commit ceb6a3c

Please sign in to comment.