mwmitchell-rsolr 0.9.1 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.txt CHANGED
@@ -1,3 +1,23 @@
1
+ 0.9.5 - September 4, 2009
2
+ Removed Array #extract_options!
3
+ Removed the Connection #send_request method (now #request)
4
+ Removed the Connection #select method -- still works, but this now ends up calling Connection #method_missing
5
+ Removed HTTPClient::Connector
6
+ - HTTPClient now uses a method called #connect (like RSolr.connect)
7
+ - This method accepts 1 or 2 args, see the #connect method comments
8
+ Changed the way the HTTP client adapter is set. Now just pass in when connecting:
9
+ - RSolr.connect(:http, :adapter=>curb, :url=>'http://solr.com')
10
+ Moved Message::Builders to Message::Adapter
11
+ Made Connection a module and moved class methods to "Base" class
12
+ Made HTTPClient a module and moved class methods to "Base" class
13
+ Removed the "adapter.rb" files -- Adapter modules are defined in the parent module file.
14
+ Moved Message module/singleton functionality to Message::Builder class
15
+ XML message adapter API change: no longer a singleton, must instantiate Message::Builder
16
+ Made RSolr::Connection #message public -- can change the adapter as needed; connection.message.adapter = RSolr::Message::Adapter::LibXML.new
17
+ More tests for HTTPClient::Util
18
+ Simplified url/query building in HTTPClient::Util
19
+ Updated tests accordingly
20
+
1
21
  0.9.1 - July 22, 2009
2
22
  Added LibXml builder support (Thanks to Mat Brown - github.com/outoftime)
3
23
 
data/LICENSE CHANGED
@@ -10,58 +10,4 @@ Unless required by applicable law or agreed to in writing, software
10
10
  distributed under the License is distributed on an "AS IS" BASIS,
11
11
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  See the License for the specific language governing permissions and
13
- limitations under the License.
14
-
15
- ========================================================================
16
-
17
- For use of the lib/Mash/extlib code:
18
-
19
- ========================================================================
20
-
21
- Copyright (c) 2008 Sam Smoot.
22
-
23
- Permission is hereby granted, free of charge, to any person obtaining
24
- a copy of this software and associated documentation files (the
25
- "Software"), to deal in the Software without restriction, including
26
- without limitation the rights to use, copy, modify, merge, publish,
27
- distribute, sublicense, and/or sell copies of the Software, and to
28
- permit persons to whom the Software is furnished to do so, subject to
29
- the following conditions:
30
-
31
- The above copyright notice and this permission notice shall be
32
- included in all copies or substantial portions of the Software.
33
-
34
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
-
42
- ---
43
- ---
44
-
45
- Some portions of blank.rb and mash.rb are verbatim copies of software
46
- licensed under the MIT license. That license is included below:
47
-
48
- Copyright (c) 2005-2008 David Heinemeier Hansson
49
-
50
- Permission is hereby granted, free of charge, to any person obtaining
51
- a copy of this software and associated documentation files (the
52
- "Software"), to deal in the Software without restriction, including
53
- without limitation the rights to use, copy, modify, merge, publish,
54
- distribute, sublicense, and/or sell copies of the Software, and to
55
- permit persons to whom the Software is furnished to do so, subject to
56
- the following conditions:
57
-
58
- The above copyright notice and this permission notice shall be
59
- included in all copies or substantial portions of the Software.
60
-
61
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
62
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
64
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
65
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
66
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
67
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ limitations under the License.
data/README.rdoc CHANGED
@@ -1,83 +1,79 @@
1
1
  =RSolr
2
2
 
3
- A Ruby client for Apache Solr. Has transparent JRuby support by using "org.apache.solr.servlet.DirectSolrConnection" as a connection adapter.
3
+ A Ruby client for Apache Solr. RSolr has been developed to be simple and extendable. It features transparent JRuby DirectSolrConnection support and a simple Hash-in, Hash-out architecture.
4
4
 
5
- ==Installation:
5
+ == Installation:
6
6
  gem sources -a http://gems.github.com
7
7
  sudo gem install mwmitchell-rsolr
8
8
 
9
- ==Community
10
- http://groups.google.com/group/rsolr
9
+ ==Related Resources & Projects
10
+ * {Solr}[http://lucene.apache.org/solr/]
11
+ * {RSolr Google Group}[http://groups.google.com/group/rsolr]
12
+ * {RSolr::Ext}[http://github.com/mwmitchell/rsolr-ext] -- an extension kit for RSolr
13
+ * {Sunspot}[http://github.com/outoftime/sunspot] -- an awesome Solr DSL, built with RSolr
14
+ * {Blacklight}[http://blacklightopac.org] -- a next generation Library OPAC, built with RSolr
15
+ * {solr-ruby}[http://wiki.apache.org/solr/solr-ruby] -- the original Solr Ruby Gem
11
16
 
12
- ==Related Projects
13
- http://github.com/mwmitchell/rsolr-ext
14
- http://wiki.apache.org/solr/solr-ruby
15
-
16
- ==Simple usage:
17
+ == Simple usage:
17
18
  require 'rubygems'
18
19
  require 'rsolr'
19
- rsolr = RSolr.connect
20
+ solr = RSolr.connect :url=>'http://solrserver.com'
20
21
 
21
- # sends a request to /select
22
- response = rsolr.select(:q=>'*:*')
22
+ # send a request to /select
23
+ response = rsolr.select :q=>'*:*'
23
24
 
24
25
  # send a request to a custom request handler; /catalog
25
- response = rsolr.send_request('/catalog', :q=>'*:*')
26
+ response = rsolr.request '/catalog', :q=>'*:*'
26
27
 
27
- # alternative to above (uses Ruby's method_missing):
28
+ # alternative to above:
28
29
  response = rsolr.catalog :q=>'*:*'
29
-
30
- To run tests:
31
-
32
- Copy an Apache Solr 1.3.0/or later (http://apache.seekmeup.com/lucene/solr/1.3.0/) distribution into this directory and rename to "apache-solr"
33
- Start Solr HTTP: rake rsolr:start_test_server
34
- MRI Ruby: rake
35
- JRuby: jruby -S rake
36
-
37
- To get a connection in MRI/standard Ruby:
38
30
 
39
- solr = RSolr.connect
40
-
41
- To change the Solr HTTP host:
31
+ To use a DirectSolrConnection (no http) in JRuby:
42
32
 
43
- solr = RSolr.connect(:url=>'http://solrserver.com')
44
-
45
- To get a direct connection (no http) in jRuby using DirectSolrConnection:
46
-
47
- solr = RSolr.connect({
48
- :adapter=>:direct,
33
+ solr = RSolr.connect(:direct,
49
34
  :home_dir=>'/path/to/solr/home',
50
35
  :dist_dir=>'/path/to/solr/distribution'
51
- })
36
+ )
52
37
 
53
- == Requests
54
- Once you have a connection, you can execute queries, updates etc..
38
+ For more information about DirecSolrConnection, see the {API}[http://lucene.apache.org/solr/api/org/apache/solr/servlet/DirectSolrConnection.html].
55
39
 
56
- === Querying
40
+
41
+ == Querying
57
42
  Use the #select method to send requests to the /select handler:
58
43
  response = solr.select({
59
44
  :q=>'washington',
60
45
  :start=>0,
61
46
  :rows=>10
62
47
  })
48
+
49
+ The params sent into the method are sent to Solr as-is. The one exception is if a value is an array. When an array is used, multiple parameters are generated for the Solr query. Example:
63
50
 
64
- Use the #send_request method to set a custom request handler path:
65
- response = solr.send_request('/documents', {:q=>'test'})
51
+ solr.select :q=>'roses', :fq=>['red', 'violet']
66
52
 
53
+ The above statement generates this Solr query:
54
+
55
+ ?q=roses&fq=red&fq=violet
56
+
57
+ Use the #request method for a custom request handler path:
58
+ response = solr.request '/documents', :q=>'test'
59
+
60
+ A shortcut for the above example:
61
+ response = solr.documents :q=>'test'
67
62
 
68
- === Updating Solr
69
- Updating can be 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". Raw XML can also be used of course.
63
+
64
+ == Updating Solr
65
+ Updating can be 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". Raw XML strings can also be used.
70
66
 
71
67
  Raw XML via #update
72
- solr.update('</commit>')
73
- solr.update('</optimize>')
68
+ solr.update '</commit>'
69
+ solr.update '</optimize>'
74
70
 
75
71
  Single document via #add
76
- solr.add(:id=>1, :price=>1.00)
72
+ solr.add :id=>1, :price=>1.00
77
73
 
78
74
  Multiple documents via #add
79
75
  documents = [{:id=>1, :price=>1.00}, {:id=>2, :price=>10.50}]
80
- solr.add(documents)
76
+ solr.add documents
81
77
 
82
78
  When adding, you can also supply "add" xml element attributes and/or a block for manipulating other "add" related elements (docs and fields) when using the #add method:
83
79
 
@@ -91,23 +87,27 @@ When adding, you can also supply "add" xml element attributes and/or a block for
91
87
  end
92
88
 
93
89
  Delete by id
94
- solr.delete_by_id(1)
90
+ solr.delete_by_id 1
95
91
  or an array of ids
96
- solr.delete_by_id([1, 2, 3, 4])
92
+ solr.delete_by_id [1, 2, 3, 4]
97
93
 
98
94
  Delete by query:
99
- solr.delete_by_query('price:1.00')
95
+ solr.delete_by_query 'price:1.00'
100
96
  Delete by array of queries
101
- solr.delete_by_query(['price:1.00', 'price:10.00'])
102
-
97
+ solr.delete_by_query ['price:1.00', 'price:10.00']
103
98
 
104
99
  Commit & optimize shortcuts
105
100
  solr.commit
106
101
  solr.optimize
107
102
 
103
+ ===XML Builders for RSolr
104
+ As of version 0.9.1, RSolr can use LibXml to create the update messages sent to solr. To switch from Builder to LibXml, set the RSolr::Message.builder like:
105
+ solr = RSolr.connect
106
+ solr.message.adapter = RSolr::Message::Adapter::Libxml.new
107
+
108
108
 
109
109
  == Response Formats
110
- 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..
110
+ The default response format is Ruby. When the :wt param is set to :ruby, the response is eval'd resulting in a Hash. You can get a raw response by setting the :wt to "ruby" - notice, the string -- not a symbol. RSolr will eval the Ruby string ONLY if the :wt value is :ruby. All other response formats are available as expected, :wt=>'xml' etc..
111
111
 
112
112
  ===Evaluated Ruby (default)
113
113
  solr.select(:wt=>:ruby) # notice :ruby is a Symbol
@@ -120,7 +120,7 @@ The default response format is Ruby. When the :wt param is set to :ruby, the res
120
120
  solr.select(:wt=>:json)
121
121
 
122
122
  You can access the original request context (path, params, url etc.) by calling the #adapter_response method:
123
- response = solr.select(:q=>'*:*')
123
+ response = solr.select :q=>'*:*'
124
124
  response.adapter_response[:status_code]
125
125
  response.adapter_response[:body]
126
126
  response.adapter_response[:url]
@@ -129,20 +129,20 @@ The adapter_response is a hash that contains the generated params, url, path, po
129
129
 
130
130
 
131
131
  == HTTP Client Adapter
132
- You can specify the http client adapter to use by setting solr.adapter.connector.adapter_name to one of:
132
+ You can specify the http client adapter:
133
133
  :net_http uses the standard Net::HTTP library
134
- :curb uses the Ruby "curl" bindings
134
+ :curb uses the C based "curl" library
135
135
 
136
- Example:
137
-
138
- solr.adapter.connector.adapter_name = :curb
136
+ NOTE: The Net::Http is the default adapter.
139
137
 
140
- Example of using the HTTP client only:
138
+ Example:
141
139
 
142
- hclient = RSolr::HTTPClient::Connector.new(:curb).connect(url)
143
- hclient = RSolr::HTTPClient::Connector.new(:net_http).connect(url)
144
- hclient.get('/')
140
+ RSolr.connect(:adapter => :curb)
141
+ RSolr.connect(:adapter => :net_http)
145
142
 
146
- After reading this http://apocryph.org/2008/11/09/more_indepth_analysis_ruby_http_client_performance - I would recommend using the :curb adapter. NOTE: You can't use the :curb adapter under jRuby. To install curb:
143
+ Intereseting read about Ruby's Net::HTTP library:
144
+ http://apocryph.org/2008/11/09/more_indepth_analysis_ruby_http_client_performance
147
145
 
146
+ NOTE: You can't use the :curb adapter under jRuby. To install curb:
147
+
148
148
  sudo gem install curb
data/Rakefile CHANGED
@@ -29,24 +29,24 @@ Spec::Rake::SpecTask.new('spec') do |t|
29
29
  t.libs += ["lib", "spec"]
30
30
  end
31
31
 
32
- #desc 'Run specs' # this task runs each test in its own process
33
- #task :specs do
34
- # require 'rubygems'
35
- # require 'facets/more/filelist' unless defined?(FileList)
36
- # files = FileList["**/*_spec.rb"]
37
- # p files.to_a
38
- # files.each do |filename|
39
- # system "cd #{File.dirname(filename)} && ruby #{File.basename(filename)}"
40
- # end
41
- #end
32
+ desc 'Run specs' # this task runs each test in its own process
33
+ task :specs do
34
+ require 'rubygems'
35
+ require 'facets/more/filelist' unless defined?(FileList)
36
+ files = FileList["**/*_spec.rb"]
37
+ p files.to_a
38
+ files.each do |filename|
39
+ system "cd #{File.dirname(filename)} && ruby #{File.basename(filename)}"
40
+ end
41
+ end
42
42
 
43
- #desc "Run specs"
44
- #Rake::TestTask.new("specs") { |t|
45
- # t.pattern = 'spec/**/*_spec.rb'
46
- # t.verbose = true
47
- # t.warning = true
48
- # t.libs += ["lib", "spec"]
49
- #}
43
+ desc "Run specs"
44
+ Rake::TestTask.new("specs") { |t|
45
+ t.pattern = 'spec/**/*_spec.rb'
46
+ t.verbose = true
47
+ t.warning = true
48
+ t.libs += ["lib", "spec"]
49
+ }
50
50
 
51
51
  # Clean house
52
52
  desc 'Clean up tmp files.'
data/examples/direct.rb CHANGED
@@ -5,13 +5,15 @@ base = File.expand_path( File.dirname(__FILE__) )
5
5
  dist = File.join(base, '..', 'apache-solr')
6
6
  home = File.join(dist, 'example', 'solr')
7
7
 
8
- solr = RSolr.connect(:adapter=>:direct, :home_dir=>home, :dist_dir=>dist)
8
+ solr = RSolr.connect(:direct, :home_dir=>home, :dist_dir=>dist)
9
9
 
10
10
  Dir['../apache-solr/example/exampledocs/*.xml'].each do |xml_file|
11
11
  puts "Updating with #{xml_file}"
12
12
  solr.update File.read(xml_file)
13
13
  end
14
14
 
15
+ solr.commit
16
+
15
17
  puts
16
18
 
17
19
  response = solr.select :q=>'ipod', :fq=>'price:[0 TO 50]', :rows=>2, :start=>0
data/examples/http.rb CHANGED
@@ -1,22 +1,24 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'lib', 'rsolr')
2
2
 
3
- solr = RSolr.connect
4
-
5
- # switch out the http adapter from curb to net_http (just for an example)
6
- solr.adapter.connector.adapter_name = :curb
3
+ # switch out the http adapter from net_http to curb
4
+ solr = RSolr.connect :adapter=>:curb
7
5
 
8
6
  Dir['../apache-solr/example/exampledocs/*.xml'].each do |xml_file|
9
7
  puts "Updating with #{xml_file}"
10
8
  solr.update File.read(xml_file)
11
9
  end
12
10
 
11
+ solr.commit
12
+
13
13
  puts
14
14
 
15
- response = solr.select(:q=>'ipod', :fq=>'price:[0 TO 50]', :rows=>2, :start=>0)
15
+ response = solr.select(:q=>'ipod', :fq=>['price:[0 TO 50]'], :rows=>2, :start=>0)
16
16
 
17
17
  puts "URL : #{response.adapter_response[:url]} -> #{response.adapter_response[:status_code]}"
18
18
 
19
- solr_response['response']['docs'].each do |doc|
19
+ puts
20
+
21
+ response['response']['docs'].each do |doc|
20
22
  puts doc['timestamp']
21
23
  end
22
24
 
@@ -5,7 +5,7 @@ require 'java'
5
5
  #
6
6
  # Connection for JRuby + DirectSolrConnection
7
7
  #
8
- class RSolr::Adapter::Direct
8
+ class RSolr::Connection::Adapter::Direct
9
9
 
10
10
  include RSolr::HTTPClient::Util
11
11
 
@@ -52,8 +52,9 @@ class RSolr::Adapter::Direct
52
52
  end
53
53
 
54
54
  # send a request to the connection
55
+ # request '/select', :q=>'something'
55
56
  # request '/update', :wt=>:xml, '</commit>'
56
- def send_request(path, params={}, data=nil)
57
+ def request(path, params={}, data=nil)
57
58
  data = data.to_xml if data.respond_to?(:to_xml)
58
59
  url = build_url(path, params)
59
60
  begin
@@ -1,25 +1,24 @@
1
1
  #
2
2
  # Connection for standard HTTP Solr server
3
3
  #
4
- class RSolr::Adapter::HTTP
4
+ class RSolr::Connection::Adapter::HTTP
5
5
 
6
- attr_reader :opts, :connector, :connection
6
+ attr_reader :opts
7
7
 
8
8
  # opts can have:
9
9
  # :url => 'http://localhost:8080/solr'
10
10
  def initialize(opts={}, &block)
11
- opts[:url]||='http://127.0.0.1:8983/solr'
11
+ opts[:url] ||= 'http://127.0.0.1:8983/solr'
12
12
  @opts = opts
13
- @connector = RSolr::HTTPClient::Connector.new
14
13
  end
15
14
 
16
15
  def connection
17
- @connection ||= @connector.connect(@opts[:url])
16
+ @connection ||= RSolr::HTTPClient.connect(@opts)
18
17
  end
19
18
 
20
19
  # send a request to the connection
21
20
  # request '/update', :wt=>:xml, '</commit>'
22
- def send_request(path, params={}, data=nil)
21
+ def request(path, params={}, data=nil)
23
22
  data = data.to_xml if data.respond_to?(:to_xml)
24
23
  if data
25
24
  http_context = connection.post(path, data, params, post_headers)
@@ -1,124 +1,125 @@
1
- class RSolr::Connection
1
+ module RSolr::Connection
2
2
 
3
- attr_reader :adapter, :opts
4
-
5
- # "adapter" is instance of:
6
- # RSolr::Adapter::HTTP
7
- # RSolr::Adapter::Direct (jRuby only)
8
- def initialize(adapter, opts={})
9
- @adapter = adapter
10
- @opts = opts
11
- end
12
-
13
- # Send a request to a request handler using the method name.
14
- # This does not handle data, only selects
15
- def method_missing(method_name, params)
16
- send_request("/#{method_name}", map_params(params))
17
- end
18
-
19
- # send a request to the "select" handler
20
- def select(params)
21
- send_request('/select', map_params(params))
22
- end
23
-
24
- # sends data to the update handler
25
- # data can be a string of xml, or an object that returns xml from its #to_xml method
26
- def update(data, params={})
27
- send_request('/update', map_params(params), data)
3
+ module Adapter
4
+ autoload :Direct, 'rsolr/connection/adapter/direct'
5
+ autoload :HTTP, 'rsolr/connection/adapter/http'
28
6
  end
29
7
 
30
- # send request solr
31
- # params is hash with valid solr request params (:q, :fl, :qf etc..)
32
- # if params[:wt] is not set, the default is :ruby
33
- # if :wt is something other than :ruby, the raw response body is used
34
- # otherwise, a simple Hash is returned
35
- # NOTE: to get raw ruby, use :wt=>'ruby' <- a string, not a symbol like :ruby
36
- #
37
- #
38
- def send_request(path, params={}, data=nil)
39
- response = @adapter.send_request(path, map_params(params), data)
40
- adapt_response(response)
41
- end
42
-
43
- # allow #request to be used like send_request
44
- alias_method :request, :send_request
8
+ class Base
9
+
10
+ attr_reader :adapter
11
+
12
+ # "adapter" is instance of:
13
+ # RSolr::Adapter::HTTP
14
+ # RSolr::Adapter::Direct (jRuby only)
15
+ # or any other class that uses the connection "interface"
16
+ def initialize(adapter)
17
+ @adapter = adapter
18
+ end
45
19
 
46
- #
47
- # single record:
48
- # solr.update(:id=>1, :name=>'one')
49
- #
50
- # update using an array
51
- # solr.update([{:id=>1, :name=>'one'}, {:id=>2, :name=>'two'}])
52
- #
53
- def add(doc, &block)
54
- update message.add(doc, &block)
55
- end
20
+ # Send a request to a request handler using the method name.
21
+ # This does not handle data/POSTs, only GET requests.
22
+ def method_missing(method_name, params, &blk)
23
+ request("/#{method_name}", map_params(params))
24
+ end
56
25
 
57
- # send </commit>
58
- def commit
59
- update message.commit
60
- end
26
+ # sends data to the update handler
27
+ # data can be a string of xml, or an object that returns xml from its #to_xml method
28
+ def update(data, params={})
29
+ request('/update', map_params(params), data)
30
+ end
61
31
 
62
- # send </optimize>
63
- def optimize
64
- update message.optimize
65
- end
32
+ # send request solr
33
+ # params is hash with valid solr request params (:q, :fl, :qf etc..)
34
+ # if params[:wt] is not set, the default is :ruby
35
+ # if :wt is something other than :ruby, the raw response body is used
36
+ # otherwise, a simple Hash is returned
37
+ # NOTE: to get raw ruby, use :wt=>'ruby' <- a string, not a symbol like :ruby
38
+ #
39
+ #
40
+ def request(path, params={}, data=nil)
41
+ response = @adapter.request(path, map_params(params), data)
42
+ adapt_response(response)
43
+ end
66
44
 
67
- # send </rollback>
68
- # NOTE: solr 1.4 only
69
- def rollback
70
- update message.rollback
71
- end
45
+ #
46
+ # single record:
47
+ # solr.update(:id=>1, :name=>'one')
48
+ #
49
+ # update using an array
50
+ # solr.update([{:id=>1, :name=>'one'}, {:id=>2, :name=>'two'}])
51
+ #
52
+ def add(doc, &block)
53
+ update message.add(doc, &block)
54
+ end
72
55
 
73
- # Delete one or many documents by id
74
- # solr.delete_by_id 10
75
- # solr.delete_by_id([12, 41, 199])
76
- def delete_by_id(id)
77
- update message.delete_by_id(id)
78
- end
56
+ # send </commit>
57
+ def commit
58
+ update message.commit
59
+ end
79
60
 
80
- # delete one or many documents by query
81
- # solr.delete_by_query 'available:0'
82
- # solr.delete_by_query ['quantity:0', 'manu:"FQ"']
83
- def delete_by_query(query)
84
- update message.delete_by_query(query)
85
- end
61
+ # send </optimize>
62
+ def optimize
63
+ update message.optimize
64
+ end
86
65
 
87
- protected
66
+ # send </rollback>
67
+ # NOTE: solr 1.4 only
68
+ def rollback
69
+ update message.rollback
70
+ end
88
71
 
89
- # shortcut to solr::message
90
- def message
91
- RSolr::Message
92
- end
72
+ # Delete one or many documents by id
73
+ # solr.delete_by_id 10
74
+ # solr.delete_by_id([12, 41, 199])
75
+ def delete_by_id(id)
76
+ update message.delete_by_id(id)
77
+ end
93
78
 
94
- # sets default params etc.. - could be used as a mapping hook
95
- # type of request should be passed in here? -> map_params(:query, {})
96
- def map_params(params)
97
- params||={}
98
- {:wt=>:ruby}.merge(params)
99
- end
79
+ # delete one or many documents by query
80
+ # solr.delete_by_query 'available:0'
81
+ # solr.delete_by_query ['quantity:0', 'manu:"FQ"']
82
+ def delete_by_query(query)
83
+ update message.delete_by_query(query)
84
+ end
85
+
86
+ # shortcut to RSolr::Message::Builder
87
+ def message
88
+ @message ||= RSolr::Message::Builder.new
89
+ end
90
+
91
+ protected
92
+
93
+ # sets default params etc.. - could be used as a mapping hook
94
+ # type of request should be passed in here? -> map_params(:query, {})
95
+ def map_params(params)
96
+ params||={}
97
+ {:wt=>:ruby}.merge(params)
98
+ end
100
99
 
101
- # "adapter_response" must be a hash with the following keys:
102
- # :params - a sub hash of standard solr params
103
- # : body - the raw response body from the solr server
104
- # This method will evaluate the :body value if the params[:wt] == :ruby
105
- # otherwise, the body is returned
106
- # The return object has a special method attached called #adapter_response
107
- # This method gives you access to the original response from the adapter,
108
- # so you can access things like the actual :url sent to solr,
109
- # the raw :body, original :params and original :data
110
- def adapt_response(adapter_response)
111
- data = adapter_response[:body]
112
- # if the wt is :ruby, evaluate the ruby string response
113
- if adapter_response[:params][:wt] == :ruby
114
- data = Kernel.eval(data)
100
+ # "adapter_response" must be a hash with the following keys:
101
+ # :params - a sub hash of standard solr params
102
+ # : body - the raw response body from the solr server
103
+ # This method will evaluate the :body value if the params[:wt] == :ruby
104
+ # otherwise, the body is returned
105
+ # The return object has a special method attached called #adapter_response
106
+ # This method gives you access to the original response from the adapter,
107
+ # so you can access things like the actual :url sent to solr,
108
+ # the raw :body, original :params and original :data
109
+ def adapt_response(adapter_response)
110
+ data = adapter_response[:body]
111
+ # if the wt is :ruby, evaluate the ruby string response
112
+ if adapter_response[:params][:wt] == :ruby
113
+ data = Kernel.eval(data)
114
+ end
115
115
  # attach a method called #adapter_response that returns the original adapter response value
116
116
  def data.adapter_response
117
117
  @adapter_response
118
118
  end
119
119
  data.send(:instance_variable_set, '@adapter_response', adapter_response)
120
+ data
120
121
  end
121
- data
122
+
122
123
  end
123
124
 
124
125
  end
@@ -8,8 +8,8 @@ class RSolr::HTTPClient::Adapter::Curb
8
8
  attr :uri
9
9
  attr :connection
10
10
 
11
- def initialize(url)
12
- @uri = URI.parse(url)
11
+ def initialize(opts={})
12
+ @uri = URI.parse(opts[:url])
13
13
  @connection = ::Curl::Easy.new
14
14
  end
15
15