Class: RSolr::Connection::Base
- Inherits:
-
Object
- Object
- RSolr::Connection::Base
- Defined in:
- lib/rsolr/connection.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
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(adapter) ⇒ Base
constructor
“adapter” is instance of: RSolr::Adapter::HTTP RSolr::Adapter::Direct (jRuby only) or any other class that uses the connection “interface”.
-
#message ⇒ Object
shortcut to RSolr::Message::Builder.
-
#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.
21 22 23 |
# File 'lib/rsolr/connection.rb', line 21 def method_missing(method_name, *args, &blk) request("/#{method_name}", *args, &blk) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
10 11 12 |
# File 'lib/rsolr/connection.rb', line 10 def adapter @adapter 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’])
51 52 53 |
# File 'lib/rsolr/connection.rb', line 51 def add(doc, &block) update .add(doc, &block) end |
#commit ⇒ Object
send </commit>
56 57 58 |
# File 'lib/rsolr/connection.rb', line 56 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])
74 75 76 |
# File 'lib/rsolr/connection.rb', line 74 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"']
81 82 83 |
# File 'lib/rsolr/connection.rb', line 81 def delete_by_query(query) update .delete_by_query(query) end |
#message ⇒ Object
shortcut to RSolr::Message::Builder
86 87 88 |
# File 'lib/rsolr/connection.rb', line 86 def @message ||= RSolr::Message::Builder.new end |
#optimize ⇒ Object
send </optimize>
61 62 63 |
# File 'lib/rsolr/connection.rb', line 61 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
39 40 41 42 |
# File 'lib/rsolr/connection.rb', line 39 def request(path, params={}, *extra) response = @adapter.request(path, map_params(params), *extra) adapt_response(response) end |
#rollback ⇒ Object
send </rollback> NOTE: solr 1.4 only
67 68 69 |
# File 'lib/rsolr/connection.rb', line 67 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
27 28 29 |
# File 'lib/rsolr/connection.rb', line 27 def update(data, params={}) request '/update', params, data end |