mwmitchell-rsolr-ext 0.5.1 → 0.5.2

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.rdoc CHANGED
@@ -1,2 +1,36 @@
1
1
  =RSolr::Ext
2
- A set of helper methods/modules to assist in building Solr queries and handling responses when using the RSolr library.
2
+ A set of helper methods/modules to assist in building Solr queries and handling responses when using the RSolr library.
3
+
4
+ ==Request Example
5
+ std = RSolr::Ext::Request::Standard.new
6
+
7
+ solr_params = std.map(
8
+ :page=>2,
9
+ :per_page=>10,
10
+ :phrases=>{:name=>'This is a phrase'},
11
+ :filters=>['test', {:price=>(1..10)}],
12
+ :phrase_filters=>{:manu=>['Apple']},
13
+ :q=>'ipod',
14
+ :facets=>{:fields=>['cat', 'blah']}
15
+ )
16
+
17
+ rsolr = RSolr.connect
18
+
19
+ response = rsolr.select(solr_params)
20
+
21
+ ==Response Example
22
+ rsolr = RSolr.connect
23
+ raw_response = rsolr.select(:q=>'*:*)
24
+ r = RSolr::Ext::Response::Standard.new(raw_response)
25
+
26
+ r.response_header.params
27
+ r.response.docs
28
+ r.response.docs.previous_page
29
+
30
+ ===Doc Pagination
31
+ After creating a RSolr::Ext::Response object, pass-in the response.docs to the will_paginate view helper:
32
+ rsolr = RSolr.connect
33
+ raw_response = rsolr.select(:q=>'*:*)
34
+ @response = RSolr::Ext::Response::Standard.new(raw_response)
35
+ # in view:
36
+ <%= will_paginate @response.response.docs %>
data/lib/rsolr-ext.rb CHANGED
@@ -15,7 +15,7 @@ module RSolr
15
15
 
16
16
  module Ext
17
17
 
18
- VERSION = '0.5.1'
18
+ VERSION = '0.5.2'
19
19
 
20
20
  autoload :Request, 'rsolr-ext/request.rb'
21
21
  autoload :Response, 'rsolr-ext/response.rb'
data/rsolr-ext.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "rsolr-ext"
3
- s.version = "0.5.1"
3
+ s.version = "0.5.2"
4
4
  s.date = "2009-03-17"
5
5
  s.summary = "An extension lib for RSolr"
6
6
  s.email = "goodieboy@gmail.com"
@@ -31,6 +31,12 @@ Gem::Specification.new do |s|
31
31
  "README.rdoc",
32
32
  "rsolr-ext.gemspec"
33
33
  ]
34
- s.test_files = ['test/request_test.rb', 'test/response_test.rb', 'test/test_unit_test_case.rb', 'test/helper.rb']
34
+ s.test_files = [
35
+ 'test/hash_methodizer_test.rb',
36
+ 'test/request_test.rb',
37
+ 'test/response_test.rb',
38
+ 'test/test_unit_test_case.rb',
39
+ 'test/helper.rb'
40
+ ]
35
41
  s.extra_rdoc_files = %w(LICENSE README.rdoc)
36
42
  end
@@ -0,0 +1,53 @@
1
+ require 'test_unit_test_case'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr-ext')
3
+
4
+ class RSolrExtRequestTest < Test::Unit::TestCase
5
+
6
+ def testable_hash
7
+ {:name=>'Sam', :age=>90, :kids=>['Fred', 'Betty'], :favorites=>{:red=>1, :blue=>9}}
8
+ end
9
+
10
+ test 'the default behavior of a hash, after methodize!' do
11
+ my_hash = testable_hash
12
+
13
+ original_methods = my_hash.methods
14
+ key_count = my_hash.keys.size
15
+
16
+ RSolr::Ext::HashMethodizer.methodize!(my_hash)
17
+
18
+ assert_equal key_count, my_hash.keys.size
19
+
20
+ [:name, :age, :kids, :favorites].each do |k|
21
+ assert my_hash.keys.include?(k)
22
+ end
23
+
24
+ assert_equal 1, my_hash[:favorites][:red]
25
+ assert_equal 9, my_hash[:favorites][:blue]
26
+
27
+ assert_equal Hash, my_hash.class
28
+
29
+ # make sure that the difference in method size is the size of the keys in my_hash
30
+ assert_equal my_hash.methods.size - key_count, original_methods.size
31
+ end
32
+
33
+ test 'the method accessors on a modified hash' do
34
+
35
+ my_hash = testable_hash
36
+
37
+ assert_raise NoMethodError do
38
+ my_hash.favorites
39
+ end
40
+
41
+ RSolr::Ext::HashMethodizer.methodize!(my_hash)
42
+
43
+ assert_equal my_hash[:name], my_hash.name
44
+ assert_equal my_hash[:age], my_hash.age
45
+ assert_equal my_hash[:kids], my_hash.kids
46
+ assert_equal my_hash[:favorites], my_hash.favorites
47
+
48
+ assert_equal my_hash[:favorites][:blue], my_hash.favorites.blue
49
+ assert_equal my_hash[:favorites][:red], my_hash.favorites.red
50
+
51
+ end
52
+
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mwmitchell-rsolr-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mitchell
@@ -65,6 +65,7 @@ signing_key:
65
65
  specification_version: 2
66
66
  summary: An extension lib for RSolr
67
67
  test_files:
68
+ - test/hash_methodizer_test.rb
68
69
  - test/request_test.rb
69
70
  - test/response_test.rb
70
71
  - test/test_unit_test_case.rb