mwmitchell-rsolr-ext 0.7.5 → 0.7.6

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
@@ -59,4 +59,20 @@ The #find method provides a convenient way to search solr. Here are some example
59
59
  books_about_jefferson = solr.find 'jefferson', :phrase_filters=>{:type=>'book'}
60
60
 
61
61
  # q=something -- the entire response
62
- solr_response = solr.find {:q=>'something'}, :include_response=>true
62
+ solr_response = solr.find {:q=>'something'}, :include_response=>true
63
+
64
+ ===The Doc Module
65
+ You can create your own "models" using RSolr::Ext::Doc
66
+ class Book
67
+ include RSolr::Ext::Doc
68
+ @default_params = {:fq=>'object_type:"book"', :rows=>10}
69
+
70
+ def self.find_by_author(author)
71
+ find(:phrase_filters=>{:author=>author})
72
+ end
73
+ end
74
+
75
+ all_books = Book.find('*:*')
76
+ hawk_books = Book.find_by_author('hawk')
77
+
78
+ If you wanna paginate, just throw the collection into the WillPaginate view helper.
data/lib/rsolr-ext/doc.rb CHANGED
@@ -52,19 +52,12 @@ module RSolr::Ext::Doc
52
52
  end
53
53
 
54
54
  def find(*args)
55
- call_finder_method(:find, *args)
55
+ mode, solr_params, opts = connection.send(:extract_find_opts!, *args)
56
+ connection.find(*[mode, default_params.merge(solr_params), opts]) { |doc| self.new(doc) }
56
57
  end
57
58
 
58
- def find_by_id(*args)
59
- call_finder_method(:find_by_id, *args)
60
- end
61
-
62
- protected
63
-
64
- def call_finder_method(method_name, *args)
65
- mode, params, opts = connection.send(:extract_find_opts!, *args)
66
- params.merge!(default_params)
67
- connection.send(method_name, *[mode, params, opts]) { |doc| self.new(doc) }
59
+ def find_by_id(id, solr_params={}, opts={})
60
+ connection.find_by_id(id, default_params.merge(solr_params), opts) { |doc| self.new(doc) }
68
61
  end
69
62
 
70
63
  end
@@ -34,6 +34,10 @@ module RSolr::Ext::Findable
34
34
  def find(*args, &blk)
35
35
  mode, solr_params, opts = extract_find_opts!(*args)
36
36
 
37
+ unless solr_params.respond_to?(:each_pair)
38
+ solr_params = {:q=>solr_params}
39
+ end
40
+
37
41
  opts[:include_response] = false unless opts.key?(:include_response)
38
42
 
39
43
  solr_params[:rows] = 1 if mode == :first
@@ -64,9 +68,14 @@ module RSolr::Ext::Findable
64
68
  end
65
69
 
66
70
  # find_by_id(10, :handler=>'catalog')
71
+ # find_by_id(:id=>10)
67
72
  def find_by_id(id, solr_params={}, opts={}, &blk)
68
- solr_params[:phrases] ||= {}
69
- solr_params[:phrases][:id] = id
73
+ if id.respond_to?(:each_pair)
74
+ solr_params = id
75
+ else
76
+ solr_params[:phrases] ||= {}
77
+ solr_params[:phrases][:id] = id
78
+ end
70
79
  self.find(:first, solr_params, opts, &blk)
71
80
  end
72
81
 
@@ -81,10 +90,6 @@ module RSolr::Ext::Findable
81
90
  end
82
91
  # extract solr params
83
92
  solr_params = args.shift || {}
84
- # create a hash if a string was passed in...
85
- unless solr_params.respond_to?(:each_pair)
86
- solr_params = {:q=>solr_params}
87
- end
88
93
  # extract options
89
94
  opts = args.shift || {}
90
95
  [mode, solr_params, opts]
data/lib/rsolr-ext.rb CHANGED
@@ -23,7 +23,7 @@ module RSolr
23
23
 
24
24
  module Ext
25
25
 
26
- VERSION = '0.7.5'
26
+ VERSION = '0.7.6'
27
27
 
28
28
  autoload :Request, 'rsolr-ext/request.rb'
29
29
  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.7.5"
3
+ s.version = "0.7.6"
4
4
  s.date = "2009-05-04"
5
5
  s.summary = "An extension lib for RSolr"
6
6
  s.email = "goodieboy@gmail.com"
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.7.5
4
+ version: 0.7.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Mitchell