Class: RSolr::Connection
- Inherits:
-
Object
- Object
- RSolr::Connection
- Defined in:
- lib/rsolr/connection.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
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, opts = {}) ⇒ Connection
constructor
“adapter” is instance of: RSolr::Adapter::HTTP RSolr::Adapter::Direct (jRuby only).
-
#optimize ⇒ Object
send </optimize>.
-
#rollback ⇒ Object
send </rollback> NOTE: solr 1.4 only.
-
#select(params, &blk) ⇒ Object
send a request to the “select” handler.
-
#send_request(path, params = {}, data = nil, &blk) ⇒ 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 .
-
#update(data, params = {}, &blk) ⇒ Object
sends data to the update handler data can be a string of xml, or an object that returns xml from its #to_s method.
Constructor Details
#initialize(adapter, opts = {}) ⇒ Connection
“adapter” is instance of:
RSolr::Adapter::HTTP
RSolr::Adapter::Direct (jRuby only)
8 9 10 11 |
# File 'lib/rsolr/connection.rb', line 8 def initialize(adapter, opts={}) @adapter = adapter @opts = opts end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
3 4 5 |
# File 'lib/rsolr/connection.rb', line 3 def adapter @adapter end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/rsolr/connection.rb', line 3 def opts @opts 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’])
49 50 51 |
# File 'lib/rsolr/connection.rb', line 49 def add(doc, &block) update .add(doc, &block) end |
#commit ⇒ Object
send </commit>
54 55 56 |
# File 'lib/rsolr/connection.rb', line 54 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])
72 73 74 |
# File 'lib/rsolr/connection.rb', line 72 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"']
79 80 81 |
# File 'lib/rsolr/connection.rb', line 79 def delete_by_query(query) update .delete_by_query(query) end |
#optimize ⇒ Object
send </optimize>
59 60 61 |
# File 'lib/rsolr/connection.rb', line 59 def optimize update .optimize end |
#rollback ⇒ Object
send </rollback> NOTE: solr 1.4 only
65 66 67 |
# File 'lib/rsolr/connection.rb', line 65 def rollback update .rollback end |
#select(params, &blk) ⇒ Object
send a request to the “select” handler
14 15 16 |
# File 'lib/rsolr/connection.rb', line 14 def select(params, &blk) send_request('/select', map_params(params), &blk) end |
#send_request(path, params = {}, data = nil, &blk) ⇒ 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
use a block to get access to the adapter response: solr.send_request(‘/select’, :q=>‘blue’) do |solr_response, adapter_response|
raise 'Woops!' if adapter_response[:status] != 200
solr_response[:response][:docs].each {|doc|}
end
37 38 39 40 |
# File 'lib/rsolr/connection.rb', line 37 def send_request(path, params={}, data=nil, &blk) response = @adapter.send_request(path, map_params(params), data) adapt_response(response, &blk) end |
#update(data, params = {}, &blk) ⇒ Object
sends data to the update handler data can be a string of xml, or an object that returns xml from its #to_s method
20 21 22 |
# File 'lib/rsolr/connection.rb', line 20 def update(data, params={}, &blk) send_request('/update', map_params(params), data, &blk) end |