mwmitchell-rsolr 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,3 +1,7 @@
1
+ 0.8.4 - April 3, 2009
2
+ New test suite using RSpec and mocks coming. Run "rake spec"
3
+ - added specs for RSolr and RSolr::Connection
4
+
1
5
  0.8.3 - April 3, 2009
2
6
  RSolr::Connection
3
7
  - removed the block functionality of send_request and related methods
data/README.rdoc CHANGED
@@ -41,7 +41,7 @@ To get a direct connection (no http) in jRuby using DirectSolrConnection:
41
41
  :adapter=>:direct,
42
42
  :home_dir=>'/path/to/solr/home',
43
43
  :dist_dir=>'/path/to/solr/distribution'
44
- )
44
+ })
45
45
 
46
46
  == Requests
47
47
  Once you have a connection, you can execute queries, updates etc..
@@ -50,29 +50,29 @@ Once you have a connection, you can execute queries, updates etc..
50
50
  Use the #select method to send requests to the /select handler:
51
51
  response = solr.select({
52
52
  :q=>'washington',
53
- :facet=>true,
54
- 'facet.limit'=>-1,
55
- 'facet.field'=>'cat',
56
- 'facet.field'=>'inStock',
57
53
  :start=>0,
58
54
  :rows=>10
59
55
  })
56
+
57
+ Use the #send_request method to set a custom request handler path:
58
+ response = solr.send_request('/documents', {:q=>'test'})
60
59
 
61
60
 
62
61
  === Updating Solr
63
- Updating is done using native Ruby structures. Hashes are used for single documents and arrays are used for a collection of documents (hashes). These structures get turned into simple XML "messages".
62
+ Updating can be done using native Ruby structures. Hashes are used for single documents and arrays are used for a collection of documents (hashes). These structures get turned into simple XML "messages". Raw XML can also be used of course.
64
63
 
65
- Raw XML
66
- response = solr.update('</optimize>')
64
+ Raw XML via #update
65
+ solr.update('</commit>')
66
+ solr.update('</optimize>')
67
67
 
68
- Single document
69
- response = solr.add(:id=>1, :price=>1.00)
68
+ Single document via #add
69
+ solr.add(:id=>1, :price=>1.00)
70
70
 
71
- Multiple documents
71
+ Multiple documents via #add
72
72
  documents = [{:id=>1, :price=>1.00}, {:id=>2, :price=>10.50}]
73
- response = solr.add(documents)
73
+ solr.add(documents)
74
74
 
75
- When adding, you can also supply "add" xml element attributes and/or a block for manipulating other "add" related elements:
75
+ When adding, you can also supply "add" xml element attributes and/or a block for manipulating other "add" related elements (docs and fields) when using the #add method:
76
76
 
77
77
  doc = {:id=>1, :price=>1.00}
78
78
  add_attributes = {:allowDups=>false, :commitWithin=>10.0}
@@ -84,14 +84,14 @@ When adding, you can also supply "add" xml element attributes and/or a block for
84
84
  end
85
85
 
86
86
  Delete by id
87
- response = solr.delete_by_id(1)
87
+ solr.delete_by_id(1)
88
88
  or an array of ids
89
- response = solr.delete_by_id([1, 2, 3, 4])
89
+ solr.delete_by_id([1, 2, 3, 4])
90
90
 
91
91
  Delete by query:
92
- response = solr.delete_by_query('price:1.00')
92
+ solr.delete_by_query('price:1.00')
93
93
  Delete by array of queries
94
- response = solr.delete_by_query(['price:1.00', 'price:10.00'])
94
+ solr.delete_by_query(['price:1.00', 'price:10.00'])
95
95
 
96
96
 
97
97
  Commit & optimize shortcuts
data/Rakefile CHANGED
@@ -21,18 +21,25 @@ Rake::TestTask.new("test_units") { |t|
21
21
  t.libs << "test"
22
22
  }
23
23
 
24
+ require 'spec/rake/spectask'
24
25
 
25
- desc 'Run specs' # this task runs each test in its own process
26
- task :specs do
27
- require 'rubygems'
28
- require 'facets/more/filelist' unless defined?(FileList)
29
- files = FileList["**/*_spec.rb"]
30
- p files.to_a
31
- files.each do |filename|
32
- system "cd #{File.dirname(filename)} && ruby #{File.basename(filename)}"
33
- end
26
+ desc "Run specs"
27
+ Spec::Rake::SpecTask.new('spec') do |t|
28
+ t.spec_files = FileList['spec/**/*_spec.rb']
29
+ t.libs += ["lib", "spec"]
34
30
  end
35
31
 
32
+ #desc 'Run specs' # this task runs each test in its own process
33
+ #task :specs do
34
+ # require 'rubygems'
35
+ # require 'facets/more/filelist' unless defined?(FileList)
36
+ # files = FileList["**/*_spec.rb"]
37
+ # p files.to_a
38
+ # files.each do |filename|
39
+ # system "cd #{File.dirname(filename)} && ruby #{File.basename(filename)}"
40
+ # end
41
+ #end
42
+
36
43
  #desc "Run specs"
37
44
  #Rake::TestTask.new("specs") { |t|
38
45
  # t.pattern = 'spec/**/*_spec.rb'
data/lib/rsolr.rb CHANGED
@@ -9,7 +9,7 @@ require 'mash'
9
9
 
10
10
  module RSolr
11
11
 
12
- VERSION = '0.8.3'
12
+ VERSION = '0.8.4'
13
13
 
14
14
  autoload :Message, 'rsolr/message'
15
15
  autoload :Connection, 'rsolr/connection'
@@ -0,0 +1,151 @@
1
+ require 'helper'
2
+
3
+ describe RSolr::Connection do
4
+
5
+ context 'the initialize method' do
6
+
7
+ it 'should require one argument' do
8
+ lambda{RSolr::Connection.new}.should raise_error(ArgumentError)
9
+ end
10
+
11
+ end
12
+
13
+ before(:each) do
14
+ @adapter = mock('RSolr::Adapter::HTTP')
15
+ @connection = RSolr::Connection.new(@adapter)
16
+ end
17
+
18
+ context '#map_params method' do
19
+ it 'should merge :wt=>:ruby to the incoming params' do
20
+ result = @connection.send(:map_params, {})
21
+ result[:wt].should == :ruby
22
+ end
23
+ it 'should not overwrite an existing :wt param' do
24
+ result = @connection.send(:map_params, {:wt=>'xml'})
25
+ result[:wt].should == 'xml'
26
+ end
27
+ end
28
+
29
+ context '#adapt_response method' do
30
+ it 'should evaluate the :body value if the :wt param IS :ruby' do
31
+ response_from_adapter = {:body=>'{}', :params=>{:wt=>:ruby}}
32
+ result = @connection.send(:adapt_response, response_from_adapter)
33
+ result.should be_a(Hash)
34
+ end
35
+ it 'should not evaluate the :body value if the :wt is NOT :ruby' do
36
+ response_from_adapter = {:body=>'</xml>', :params=>{:wt=>:xml}}
37
+ result = @connection.send(:adapt_response, response_from_adapter)
38
+ result.should be_a(String)
39
+ end
40
+ it 'should return an object that will respond_to?(:adapter_response)' do
41
+ response_from_adapter = {:body=>'</xml>', :params=>{:wt=>:xml}}
42
+ result = @connection.send(:adapt_response, response_from_adapter)
43
+ result.should respond_to(:adapter_response)
44
+ end
45
+ it 'should return the original adapter response from #adapter_response method' do
46
+ response_from_adapter = {:body=>'</xml>', :params=>{:wt=>:xml}}
47
+ result = @connection.send(:adapt_response, response_from_adapter)
48
+ result.adapter_response.should == response_from_adapter
49
+ end
50
+ end
51
+
52
+ it 'should have an adapter' do
53
+ @connection.adapter.should == @adapter
54
+ end
55
+
56
+ it 'should send requests to the adapter' do
57
+ params = {:wt=>:ruby, :q=>'test'}
58
+ expected_return = {:params=>params, :body=>'{}'}
59
+ @adapter.should_receive(:send_request).with(
60
+ '/documents',
61
+ params,
62
+ nil
63
+ ).once.and_return(expected_return)
64
+ @connection.send_request('/documents', :q=>'test')
65
+ end
66
+
67
+ context '#select method' do
68
+
69
+ it 'should set the solr request path to /select' do
70
+ params = {:wt=>:ruby, :q=>'test'}
71
+ expected_return = {:params=>params, :body=>'{}'}
72
+ @adapter.should_receive(:send_request).with(
73
+ '/select',
74
+ params,
75
+ nil
76
+ ).once.and_return(expected_return)
77
+ @connection.select(:q=>'test')
78
+ end
79
+
80
+ it 'should add a :qt=>:ruby to the params, then pass the params to the adapter' do
81
+ input_params = {:q=>'test', :fq=>'filter:one', :fq=>'documents'}
82
+ expected_modified_params = input_params.merge({:wt=>:ruby})
83
+ expected_return = {:body=>'{}', :params=>expected_modified_params}
84
+ @adapter.should_receive(:send_request).with(
85
+ '/select',
86
+ hash_including(expected_modified_params),
87
+ nil
88
+ ).once.and_return(expected_return)
89
+ @connection.select(input_params)
90
+ end
91
+
92
+ it 'should return a hash' do
93
+ @adapter.should_receive(:send_request).and_return(
94
+ {:body=>'{}', :params=>{:wt=>:ruby}}
95
+ )
96
+ @connection.select(:q=>'test').should be_a(Hash)
97
+ end
98
+
99
+ end
100
+
101
+ context '#update method' do
102
+
103
+ it 'should set the solr request path to /update' do
104
+ expected_params = {:name=>'test', :wt=>:ruby}
105
+ @adapter.should_receive(:send_request).with(
106
+ '/update',
107
+ hash_including(expected_params),
108
+ '</optimize>'
109
+ ).once.and_return(
110
+ {:body=>'{}', :params=>expected_params}
111
+ )
112
+ @connection.update('</optimize>', :name=>'test')
113
+ end
114
+
115
+ it 'should accept a solr params hash' do
116
+ @adapter.should_receive(:send_request).with(
117
+ '/update',
118
+ hash_including(:xyz=>123, :wt=>:ruby),
119
+ '</optimize>'
120
+ ).once.and_return(
121
+ {:body=>'{}', :params=>{:xyz=>123, :wt=>:ruby}}
122
+ )
123
+ @connection.update('</optimize>', :xyz=>123)
124
+ end
125
+
126
+ end
127
+
128
+ context '#send_request method' do
129
+
130
+ it 'should send the request path to the adapter' do
131
+ @adapter.should_receive(:send_request).with(
132
+ '/documents',
133
+ hash_including(:q=>'test', :wt=>:ruby),
134
+ nil
135
+ ).once.and_return({:body=>'{}', :params=>{:wt=>:ruby, :q=>'test'}})
136
+ @connection.send_request('/documents', :q=>'test')
137
+ end
138
+
139
+ it 'should return an object will respond_to :adapter_response' do
140
+ @adapter.should_receive(:send_request).with(
141
+ '/select',
142
+ hash_including(:q=>'test', :wt=>:ruby),
143
+ nil
144
+ ).once.and_return({:body=>'{}', :params=>{:q=>'test', :wt=>:ruby}})
145
+ response = @connection.select(:q=>'test')
146
+ response.should respond_to(:adapter_response)
147
+ end
148
+
149
+ end
150
+
151
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+
4
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr')
@@ -0,0 +1,29 @@
1
+ require 'helper'
2
+
3
+ describe RSolr::Connection do
4
+
5
+ context 'the #connect method' do
6
+
7
+ it 'should exist' do
8
+ RSolr.should respond_to(:connect)
9
+ end
10
+
11
+ it 'should return an RSolr::Connection object' do
12
+ RSolr.connect.should be_a(RSolr::Connection)
13
+ end
14
+
15
+ end
16
+
17
+ context "the #escape method" do
18
+
19
+ it "should exist" do
20
+ RSolr.should respond_to(:escape)
21
+ end
22
+
23
+ it "should escape properly" do
24
+ RSolr.escape('Trying & % different "characters" here!').should == "Trying\\ \\&\\ \\%\\ different\\ \\\"characters\\\"\\ here\\!"
25
+ end
26
+
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwmitchell-rsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 0.8.4
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: 2009-03-24 00:00:00 -07:00
12
+ date: 2009-04-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -91,3 +91,6 @@ test_files:
91
91
  - test/message_test.rb
92
92
  - test/rsolr_test
93
93
  - test/test_helpers.rb
94
+ - spec/connection_spec.rb
95
+ - spec/helper.rb
96
+ - spec/rsolr_spec.rb