delsolr 0.0.4 → 0.0.5

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.
Files changed (3) hide show
  1. data/lib/delsolr.rb +10 -1
  2. data/test/test_client.rb +24 -0
  3. metadata +2 -2
@@ -35,7 +35,10 @@ module DelSolr
35
35
  # (optional) a cache instance (any object the supports get and set)
36
36
  #
37
37
  # [<b><tt>:shortcuts</tt></b>]
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]
38
+ # (optional) 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
+ #
40
+ # [<b><tt>:path</tt></b>]
41
+ # (optional) the path of the solr install (defaults to "/solr")
39
42
  def initialize(options = {})
40
43
  @configuration = DelSolr::Client::Configuration.new(options[:server], options[:port], options[:timeout], options[:path])
41
44
  @cache = options[:cache]
@@ -159,6 +162,12 @@ module DelSolr
159
162
  if body.blank? # cache miss (or wasn't enabled)
160
163
  header, body = connection.get(configuration.path + query_builder.request_string)
161
164
 
165
+ # We get UTF-8 from Solr back, make sure the string knows about it
166
+ # when running on Ruby >= 1.9
167
+ if body.respond_to?(:force_encoding)
168
+ body.force_encoding("UTF-8")
169
+ end
170
+
162
171
  # add to the cache if caching
163
172
  if enable_caching
164
173
  begin
@@ -221,6 +221,30 @@ class ClientTest < Test::Unit::TestCase
221
221
  assert_equal([1,3,4,5,7,8,9,10,11,12], r.ids.sort)
222
222
  assert(r.from_cache?, 'this one should be from the cache')
223
223
  end
224
+
225
+ if RUBY_VERSION.to_f >= 1.9
226
+ def test_query_encoding_ruby19_ut8
227
+ c = setup_client
228
+
229
+ mock_query_builder = DelSolr::Client::QueryBuilder
230
+ mock_query_builder.stubs(:request_string).returns('/select?some_query') # mock the query builder
231
+ DelSolr::Client::QueryBuilder.stubs(:new).returns(mock_query_builder)
232
+ c.connection.expects(:get).with("/solr" + mock_query_builder.request_string).returns([nil, @@response_buffer]) # mock the connection
233
+ r = c.query('standard', :query => '123')
234
+ assert(r)
235
+
236
+ ensure_encoding = lambda { |v|
237
+ case v
238
+ when String; assert_equal 'UTF-8', v.encoding.name
239
+ when Array; v.each(&ensure_encoding)
240
+ when Hash; (v.keys + v.values).each(&ensure_encoding)
241
+ end
242
+ }
243
+
244
+ ensure_encoding.call(r.raw_response)
245
+ end
246
+ end
247
+
224
248
 
225
249
  private
226
250
 
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.4
4
+ version: 0.0.5
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.4
66
+ rubygems_version: 1.3.5
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.