Class: Solr::Adapter::HTTP
- Inherits:
-
Object
- Object
- Solr::Adapter::HTTP
- Includes:
- CommonMethods
- Defined in:
- lib/solr/adapter/http.rb
Overview
Connection for standard HTTP Solr server
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(opts = {}) {|@connection| ... } ⇒ HTTP
constructor
opts can have: :url => ‘localhost:8080/solr’ :select_path => ‘/the/url/path/to/the/select/handler’ :update_path => ‘/the/url/path/to/the/update/handler’ :luke_path => ‘/admin/luke’.
-
#send_request(request_url_path, params = {}, data = nil) ⇒ Object
send a request to the connection request ‘/update’, :wt=>:xml, ‘</commit>’.
Constructor Details
#initialize(opts = {}) {|@connection| ... } ⇒ HTTP
opts can have:
:url => 'http://localhost:8080/solr'
:select_path => '/the/url/path/to/the/select/handler'
:update_path => '/the/url/path/to/the/update/handler'
:luke_path => '/admin/luke'
If a block is given, the @connection (Net::HTTP) instance is yielded
19 20 21 22 23 24 25 |
# File 'lib/solr/adapter/http.rb', line 19 def initialize(opts={}, &block) opts[:url]||='http://127.0.0.1:8983/solr' @url = URI.parse(opts[:url]) @connection = Net::HTTP.new(@url.host, @url.port) yield @connection if block_given? @opts = .merge(opts) end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
10 11 12 |
# File 'lib/solr/adapter/http.rb', line 10 def connection @connection end |
#opts ⇒ Object
Returns the value of attribute opts.
10 11 12 |
# File 'lib/solr/adapter/http.rb', line 10 def opts @opts end |
#url ⇒ Object
Returns the value of attribute url.
10 11 12 |
# File 'lib/solr/adapter/http.rb', line 10 def url @url end |
Instance Method Details
#send_request(request_url_path, params = {}, data = nil) ⇒ Object
send a request to the connection request ‘/update’, :wt=>:xml, ‘</commit>’
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/solr/adapter/http.rb', line 29 def send_request(request_url_path, params={}, data=nil) data = data.to_xml if data.respond_to?(:to_xml) full_path = build_url(@url.path + request_url_path, params) if data response = @connection.post(full_path, data, post_headers) else response = @connection.get(full_path) end unless response.code=='200' raise Solr::RequestError.new(parse_solr_html_error(response.body)) end response.body end |