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 +17 -1
- data/lib/rsolr-ext/doc.rb +4 -11
- data/lib/rsolr-ext/findable.rb +11 -6
- data/lib/rsolr-ext.rb +1 -1
- data/rsolr-ext.gemspec +1 -1
- metadata +1 -1
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
|
-
|
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(
|
59
|
-
|
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
|
data/lib/rsolr-ext/findable.rb
CHANGED
@@ -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
|
-
|
69
|
-
|
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
data/rsolr-ext.gemspec
CHANGED