rsolr-direct 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,30 +2,27 @@
2
2
  rsolr-direct enhances the RSolr core library by adding the ability to connect to Solr directly, using JRuby, sans http. Hotdog!
3
3
 
4
4
  = How
5
- Check out the specs to see the various connection methods. Overview below...
5
+ Check out the specs to see the various connection methods.
6
6
 
7
- ==Using :solr_home
7
+ == Solr Java libs/jars
8
+ RSolr-Direct comes with the required Solr jars. If you'd like to use them, just call #load_java_libs:
8
9
  require 'rsolr-direct'
9
- Dir['/path/to/solr/distribution/lib/*.jar', '/path/to/solr/distribution/dist/*.jar'].each do |jar|
10
- require jar
11
- end
12
- connection = RSolr.connect :solr_home => '/absolute/path/to/solr/home'
10
+ RSolr.load_java_libs
11
+ # create connection etc..
13
12
 
14
- ==Using a Java::OrgApacheSolrCore::SolrCore instance
13
+ ==:solr_home
15
14
  require 'rsolr-direct'
16
- Dir['/path/to/solr/distribution/lib/*.jar', '/path/to/solr/distribution/dist/*.jar'].each do |jar|
17
- require jar
18
- end
19
- core = org.apache.solr.core.SolrCore.new( nil, solr_data_path, solr_config, index_schema, dcore)
20
- connection = RSolr.connect core
15
+ connection = RSolr.connect :direct, :solr_home => '/absolute/path/to/solr/home'
16
+
17
+ ==Java::OrgApacheSolrCore::SolrCore
18
+ require 'rsolr-direct'
19
+ core = org.apache.solr.core.SolrCore.new(nil, solr_data_path, solr_config, index_schema, dcore)
20
+ connection = RSolr.connect :direct, core
21
21
 
22
- ==Using a Java::OrgApacheSolrServlet::DirectSolrConnection
22
+ ==Java::OrgApacheSolrServlet::DirectSolrConnection
23
23
  require 'rsolr-direct'
24
- Dir['/path/to/solr/distribution/lib/*.jar', '/path/to/solr/distribution/dist/*.jar'].each do |jar|
25
- require jar
26
- end
27
- dc = org.apache.solr.servlet.DirectSolrConnection.new(solr_home_path, solr_data_path, nil)
28
- connection = RSolr.connect dc
24
+ dc = org.apache.solr.servlet.DirectSolrConnection.new(solr_home_path, solr_data_path, solr_log_path)
25
+ connection = RSolr.connect :direct, dc
29
26
 
30
27
  = Why
31
28
  Using a direct connection to Solr can speed up indexing. How much faster? I have no idea yet. Numbers to come?
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ begin
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
14
  gem.add_dependency "rsolr", ">= 0.12.1"
15
15
 
16
- gem.files = FileList['lib/**/*.rb', 'LICENSE', 'README.rdoc', 'VERSION']
16
+ gem.files = FileList['lib/**/*.rb', 'LICENSE', 'README.rdoc', 'VERSION', 'solr/dist/*', 'solr/lib/*']
17
17
  gem.test_files = ['spec/*', 'Rakefile', 'solr/dist/*', 'solr/lib/*', 'solr/example/solr/*']
18
18
 
19
19
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
data/lib/rsolr-direct.rb CHANGED
@@ -1,4 +1,4 @@
1
- #require 'java'
1
+ require 'java'
2
2
  require 'rubygems'
3
3
  require 'rsolr'
4
4
 
@@ -9,13 +9,27 @@ module RSolr::Direct
9
9
 
10
10
  module Connectable
11
11
 
12
+ # load the java libs that ship with rsolr-direct
13
+ # RSolr.load_java_libs
14
+ # rsolr = RSolr.connect :direct, :solr_home => ''
15
+ def load_java_libs
16
+ @java_libs_loaded ||= (
17
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'solr'))
18
+ ['lib', 'dist'].each do |sub|
19
+ Dir[File.join(base_dir, sub, '*.jar')].each do |jar|
20
+ require jar
21
+ end
22
+ end
23
+ true
24
+ )
25
+ end
26
+
27
+ # RSolr.connect :direct, :solr_home => 'apache-solr/example/solr'
28
+ # RSolr.connect :direct, java_solr_core
29
+ # RSolr.connect :direct, java_direct_solr_connection
12
30
  def connect *args, &blk
13
- first = args.first
14
- use_dc = first.is_a?(Hash) and first[:solr_home]
15
- use_dc = use_dc || (first.class.to_s == "Java::OrgApacheSolrCore::SolrCore")
16
- use_dc = use_dc || (first.class.to_s == "Java::OrgApacheSolrServlet::DirectSolrConnection")
17
- if use_dc
18
- client = RSolr::Client.new RSolr::Direct::Connection.new(first)
31
+ if args.first == :direct
32
+ client = RSolr::Client.new RSolr::Direct::Connection.new(*args[1..-1])
19
33
  if block_given?
20
34
  yield client
21
35
  client.connection.close
@@ -50,7 +64,6 @@ module RSolr::Direct
50
64
  # then...
51
65
  # required: opts[:solr_home] is absolute path to solr home (the directory with "data", "config" etc.)
52
66
  def initialize opts
53
- opts ||= {}
54
67
 
55
68
  begin
56
69
  org.apache.solr.servlet.DirectSolrConnection
@@ -58,30 +71,27 @@ module RSolr::Direct
58
71
  raise MissingRequiredJavaLibs
59
72
  end
60
73
 
61
- if defined?(Java::OrgApacheSolrCore::SolrCore) and opts.is_a?(Java::OrgApacheSolrCore::SolrCore)
62
- puts "OKOKOKOK a SolrCore!"
63
- @connection = org.apache.solr.servlet.DirectSolrConnection.new(opts)
64
- elsif defined?(Java::OrgApacheSolrServlet::DirectSolrConnection) and opts.is_a?(Java::OrgApacheSolrServlet::DirectSolrConnection)
65
- @connection = opts
66
- else
67
- opts[:solr_home] ||= ''
74
+ if opts.is_a?(Hash) and opts[:solr_home]
68
75
  raise InvalidSolrHome unless File.exists?(opts[:solr_home])
69
76
  opts[:data_dir] ||= File.join(opts[:solr_home], 'data')
70
77
  @opts = opts
78
+ elsif opts.class.to_s == "Java::OrgApacheSolrCore::SolrCore"
79
+ @direct = org.apache.solr.servlet.DirectSolrConnection.new(opts)
80
+ elsif opts.class.to_s == "Java::OrgApacheSolrServlet::DirectSolrConnection"
81
+ @direct = opts
71
82
  end
72
83
  end
73
84
 
74
- # sets the @connection instance variable if it has not yet been set
75
- def connection
76
- @connection ||= (
77
- org.apache.solr.servlet.DirectSolrConnection.new(opts[:home_dir], @opts[:data_dir], nil)
78
- )
85
+ # sets the @direct instance variable if it has not yet been set
86
+ def direct
87
+ @direct ||= org.apache.solr.servlet.DirectSolrConnection.new(opts[:solr_home], @opts[:data_dir], nil)
79
88
  end
80
89
 
81
90
  def close
82
- if @connection
83
- @connection.close
84
- @connection=nil
91
+ if @direct
92
+ @direct.close
93
+ puts "CLOSING -> #{@direct}"
94
+ @direct = nil
85
95
  end
86
96
  end
87
97
 
@@ -92,7 +102,7 @@ module RSolr::Direct
92
102
  data = data.to_xml if data.respond_to?(:to_xml)
93
103
  url = build_url(path, params)
94
104
  begin
95
- body = connection.request(url, data)
105
+ body = direct.request(url, data)
96
106
  rescue
97
107
  raise RSolr::RequestError.new($!.message)
98
108
  end
@@ -14,26 +14,26 @@ describe RSolr::Direct do
14
14
 
15
15
  it 'should attempt to use a direct connect if :solr_home is set but raise a MissingRequiredJavaLibs' do
16
16
  lambda{
17
- RSolr.connect(:solr_home=>'')
17
+ RSolr.connect(:direct, nil)
18
18
  }.should raise_error(RSolr::Direct::Connection::MissingRequiredJavaLibs)
19
19
  end
20
20
 
21
21
  it 'should attempt to use a direct connect if :solr_home is set but raise a InvalidSolrHome' do
22
22
  load_required_java_libs
23
23
  lambda{
24
- RSolr.connect(:solr_home=>'')
24
+ RSolr.connect(:direct, :solr_home=>'')
25
25
  }.should raise_error(RSolr::Direct::Connection::InvalidSolrHome)
26
26
  end
27
27
 
28
28
  it 'should create direct connection succesfully' do
29
29
  load_required_java_libs
30
- RSolr.connect(:solr_home=>solr_home_dir).connection.should be_a(RSolr::Direct::Connection)
30
+ RSolr.connect(:direct, :solr_home=>solr_home_dir).connection.should be_a(RSolr::Direct::Connection)
31
31
  end
32
32
 
33
33
  it 'should accept a Java::OrgApacheSolrCore::SolrCore' do
34
34
  load_required_java_libs
35
35
  core = new_solr_core solr_home_dir, solr_data_dir
36
- rsolr = RSolr.connect(core)
36
+ rsolr = RSolr.connect(:direct, core)
37
37
  rsolr.should be_a(RSolr::Client)
38
38
  rsolr.connection.should be_a(RSolr::Direct::Connection)
39
39
  core.close
@@ -42,7 +42,7 @@ describe RSolr::Direct do
42
42
  it 'should accept a Java::OrgApacheSolrServlet::DirectSolrConnection' do
43
43
  load_required_java_libs
44
44
  dc = new_direct_solr_connection solr_home_dir, solr_data_dir
45
- rsolr = RSolr.connect(dc)
45
+ rsolr = RSolr.connect(:direct, dc)
46
46
  rsolr.should be_a(RSolr::Client)
47
47
  rsolr.connection.should be_a(RSolr::Direct::Connection)
48
48
  dc.close
@@ -50,4 +50,58 @@ describe RSolr::Direct do
50
50
 
51
51
  end
52
52
 
53
+ module ConnectionHelpers
54
+
55
+ def self.included base
56
+ base.let(:connections){
57
+ [
58
+ RSolr.connect(:direct, :solr_home=>solr_home_dir),
59
+ RSolr.connect(:direct, new_solr_core(solr_home_dir, solr_data_dir)),
60
+ RSolr.connect(:direct, new_direct_solr_connection(solr_home_dir, solr_data_dir))
61
+ ]
62
+ }
63
+ end
64
+
65
+ end
66
+
67
+ context 'connection closing' do
68
+
69
+ include ConnectionHelpers
70
+
71
+ it '(they) should have connection objects that respond to close, and set the internal "direct" attribute to nil' do
72
+ connections.each do |rsolr|
73
+ rsolr.connection.direct # <- connect
74
+ rsolr.connection.instance_variable_get("@direct").should_not be(nil)
75
+ rsolr.connection.close
76
+ rsolr.connection.instance_variable_get("@direct").should be(nil)
77
+ end
78
+ end
79
+
80
+ it 'should automatically close when using the block style of connecting' do
81
+ rsolr = nil
82
+ RSolr.connect(:direct, :solr_home => solr_home_dir) do |client|
83
+ rsolr = client
84
+ client.connection.direct # <- connect
85
+ rsolr.connection.instance_variable_get("@direct").should_not be(nil)
86
+ end
87
+ rsolr.connection.instance_variable_get("@direct").should be(nil)
88
+ end
89
+
90
+ end
91
+
92
+ context 'querying' do
93
+
94
+ include ConnectionHelpers
95
+
96
+ it '(they) should return a solr response hash when calling select' do
97
+ connections.each do |rsolr|
98
+ response = rsolr.select(:q => '*:*')
99
+ response.should be_a(Hash)
100
+ response.keys.should include("response", "responseHeader")
101
+ rsolr.connection.close
102
+ end
103
+ end
104
+
105
+ end
106
+
53
107
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rsolr-direct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mitchell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-04 00:00:00 -05:00
12
+ date: 2010-02-05 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -46,6 +46,35 @@ files:
46
46
  - README.rdoc
47
47
  - VERSION
48
48
  - lib/rsolr-direct.rb
49
+ - solr/dist/apache-solr-1.4.0.war
50
+ - solr/dist/apache-solr-cell-1.4.0.jar
51
+ - solr/dist/apache-solr-clustering-1.4.0.jar
52
+ - solr/dist/apache-solr-core-1.4.0.jar
53
+ - solr/dist/apache-solr-dataimporthandler-1.4.0.jar
54
+ - solr/dist/apache-solr-dataimporthandler-extras-1.4.0.jar
55
+ - solr/dist/apache-solr-solrj-1.4.0.jar
56
+ - solr/lib/commons-codec-1.3.jar
57
+ - solr/lib/commons-csv-1.0-SNAPSHOT-r609327.jar
58
+ - solr/lib/commons-fileupload-1.2.1.jar
59
+ - solr/lib/commons-httpclient-3.1.jar
60
+ - solr/lib/commons-io-1.4.jar
61
+ - solr/lib/easymock.jar
62
+ - solr/lib/geronimo-stax-api_1.0_spec-1.0.1.jar
63
+ - solr/lib/jcl-over-slf4j-1.5.5.jar
64
+ - solr/lib/junit-4.3.jar
65
+ - solr/lib/lucene-analyzers-2.9.1.jar
66
+ - solr/lib/lucene-core-2.9.1.jar
67
+ - solr/lib/lucene-highlighter-2.9.1.jar
68
+ - solr/lib/lucene-memory-2.9.1.jar
69
+ - solr/lib/lucene-misc-2.9.1.jar
70
+ - solr/lib/lucene-queries-2.9.1.jar
71
+ - solr/lib/lucene-snowball-2.9.1.jar
72
+ - solr/lib/lucene-spellchecker-2.9.1.jar
73
+ - solr/lib/servlet-api-2.4.jar
74
+ - solr/lib/slf4j-api-1.5.5.jar
75
+ - solr/lib/slf4j-jdk14-1.5.5.jar
76
+ - solr/lib/solr-commons-csv-pom.xml.template
77
+ - solr/lib/wstx-asl-3.2.7.jar
49
78
  has_rdoc: true
50
79
  homepage: http://github.com/mwmitchell/rsolr-direct
51
80
  licenses: []