mwmitchell-rsolr 0.8.2 → 0.8.3
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/CHANGES.txt +9 -0
- data/README.rdoc +28 -13
- data/Rakefile +20 -0
- data/lib/rsolr/connection.rb +24 -16
- data/lib/rsolr.rb +8 -6
- metadata +1 -1
data/CHANGES.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
0.8.3 - April 3, 2009
|
2
|
+
RSolr::Connection
|
3
|
+
- removed the block functionality of send_request and related methods
|
4
|
+
- this was used to gain access to the raw adapter response
|
5
|
+
- added #adapter_response method to all response objects
|
6
|
+
- this is used to get access to the original adapter response:
|
7
|
+
response = rsolr.select(:q=>'test')
|
8
|
+
response.adapter_response[:status_code]
|
9
|
+
|
1
10
|
0.8.2 - March 24, 2009
|
2
11
|
Changed RSolr.connect method to accept one options hash argument
|
3
12
|
- This hash gets passed to the Connection object and the adapter
|
data/README.rdoc
CHANGED
@@ -13,10 +13,12 @@ http://groups.google.com/group/rsolr
|
|
13
13
|
require 'rubygems'
|
14
14
|
require 'rsolr'
|
15
15
|
rsolr = RSolr.connect
|
16
|
-
response = rsolr.select(:q=>'*:*') # sends a request to /solr/select?q=*:*
|
17
16
|
|
18
|
-
#
|
19
|
-
response = rsolr.
|
17
|
+
# sends a request to /select
|
18
|
+
response = rsolr.select(:q=>'*:*')
|
19
|
+
|
20
|
+
# send a request to a custom request handler; /catalog
|
21
|
+
response = rsolr.send_request('/catalog', :q=>'*:*')
|
20
22
|
|
21
23
|
To run tests:
|
22
24
|
|
@@ -46,12 +48,23 @@ Once you have a connection, you can execute queries, updates etc..
|
|
46
48
|
|
47
49
|
=== Querying
|
48
50
|
Use the #select method to send requests to the /select handler:
|
49
|
-
response = solr.select(
|
51
|
+
response = solr.select({
|
52
|
+
:q=>'washington',
|
53
|
+
:facet=>true,
|
54
|
+
'facet.limit'=>-1,
|
55
|
+
'facet.field'=>'cat',
|
56
|
+
'facet.field'=>'inStock',
|
57
|
+
:start=>0,
|
58
|
+
:rows=>10
|
59
|
+
})
|
50
60
|
|
51
61
|
|
52
62
|
=== Updating Solr
|
53
63
|
Updating is done using native Ruby structures. Hashes are used for single documents and arrays are used for a collection of documents (hashes). These structures get turned into simple XML "messages".
|
54
64
|
|
65
|
+
Raw XML
|
66
|
+
response = solr.update('</optimize>')
|
67
|
+
|
55
68
|
Single document
|
56
69
|
response = solr.add(:id=>1, :price=>1.00)
|
57
70
|
|
@@ -81,7 +94,7 @@ Delete by array of queries
|
|
81
94
|
response = solr.delete_by_query(['price:1.00', 'price:10.00'])
|
82
95
|
|
83
96
|
|
84
|
-
Commit &
|
97
|
+
Commit & optimize shortcuts
|
85
98
|
solr.commit
|
86
99
|
solr.optimize
|
87
100
|
|
@@ -89,19 +102,21 @@ Commit & Optimize
|
|
89
102
|
== Response Formats
|
90
103
|
The default response format is Ruby. When the :wt param is set to :ruby, the response is eval'd and wrapped up in a nice Mash (Hash) class. You can get a raw response by setting the :wt to "ruby" - notice, the string -- not a symbol. All other response formats are available as expected, :wt=>'xml' etc..
|
91
104
|
|
105
|
+
===Evaluated Ruby (default)
|
106
|
+
solr.select(:wt=>:ruby) # notice :ruby is a Symbol
|
107
|
+
===Raw Ruby
|
108
|
+
solr.select(:wt=>'ruby') # notice 'ruby' is a String
|
109
|
+
|
92
110
|
===XML:
|
93
111
|
solr.select(:wt=>:xml)
|
94
112
|
===JSON:
|
95
113
|
solr.select(:wt=>:json)
|
96
|
-
===Raw Ruby
|
97
|
-
solr.select(:wt=>'ruby')
|
98
114
|
|
99
|
-
You can access the original request context (path, params, url etc.) by
|
100
|
-
solr.select(:q=>'*:*')
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
end
|
115
|
+
You can access the original request context (path, params, url etc.) by calling the #adapter_response method:
|
116
|
+
response = solr.select(:q=>'*:*')
|
117
|
+
response.adapter_response[:status_code]
|
118
|
+
response.adapter_response[:body]
|
119
|
+
response.adapter_response[:url]
|
105
120
|
|
106
121
|
The adapter_response is a hash that contains the generated params, url, path, post data, headers etc., very useful for debugging and testing.
|
107
122
|
|
data/Rakefile
CHANGED
@@ -21,6 +21,26 @@ Rake::TestTask.new("test_units") { |t|
|
|
21
21
|
t.libs << "test"
|
22
22
|
}
|
23
23
|
|
24
|
+
|
25
|
+
desc 'Run specs' # this task runs each test in its own process
|
26
|
+
task :specs do
|
27
|
+
require 'rubygems'
|
28
|
+
require 'facets/more/filelist' unless defined?(FileList)
|
29
|
+
files = FileList["**/*_spec.rb"]
|
30
|
+
p files.to_a
|
31
|
+
files.each do |filename|
|
32
|
+
system "cd #{File.dirname(filename)} && ruby #{File.basename(filename)}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#desc "Run specs"
|
37
|
+
#Rake::TestTask.new("specs") { |t|
|
38
|
+
# t.pattern = 'spec/**/*_spec.rb'
|
39
|
+
# t.verbose = true
|
40
|
+
# t.warning = true
|
41
|
+
# t.libs += ["lib", "spec"]
|
42
|
+
#}
|
43
|
+
|
24
44
|
# Clean house
|
25
45
|
desc 'Clean up tmp files.'
|
26
46
|
task :clean do |t|
|
data/lib/rsolr/connection.rb
CHANGED
@@ -16,9 +16,9 @@ class RSolr::Connection
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# sends data to the update handler
|
19
|
-
# data can be a string of xml, or an object that returns xml from its #
|
20
|
-
def update(data, params={}
|
21
|
-
send_request('/update', map_params(params), data
|
19
|
+
# data can be a string of xml, or an object that returns xml from its #to_xml method
|
20
|
+
def update(data, params={})
|
21
|
+
send_request('/update', map_params(params), data)
|
22
22
|
end
|
23
23
|
|
24
24
|
# send request solr
|
@@ -27,16 +27,11 @@ class RSolr::Connection
|
|
27
27
|
# if :wt is something other than :ruby, the raw response body is used
|
28
28
|
# otherwise, a simple Hash is returned
|
29
29
|
# NOTE: to get raw ruby, use :wt=>'ruby' <- a string, not a symbol like :ruby
|
30
|
-
#
|
31
|
-
# use a block to get access to the adapter response:
|
32
|
-
# solr.send_request('/select', :q=>'blue') do |solr_response, adapter_response|
|
33
|
-
# raise 'Woops!' if adapter_response[:status] != 200
|
34
|
-
# solr_response[:response][:docs].each {|doc|}
|
35
|
-
# end
|
36
30
|
#
|
37
|
-
|
31
|
+
#
|
32
|
+
def send_request(path, params={}, data=nil)
|
38
33
|
response = @adapter.send_request(path, map_params(params), data)
|
39
|
-
adapt_response(response
|
34
|
+
adapt_response(response)
|
40
35
|
end
|
41
36
|
|
42
37
|
#
|
@@ -94,14 +89,27 @@ class RSolr::Connection
|
|
94
89
|
{:wt=>:ruby}.merge(params)
|
95
90
|
end
|
96
91
|
|
97
|
-
#
|
92
|
+
# "adapter_response" must be a hash with the following keys:
|
93
|
+
# :params - a sub hash of standard solr params
|
94
|
+
# : body - the raw response body from the solr server
|
95
|
+
# This method will evaluate the :body value if the params[:wt] == :ruby
|
96
|
+
# otherwise, the body is returned
|
97
|
+
# The return object has a special method attached called #adapter_response
|
98
|
+
# This method gives you access to the original response from the adapter,
|
99
|
+
# so you can access things like the actual :url sent to solr,
|
100
|
+
# the raw :body, original :params and original :data
|
98
101
|
def adapt_response(adapter_response)
|
102
|
+
data = adapter_response[:body]
|
103
|
+
# if the wt is :ruby, evaluate the ruby string response
|
99
104
|
if adapter_response[:params][:wt] == :ruby
|
100
|
-
data = Kernel.eval(
|
101
|
-
|
102
|
-
|
105
|
+
data = Kernel.eval(data).to_mash
|
106
|
+
end
|
107
|
+
# attach a method called #adapter_response that returns the original adapter response value
|
108
|
+
def data.adapter_response
|
109
|
+
@adapter_response
|
103
110
|
end
|
104
|
-
|
111
|
+
data.send(:instance_variable_set, '@adapter_response', adapter_response)
|
112
|
+
data
|
105
113
|
end
|
106
114
|
|
107
115
|
end
|
data/lib/rsolr.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# add this directory to the load path if it hasn't already been added
|
2
|
-
|
3
|
-
|
4
|
-
$: <<
|
5
|
-
|
6
|
-
|
2
|
+
|
3
|
+
if ! $:.include? File.dirname(__FILE__) or ! $:.include? File.expand_path(File.dirname(__FILE__))
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'core_ext'
|
8
|
+
require 'mash'
|
7
9
|
|
8
10
|
module RSolr
|
9
11
|
|
10
|
-
VERSION = '0.8.
|
12
|
+
VERSION = '0.8.3'
|
11
13
|
|
12
14
|
autoload :Message, 'rsolr/message'
|
13
15
|
autoload :Connection, 'rsolr/connection'
|