delsolr 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.txt CHANGED
@@ -7,6 +7,17 @@ http://delsolr.rubyforge.org
7
7
  DelSolr is a light weight ruby wrapper for solr. It's intention is to expose the full power of solr queries
8
8
  while keeping the interface as ruby-esque as possible.
9
9
 
10
+ == Installation
11
+
12
+ Can be installed as a gem which is hosted on http://gemcutter.org
13
+
14
+ gem install delsolr
15
+
16
+ or as a plugin...
17
+
18
+ ruby script/plugin install git://github.com/avvo/delsolr.git
19
+
20
+
10
21
  == PROBLEMS:
11
22
 
12
23
  * Not threadsafe yet
@@ -1,12 +1,13 @@
1
1
  module DelSolr
2
2
  class Client
3
3
  class Configuration
4
- attr_accessor :server, :port, :timeout
4
+ attr_accessor :server, :port, :timeout, :path
5
5
 
6
- def initialize(server, port, timeout = 120)
6
+ def initialize(server, port, timeout = nil, path = nil)
7
7
  @server = server
8
8
  @port = port.to_i
9
9
  @timeout = timeout || 120
10
+ @path = path || '/solr'
10
11
  end
11
12
 
12
13
  end
@@ -109,7 +109,7 @@ module DelSolr
109
109
  end
110
110
  end
111
111
 
112
- "/solr/select?#{param_strings.join('&')}"
112
+ "/select?#{param_strings.join('&')}"
113
113
  end
114
114
 
115
115
  # returns the query param
data/lib/delsolr.rb CHANGED
@@ -37,7 +37,7 @@ module DelSolr
37
37
  # [<b><tt>:shortcuts</tt></b>]
38
38
  # (options) a list of values in the doc fields to generate short cuts for (ie: [:scores, :id], you will be able to call <tt>rsp.scores</tt> and have it return an array of scores, likewise for <tt>ids</tt>.) Defaults to [:id, :unique_id, :score]
39
39
  def initialize(options = {})
40
- @configuration = DelSolr::Client::Configuration.new(options[:server], options[:port], options[:timeout])
40
+ @configuration = DelSolr::Client::Configuration.new(options[:server], options[:port], options[:timeout], options[:path])
41
41
  @cache = options[:cache]
42
42
  @shortcuts = options[:shortcuts]
43
43
  end
@@ -157,7 +157,7 @@ module DelSolr
157
157
  end
158
158
 
159
159
  if body.blank? # cache miss (or wasn't enabled)
160
- header, body = connection.get(query_builder.request_string)
160
+ header, body = connection.get(configuration.path + query_builder.request_string)
161
161
 
162
162
  # add to the cache if caching
163
163
  if enable_caching
@@ -253,7 +253,7 @@ module DelSolr
253
253
 
254
254
  # helper for posting data to solr
255
255
  def post(buffer)
256
- connection.post('/solr/update', buffer, {'Content-type' => 'text/xml;charset=utf-8'})
256
+ connection.post("#{configuration.path}/update", buffer, {'Content-type' => 'text/xml;charset=utf-8'})
257
257
  end
258
258
 
259
259
  def success?(response_body)
data/test/test_client.rb CHANGED
@@ -177,26 +177,40 @@ class ClientTest < Test::Unit::TestCase
177
177
  assert_equal(0, c.pending_documents.length)
178
178
  end
179
179
 
180
- def test_query
181
- c = setup_client
180
+ def test_query_with_path
181
+ c = setup_client(:path => '/abcsolr')
182
182
 
183
183
  mock_query_builder = DelSolr::Client::QueryBuilder
184
- mock_query_builder.stubs(:request_string).returns('/solr/select?some_query') # mock the query builder
184
+ mock_query_builder.stubs(:request_string).returns('/select?some_query') # mock the query builder
185
+ DelSolr::Client::QueryBuilder.stubs(:new).returns(mock_query_builder)
186
+ c.connection.expects(:get).with("/abcsolr" + mock_query_builder.request_string).returns([nil, @@response_buffer]) # mock the connection
187
+ r = c.query('standard', :query => '123')
188
+ assert(r)
189
+ assert_equal([1,3,4,5,7,8,9,10,11,12], r.ids.sort)
190
+ assert(!r.from_cache?, 'should not be from cache')
191
+ end
192
+
193
+ def test_query_with_default_path
194
+ c = setup_client
195
+
196
+ mock_query_builder = DelSolr::Client::QueryBuilder
197
+ mock_query_builder.stubs(:request_string).returns('/select?some_query') # mock the query builder
185
198
  DelSolr::Client::QueryBuilder.stubs(:new).returns(mock_query_builder)
186
- c.connection.expects(:get).with(mock_query_builder.request_string).returns([nil, @@response_buffer]) # mock the connection
199
+ c.connection.expects(:get).with("/solr" + mock_query_builder.request_string).returns([nil, @@response_buffer]) # mock the connection
187
200
  r = c.query('standard', :query => '123')
188
201
  assert(r)
189
202
  assert_equal([1,3,4,5,7,8,9,10,11,12], r.ids.sort)
190
203
  assert(!r.from_cache?, 'should not be from cache')
191
204
  end
205
+
192
206
 
193
207
  def test_query_from_cache
194
208
  c = setup_client(:cache => TestCache.new)
195
209
 
196
210
  mock_query_builder = DelSolr::Client::QueryBuilder
197
- mock_query_builder.stubs(:request_string).returns('/solr/select?some_query') # mock the query builder
211
+ mock_query_builder.stubs(:request_string).returns('/select?some_query') # mock the query builder
198
212
  DelSolr::Client::QueryBuilder.stubs(:new).returns(mock_query_builder)
199
- c.connection.expects(:get).with(mock_query_builder.request_string).returns([nil, @@response_buffer]) # mock the connection
213
+ c.connection.expects(:get).with("/solr" + mock_query_builder.request_string).returns([nil, @@response_buffer]) # mock the connection
200
214
  r = c.query('standard', :query => '123', :enable_caching => true)
201
215
  assert(r)
202
216
  assert_equal([1,3,4,5,7,8,9,10,11,12], r.ids.sort)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben VandenBos
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  requirements: []
64
64
 
65
65
  rubyforge_project:
66
- rubygems_version: 1.3.5
66
+ rubygems_version: 1.3.4
67
67
  signing_key:
68
68
  specification_version: 3
69
69
  summary: DelSolr is a light weight ruby wrapper for solr. It's intention is to expose the full power of solr queries while keeping the interface as ruby-esque as possible.