Class: RSolr::Connection::Direct
- Inherits:
-
Object
- Object
- RSolr::Connection::Direct
- Includes:
- Utils
- Defined in:
- lib/rsolr/connection/direct.rb
Overview
Connection for JRuby + DirectSolrConnection
Instance Attribute Summary collapse
-
#opts ⇒ Object
Returns the value of attribute opts.
Instance Method Summary collapse
- #close ⇒ Object
-
#connection ⇒ Object
sets the @connection instance variable if it has not yet been set.
-
#initialize(opts, &block) ⇒ Direct
constructor
opts can be an instance of org.apache.solr.servlet.DirectSolrConnection if opts is NOT an instance of org.apache.solr.servlet.DirectSolrConnection then…
-
#request(path, params = {}, data = nil, opts = {}) ⇒ Object
send a request to the connection request ‘/select’, :q=>‘something’ request ‘/update’, :wt=>:xml, ‘</commit>’.
Methods included from Utils
#build_param, #build_url, #bytesize, #escape, #hash_to_query
Constructor Details
#initialize(opts, &block) ⇒ Direct
opts can be an instance of org.apache.solr.servlet.DirectSolrConnection if opts is NOT an instance of org.apache.solr.servlet.DirectSolrConnection then… required: opts is absolute path to solr home (the directory with “data”, “config” etc.)
You can load your own solr java libs by setting :autoload_jars to false. When set to true (default), RSolr loads its own set of solr java libs.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rsolr/connection/direct.rb', line 21 def initialize(opts, &block) if defined?(Java::OrgApacheSolrCore::SolrCore) and opts.is_a?(Java::OrgApacheSolrCore::SolrCore) @connection = org.apache.solr.servlet.DirectSolrConnection.new(opts) elsif defined?(Java::OrgApacheSolrServlet::DirectSolrConnection) and opts.is_a?(Java::OrgApacheSolrServlet::DirectSolrConnection) @connection = opts else opts[:data_dir] ||= File.join(opts[:home_dir].to_s, 'data') @opts = opts end end |
Instance Attribute Details
#opts ⇒ Object
Returns the value of attribute opts.
12 13 14 |
# File 'lib/rsolr/connection/direct.rb', line 12 def opts @opts end |
Instance Method Details
#close ⇒ Object
39 40 41 42 43 44 |
# File 'lib/rsolr/connection/direct.rb', line 39 def close if @connection @connection.close @connection=nil end end |
#connection ⇒ Object
sets the @connection instance variable if it has not yet been set
33 34 35 36 37 |
# File 'lib/rsolr/connection/direct.rb', line 33 def connection @connection ||= ( org.apache.solr.servlet.DirectSolrConnection.new(opts[:home_dir], @opts[:data_dir], nil) ) end |
#request(path, params = {}, data = nil, opts = {}) ⇒ Object
send a request to the connection request ‘/select’, :q=>‘something’ request ‘/update’, :wt=>:xml, ‘</commit>’
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rsolr/connection/direct.rb', line 49 def request(path, params={}, data=nil, opts={}) data = data.to_xml if data.respond_to?(:to_xml) url = build_url(path, params) begin body = connection.request(url, data) rescue raise RSolr::RequestError.new($!.) end { :status_code => 200, :url=>url, :body=>body, :path=>path, :params=>params, :data=>data, :headers => {}, :message => '' } end |