Class: RSolr::Client
- Inherits:
-
Object
- Object
- RSolr::Client
- Defined in:
- lib/rsolr/client.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#add(doc, &block) ⇒ Object
single record: solr.update(:id=>1, :name=>‘one’).
-
#commit ⇒ Object
send </commit>.
-
#delete_by_id(id) ⇒ Object
Delete one or many documents by id solr.delete_by_id 10 solr.delete_by_id([12, 41, 199]).
-
#delete_by_query(query) ⇒ Object
delete one or many documents by query solr.delete_by_query ‘available:0’ solr.delete_by_query [‘quantity:0’, ‘manu:“FQ”’].
-
#initialize(connection) ⇒ Client
constructor
“connection” is instance of: RSolr::Adapter::HTTP RSolr::Adapter::Direct (jRuby only) or any other class that uses the connection “interface”.
-
#message(*opts) ⇒ Object
shortcut to RSolr::Message::Generator.
-
#method_missing(method_name, *args, &blk) ⇒ Object
Send a request to a request handler using the method name.
-
#optimize ⇒ Object
send </optimize>.
-
#request(path, params = {}, *extra) ⇒ Object
send request solr params is hash with valid solr request params (:q, :fl, :qf etc..) if params is not set, the default is :ruby if :wt is something other than :ruby, the raw response body is used otherwise, a simple Hash is returned NOTE: to get raw ruby, use :wt=>‘ruby’ <- a string, not a symbol like :ruby.
-
#rollback ⇒ Object
send </rollback> NOTE: solr 1.4 only.
-
#update(data, params = {}) ⇒ Object
sends data to the update handler data can be a string of xml, or an object that returns xml from its #to_xml method.
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &blk) ⇒ Object
Send a request to a request handler using the method name. Also proxies to the #paginate method if the method starts with “paginate_”
15 16 17 |
# File 'lib/rsolr/client.rb', line 15 def method_missing(method_name, *args, &blk) request("/#{method_name}", *args, &blk) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
3 4 5 |
# File 'lib/rsolr/client.rb', line 3 def connection @connection end |
Instance Method Details
#add(doc, &block) ⇒ Object
single record: solr.update(:id=>1, :name=>‘one’)
update using an array solr.update([:name=>‘one’, :name=>‘two’])
45 46 47 |
# File 'lib/rsolr/client.rb', line 45 def add(doc, &block) update .add(doc, &block) end |
#commit ⇒ Object
send </commit>
50 51 52 |
# File 'lib/rsolr/client.rb', line 50 def commit update .commit end |
#delete_by_id(id) ⇒ Object
Delete one or many documents by id
solr.delete_by_id 10
solr.delete_by_id([12, 41, 199])
68 69 70 |
# File 'lib/rsolr/client.rb', line 68 def delete_by_id(id) update .delete_by_id(id) end |
#delete_by_query(query) ⇒ Object
delete one or many documents by query
solr.delete_by_query 'available:0'
solr.delete_by_query ['quantity:0', 'manu:"FQ"']
75 76 77 |
# File 'lib/rsolr/client.rb', line 75 def delete_by_query(query) update .delete_by_query(query) end |
#message(*opts) ⇒ Object
shortcut to RSolr::Message::Generator
80 81 82 |
# File 'lib/rsolr/client.rb', line 80 def *opts @message ||= RSolr::Message::Generator.new end |
#optimize ⇒ Object
send </optimize>
55 56 57 |
# File 'lib/rsolr/client.rb', line 55 def optimize update .optimize end |
#request(path, params = {}, *extra) ⇒ Object
send request solr params is hash with valid solr request params (:q, :fl, :qf etc..)
if params[:wt] is not set, the default is :ruby
if :wt is something other than :ruby, the raw response body is used
otherwise, a simple Hash is returned
NOTE: to get raw ruby, use :wt=>'ruby' <- a string, not a symbol like :ruby
33 34 35 36 |
# File 'lib/rsolr/client.rb', line 33 def request(path, params={}, *extra) response = @connection.request(path, map_params(params), *extra) adapt_response(response) end |
#rollback ⇒ Object
send </rollback> NOTE: solr 1.4 only
61 62 63 |
# File 'lib/rsolr/client.rb', line 61 def rollback update .rollback end |
#update(data, params = {}) ⇒ Object
sends data to the update handler data can be a string of xml, or an object that returns xml from its #to_xml method
21 22 23 |
# File 'lib/rsolr/client.rb', line 21 def update(data, params={}) request '/update', params, data end |