Skip to content

Commit

Permalink
solrizing by accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingzumwalt committed Jun 21, 2010
1 parent 4bc9186 commit 0952d98
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ begin
gem.add_dependency('mime-types', '>= 1.16')
gem.add_dependency('multipart-post')
gem.add_dependency('nokogiri')
gem.add_dependency('om', '>= 0.1.2')
gem.add_dependency('om', '>= 0.1.4')
gem.add_dependency('yaml')

gem.add_development_dependency "rspec", ">= 1.2.9"
Expand Down
19 changes: 12 additions & 7 deletions active-fedora.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{active-fedora}
s.version = "1.1.6"
s.version = "1.1.7"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Matt Zumwalt", "McClain Looney"]
s.date = %q{2010-06-14}
s.date = %q{2010-06-21}
s.description = %q{ActiveFedora provides for creating and managing objects in the Fedora Repository Architecture.}
s.email = %q{[email protected]}
s.extra_rdoc_files = [
Expand Down Expand Up @@ -209,7 +209,7 @@ Gem::Specification.new do |s|
"lib/fedora/generic_search.rb",
"lib/fedora/repository.rb",
"lib/hydra.rb",
"lib/hydra_libs/mods_datastream.rb",
"lib/hydra_libs/mods_article.rb",
"lib/hydra_libs/opinionated_mods_document.rb",
"lib/ruby-fedora.rb",
"lib/util/class_level_inheritable_attributes.rb",
Expand All @@ -222,6 +222,7 @@ Gem::Specification.new do |s|
"spec/fixtures/changeme155.xml",
"spec/fixtures/dino.jpg",
"spec/fixtures/minivan.jpg",
"spec/fixtures/mods_articles/hydrangea_article1.xml",
"spec/fixtures/oh_qdc.xml",
"spec/fixtures/test_12.foxml.xml",
"spec/integration/base_file_management_spec.rb",
Expand Down Expand Up @@ -262,7 +263,6 @@ Gem::Specification.new do |s|
"spec/unit/inheritance_spec.rb",
"spec/unit/metadata_datastream_spec.rb",
"spec/unit/model_spec.rb",
"spec/unit/mods_datastream_spec.rb",
"spec/unit/nokogiri_datastream_spec.rb",
"spec/unit/property_spec.rb",
"spec/unit/qualified_dublin_core_datastream_spec.rb",
Expand All @@ -281,7 +281,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{rubyfedora}
s.rubygems_version = %q{1.3.6}
s.rubygems_version = %q{1.3.7}
s.summary = %q{A convenience libary for manipulating MODS (Metadata Object Description Schema) documents.}
s.test_files = [
"spec/integration/base_file_management_spec.rb",
Expand Down Expand Up @@ -319,7 +319,6 @@ Gem::Specification.new do |s|
"spec/unit/inheritance_spec.rb",
"spec/unit/metadata_datastream_spec.rb",
"spec/unit/model_spec.rb",
"spec/unit/mods_datastream_spec.rb",
"spec/unit/nokogiri_datastream_spec.rb",
"spec/unit/property_spec.rb",
"spec/unit/qualified_dublin_core_datastream_spec.rb",
Expand All @@ -337,12 +336,14 @@ Gem::Specification.new do |s|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<solr-ruby>, [">= 0.0.6"])
s.add_runtime_dependency(%q<xml-simple>, [">= 1.0.12"])
s.add_runtime_dependency(%q<mime-types>, [">= 1.16"])
s.add_runtime_dependency(%q<multipart-post>, [">= 0"])
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
s.add_runtime_dependency(%q<om>, [">= 0.1.4"])
s.add_runtime_dependency(%q<yaml>, [">= 0"])
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
s.add_development_dependency(%q<mocha>, [">= 1.2.9"])
s.add_development_dependency(%q<ruby-debug>, [">= 0"])
Expand All @@ -352,6 +353,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<mime-types>, [">= 1.16"])
s.add_dependency(%q<multipart-post>, [">= 0"])
s.add_dependency(%q<nokogiri>, [">= 0"])
s.add_dependency(%q<om>, [">= 0.1.4"])
s.add_dependency(%q<yaml>, [">= 0"])
s.add_dependency(%q<rspec>, [">= 1.2.9"])
s.add_dependency(%q<mocha>, [">= 1.2.9"])
s.add_dependency(%q<ruby-debug>, [">= 0"])
Expand All @@ -362,6 +365,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<mime-types>, [">= 1.16"])
s.add_dependency(%q<multipart-post>, [">= 0"])
s.add_dependency(%q<nokogiri>, [">= 0"])
s.add_dependency(%q<om>, [">= 0.1.4"])
s.add_dependency(%q<yaml>, [">= 0"])
s.add_dependency(%q<rspec>, [">= 1.2.9"])
s.add_dependency(%q<mocha>, [">= 1.2.9"])
s.add_dependency(%q<ruby-debug>, [">= 0"])
Expand Down
22 changes: 11 additions & 11 deletions lib/active_fedora/nokogiri_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ def initialize(attrs=nil)
end

def to_solr(solr_doc = Solr::Document.new) # :nodoc:
fields.each do |field_key, field_info|
if field_info.has_key?(:values) && !field_info[:values].nil?
field_symbol = generate_solr_symbol(field_key, field_info[:type])
field_info[:values].each do |val|
solr_doc << Solr::Field.new(field_symbol => val)
end

unless self.class.accessors.nil?
self.class.accessors.each_pair do |accessor_name,accessor_info|
solrize_accessor(accessor_name, accessor_info, :solr_doc=>solr_doc)
end
end

Expand Down Expand Up @@ -57,14 +55,16 @@ def solrize_accessor(accessor_name, accessor_info, opts={})
end

def solrize_node(node, accessor_pointer, solr_doc = Solr::Document.new)
generic_field_name_base = self.class.accessor_generic_name(accessor_pointer)
generic_field_name_base = self.class.accessor_generic_name(*accessor_pointer)
generic_field_name = generate_solr_symbol(generic_field_name_base, :text)

hierarchical_field_name_base = self.class.accessor_hierarchical_name(accessor_pointer)
hierarchical_field_name = generate_solr_symbol(hierarchical_field_name_base, :text)

solr_doc << Solr::Field.new(generic_field_name => node.text)
solr_doc << Solr::Field.new(hierarchical_field_name => node.text)

if accessor_pointer.length > 1
hierarchical_field_name_base = self.class.accessor_hierarchical_name(*accessor_pointer)
hierarchical_field_name = generate_solr_symbol(hierarchical_field_name_base, :text)
solr_doc << Solr::Field.new(hierarchical_field_name => node.text)
end
end

end
50 changes: 27 additions & 23 deletions spec/unit/nokogiri_datastream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@
ActiveFedora::SolrService.load_mappings
end

it "should iterate through the class fields, calling .values on each and appending the values to the solr doc"
it "should iterate through the class accessors, calling .solrize_accessor on each and passing in the solr doc" do
mock_accessors = {:accessor1=>:accessor1_info, :accessor2=>:accessor2_info}
ActiveFedora::NokogiriDatastream.stubs(:accessors).returns(mock_accessors)
doc = Solr::Document.new
mock_accessors.each_pair do |k,v|
@test_ds.expects(:solrize_accessor).with(k, v, :solr_doc=>doc)
end
@test_ds.to_solr(doc)
end

it "should provide .to_solr and return a SolrDocument" do
@test_ds.should respond_to(:to_solr)
Expand All @@ -116,27 +124,6 @@
doc = Solr::Document.new
@test_ds.to_solr(doc).should equal(doc)
end


it "should use Solr mappings to generate field names" do
ActiveFedora::SolrService.load_mappings(File.join(File.dirname(__FILE__), "..", "..", "config", "solr_mappings_af_0.1.yml"))
@test_ds.stubs(:fields).returns(@sample_fields)
solr_doc = @test_ds.to_solr

#should have these

solr_doc[:publisher_field].should == "publisher1"
solr_doc[:coverage_field].should == "coverage1"
solr_doc[:creation_date_date].should == "fake-date"
solr_doc[:mydate_date].should == "fake-date"

solr_doc[:publisher_t].should be_nil
solr_doc[:coverage_t].should be_nil
solr_doc[:creation_date_dt].should be_nil

# Reload default mappings
ActiveFedora::SolrService.load_mappings
end

end

Expand Down Expand Up @@ -192,7 +179,6 @@ class AccessorizedDs < ActiveFedora::NokogiriDatastream
@accessorized_ds.expects(:lookup).with( "title_info_language_xpath" ).returns(mock_language_set)
@accessorized_ds.expects(:solrize_node).with("main title", [{:title_info=>node_index}, :main_title], solr_doc)
@accessorized_ds.expects(:solrize_node).with("language", [{:title_info=>node_index}, :language], solr_doc)

end

@accessorized_ds.solrize_accessor(:title_info, AccessorizedDs.accessors[:title_info], :solr_doc=>solr_doc)
Expand All @@ -210,12 +196,30 @@ class AccessorizedDs < ActiveFedora::NokogiriDatastream

# This should catch the "submitter" roleTerm from the second role node within the first person node and put it into a solr field called "person_0_role_2_text_0_t" and a solr field called "person_role_text_t"
@accessorized_ds.solrize_accessor(:text, AccessorizedDs.accessor_info( *parents_array + [:text] ), :parents=>parents_array)
end

it "should use Solr mappings to generate field names" do

solr_doc = @accessorized_ds.to_solr
#should have these

solr_doc[:abstract_t].should == "ABSTRACT"
solr_doc[:title_info_1_language_t].should == "finnish"
solr_doc[:person_1_role_0_text_t].should == "teacher"
# solr_doc[:mydate_date].should == "fake-date"
#
# solr_doc[:publisher_t].should be_nil
# solr_doc[:coverage_t].should be_nil
# solr_doc[:creation_date_dt].should be_nil
# solr_doc.should == ""

end
end

describe ".solrize_node" do
it "should create a solr field containing node.text"
it "should create hierarchical field entries if parents is not empty"
it "should only create one node if parents is empty"
end

end

0 comments on commit 0952d98

Please sign in to comment.