solrizer-fedora 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
- gem 'active-fedora', '1.2.4'
2
+ gem 'active-fedora', '1.2.7'
3
3
  gem 'solrizer', '>=0.3.0'
4
4
 
5
5
  group :development, :test do
data/Gemfile.lock CHANGED
@@ -1,44 +1,55 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- active-fedora (1.2.4)
4
+ active-fedora (1.2.7)
5
+ activeresource (< 3.0.0)
5
6
  mime-types (>= 1.16)
6
7
  multipart-post
7
8
  nokogiri
8
9
  om (>= 1.0)
9
10
  solr-ruby (>= 0.0.6)
11
+ solrizer (>= 0.3.0)
10
12
  xml-simple (>= 1.0.12)
11
- columnize (0.3.1)
13
+ activeresource (2.3.10)
14
+ activesupport (= 2.3.10)
15
+ activesupport (2.3.10)
16
+ columnize (0.3.2)
12
17
  facets (2.9.0)
13
18
  linecache (0.43)
19
+ mediashelf-loggable (0.4.0)
14
20
  mime-types (1.16)
15
- mocha (0.9.9)
21
+ mocha (0.9.10)
16
22
  rake
17
- multipart-post (1.0.1)
18
- nokogiri (1.4.3.1)
19
- om (1.0.0)
23
+ multipart-post (1.1.0)
24
+ nokogiri (1.4.4)
25
+ om (1.0.2)
20
26
  facets
27
+ facets
28
+ nokogiri
21
29
  nokogiri (>= 1.4.2)
22
30
  rake (0.8.7)
23
31
  rspec (1.3.1)
24
- ruby-debug (0.10.3)
32
+ ruby-debug (0.10.4)
25
33
  columnize (>= 0.1)
26
- ruby-debug-base (~> 0.10.3.0)
27
- ruby-debug-base (0.10.3)
34
+ ruby-debug-base (~> 0.10.4.0)
35
+ ruby-debug-base (0.10.4)
28
36
  linecache (>= 0.3)
29
37
  solr-ruby (0.0.8)
30
- solrizer (0.3.0)
31
- active-fedora (>= 1.1.5)
32
- om (>= 1.0.0)
38
+ solrizer (0.3.2)
39
+ mediashelf-loggable
40
+ nokogiri
41
+ nokogiri
42
+ om
43
+ solr-ruby
33
44
  xml-simple (1.0.12)
34
45
 
35
46
  PLATFORMS
36
47
  ruby
37
48
 
38
49
  DEPENDENCIES
39
- active-fedora (= 1.2.4)
50
+ active-fedora (= 1.2.7)
40
51
  mocha
41
52
  rspec (< 2.0.0)
42
53
  ruby-debug
43
54
  ruby-debug-base
44
- solrizer (>= 0.2.0)
55
+ solrizer (>= 0.3.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -35,49 +35,63 @@ class Indexer
35
35
  end
36
36
 
37
37
  #
38
- # This method connects to the Solr instance
38
+ # This method connects to the Solr instance. It looks to see if Blacklight is loaded first for the
39
+ # Blacklight.solr_config. If not loaded, it then looks for the RAILS_ROOT/config/solr.yaml file and loads
40
+ # it to get the solr url. The configuration strucuture can take both the
41
+ # { "development" => {"default" => { "url" => "http://localhost"}, "fulltext" => { "url" => "http://localhost"} }}
42
+ # or { "development"=>{"url"=>"http://localhost" }}
43
+ # Can also take Blacklight.solr_config["url"] and Blacklight.solr_config[:url]
39
44
  #
40
- def connect
45
+
46
+ def connect
41
47
 
42
- if ActiveFedora.fedora_config.empty?
43
- ActiveFedora.init
44
- end
48
+ if ActiveFedora.fedora_config.empty?
49
+ ActiveFedora.init
50
+ end
45
51
 
46
- if defined?(Blacklight)
47
- solr_config = Blacklight.solr_config
48
- else
49
-
50
- if defined?(RAILS_ROOT)
51
- config_path = File.join(RAILS_ROOT, "config")
52
- yaml = YAML.load(File.open(File.join(config_path, "solr.yml")))
53
- solr_config = yaml[RAILS_ENV]
54
- puts solr_config.inspect
55
- else
56
- config_path = File.join(File.dirname(__FILE__), "..", "..", "..", "config")
57
- yaml = YAML.load(File.open(File.join(config_path, "solr.yml")))
58
-
59
-
60
- if ENV["environment"].nil?
61
- environment = "development"
52
+ if defined?(Blacklight)
53
+ solr_config = Blacklight.solr_config
54
+ else
55
+ if defined?(RAILS_ROOT)
56
+ config_path = File.join(RAILS_ROOT, "config")
57
+ yaml = YAML.load(File.open(File.join(config_path, "solr.yml")))
58
+ puts RAILS_ENV + "*****"
59
+ solr_config = yaml[RAILS_ENV]
60
+ puts solr_config.inspect
62
61
  else
63
- environment = ENV["environment"]
64
- end
62
+ config_path = File.join(File.dirname(__FILE__), "..", "..", "..", "config")
63
+ puts config_path.inspect + "&&&&&&&"
64
+ yaml = YAML.load(File.open(File.join(config_path, "solr.yml")))
65
+
66
+ if ENV["environment"].nil?
67
+ environment = "development"
68
+ else
69
+ environment = ENV["environment"]
70
+ end #if
65
71
 
66
- solr_config = yaml[environment]
67
- puts solr_config.inspect
68
- end
72
+ solr_config = yaml[environment]
73
+ puts solr_config.inspect
74
+ end #if defined?(RAILS_ROOT)
69
75
 
70
- end
76
+ end #if defined?(Blacklight)
71
77
 
72
- if index_full_text == true
73
- url = solr_config['fulltext']['url']
74
- elsif solr_config.has_key?("default")
75
- url = solr_config['default']['url']
76
- else
77
- url = solr_config['url']
78
+ if index_full_text == true && solr_config['fulltext'].has_key?('url')
79
+ url = solr_config['fulltext']['url']
80
+ elsif solr_config.has_key?("default") &&
81
+ url = solr_config['default']['url']
82
+ elsif solr_config.has_key?('url')
83
+ url = solr_config['url']
84
+ elsif solr_config.has_key?(:url)
85
+ url = solr_config[:url]
86
+ else
87
+ raise
88
+ end
89
+ @connection = Solr::Connection.new(url, :autocommit => :on )
90
+
91
+ rescue
92
+ puts "Unable to establish SOLR Connection with #{solr_config.inspect}"
93
+ raise URI::InvalidURIError
78
94
  end
79
- @connection = Solr::Connection.new(url, :autocommit => :on )
80
- end
81
95
 
82
96
  #
83
97
  # This method extracts the facet categories from the given Fedora object's external tag datastream
@@ -1,6 +1,6 @@
1
1
  namespace :solrizer do
2
2
 
3
- namespace :fedora
3
+ namespace :fedora do
4
4
  desc 'Index a fedora object of the given pid.'
5
5
  task :solrize => :environment do
6
6
  index_full_text = ENV['FULL_TEXT'] == 'true'
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{solrizer-fedora}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matt Zumwalt"]
12
- s.date = %q{2010-10-26}
12
+ s.date = %q{2011-01-22}
13
13
  s.description = %q{An extension to projecthydra/solrizer that provides utilities for loading objects from Fedora Repositories and creating solr documents from them.}
14
14
  s.email = %q{matt.zumwalt@yourmediashelf.com}
15
15
  s.extra_rdoc_files = [
@@ -39,6 +39,7 @@ Gem::Specification.new do |s|
39
39
  "solrizer-fedora.gemspec",
40
40
  "spec/fixtures/rels_ext_cmodel.xml",
41
41
  "spec/integration/fedora_indexer_spec.rb",
42
+ "spec/lib/solrizer/indexer_spec.rb",
42
43
  "spec/rcov.opts",
43
44
  "spec/spec.opts",
44
45
  "spec/spec_helper.rb",
@@ -53,6 +54,7 @@ Gem::Specification.new do |s|
53
54
  s.summary = %q{An extension to solrizer that deals with Fedora objects & Repositories}
54
55
  s.test_files = [
55
56
  "spec/integration/fedora_indexer_spec.rb",
57
+ "spec/lib/solrizer/indexer_spec.rb",
56
58
  "spec/spec_helper.rb",
57
59
  "spec/units/fedora_extractor_spec.rb",
58
60
  "spec/units/fedora_indexer_spec.rb",
@@ -0,0 +1,79 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+ require 'solrizer'
3
+ require "solrizer/fedora"
4
+
5
+
6
+ describe Solrizer::Fedora::Indexer do
7
+
8
+ before(:all) do
9
+
10
+ unless defined?(RAILS_ROOT) and defined?(RAILS_ENV)
11
+ RAILS_ROOT = "."
12
+ RAILS_ENV = "test"
13
+ end
14
+
15
+ unless defined?(Blacklight)
16
+ Object.const_set("Blacklight", String )
17
+ end
18
+ end
19
+
20
+ before(:each) do
21
+
22
+ @extractor = mock("Extractor")
23
+ @extractor.stubs(:html_content_to_solr).returns(@solr_doc)
24
+ @solr_doc = Solr::Document.new
25
+ Solrizer::Extractor.expects(:new).returns(@extractor)
26
+
27
+ end
28
+
29
+ after(:all) do
30
+ if Blacklight == String
31
+ Object.send(:remove_const,:Blacklight)
32
+ end
33
+ end
34
+
35
+ describe "#new" do
36
+ it "should return a URL from solr_config if the config has a :url" do
37
+ Blacklight.stubs(:solr_config).returns({:url => "http://foo.com:8080/solr"})
38
+ @indexer = Solrizer::Fedora::Indexer.new
39
+ end
40
+
41
+ it "should return a URL from solr_config if the config has a 'url' " do
42
+ Blacklight.stubs(:solr_config).returns({'url' => "http://foo.com:8080/solr"})
43
+ @indexer = Solrizer::Fedora::Indexer.new
44
+ end
45
+
46
+ it "should raise and error if there is not a :url or 'url' in the config hash" do
47
+ Blacklight.stubs(:solr_config).returns({'boosh' => "http://foo.com:8080/solr"})
48
+ lambda { Solrizer::Fedora::Indexer.new }.should raise_error(URI::InvalidURIError)
49
+ end
50
+
51
+ it "should return a fulltext URL if solr_config has a fulltext url defined" do
52
+ Blacklight.stubs(:solr_config).returns({'fulltext' =>{ 'url' => "http://foo.com:8080/solr"}})
53
+ @indexer = Solrizer::Fedora::Indexer.new(:index_full_text => true)
54
+ end
55
+
56
+ it "should return a fulltext URL if solr_config has a default url defined" do
57
+ Blacklight.stubs(:solr_config).returns({'default' =>{ 'url' => "http://foo.com:8080/solr"}})
58
+ @indexer = Solrizer::Fedora::Indexer.new(:index_full_text => false)
59
+ end
60
+
61
+ it "should find the solr.yml even if Blacklight is not loaded" do
62
+ Object.const_set("Blacklight_temp", Blacklight )
63
+ Object.send(:remove_const, :Blacklight)
64
+ YAML.stubs(:load).returns({'test' => {'url' => "http://thereisnoblacklightrunning.edu:8080/solr"}})
65
+ @indexer = Solrizer::Fedora::Indexer.new
66
+ Object.const_set("Blacklight", Blacklight_temp )
67
+ end
68
+
69
+ it "should find the solr.yml even if Blacklight is not loaded and RAILS is not loaded" do
70
+ Object.const_set("Blacklight_temp", Blacklight )
71
+ Object.send(:remove_const, :Blacklight)
72
+ Object.send(:remove_const, :RAILS_ROOT)
73
+ YAML.stubs(:load).returns({'development' => {'url' => "http://noblacklight.norails.edu:8080/solr"}})
74
+ @indexer = Solrizer::Fedora::Indexer.new
75
+ Object.const_set("Blacklight", Blacklight_temp )
76
+ end
77
+ end
78
+ end
79
+
data/spec/spec_helper.rb CHANGED
@@ -6,6 +6,21 @@ require 'spec/autorun'
6
6
 
7
7
  require 'solrizer'
8
8
 
9
+
10
+ # this allows us to unload constants for testing
11
+ module Kernel
12
+ # Suppresses warnings within a given block.
13
+ def with_warnings_suppressed
14
+ saved_verbosity = $-v
15
+ $-v = nil
16
+ yield
17
+ ensure
18
+ $-v = saved_verbosity
19
+ end
20
+ end
21
+
22
+
23
+
9
24
  Spec::Runner.configure do |config|
10
25
 
11
26
  config.mock_with :mocha
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solrizer-fedora
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Zumwalt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-26 00:00:00 -05:00
18
+ date: 2011-01-22 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -51,6 +51,7 @@ files:
51
51
  - solrizer-fedora.gemspec
52
52
  - spec/fixtures/rels_ext_cmodel.xml
53
53
  - spec/integration/fedora_indexer_spec.rb
54
+ - spec/lib/solrizer/indexer_spec.rb
54
55
  - spec/rcov.opts
55
56
  - spec/spec.opts
56
57
  - spec/spec_helper.rb
@@ -93,6 +94,7 @@ specification_version: 3
93
94
  summary: An extension to solrizer that deals with Fedora objects & Repositories
94
95
  test_files:
95
96
  - spec/integration/fedora_indexer_spec.rb
97
+ - spec/lib/solrizer/indexer_spec.rb
96
98
  - spec/spec_helper.rb
97
99
  - spec/units/fedora_extractor_spec.rb
98
100
  - spec/units/fedora_indexer_spec.rb