Class: RSolr::Adapter::Direct

Inherits:
Object
  • Object
show all
Includes:
HTTPClient::Util
Defined in:
lib/rsolr/adapter/direct.rb

Overview

Connection for JRuby + DirectSolrConnection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts, &block) ⇒ Direct

required: opts is absolute path to solr home (the directory with “data”, “config” etc.) opts must also contain either

:dist_dir => 'absolute path to solr distribution root

or

:jar_paths => ['array of directories containing the solr lib/jars']

OTHER OPTS:

:select_path => 'the/select/handler'
:update_path => 'the/update/handler'


22
23
24
25
26
27
28
29
30
# File 'lib/rsolr/adapter/direct.rb', line 22

def initialize(opts, &block)
  @home_dir = opts[:home_dir].to_s
  opts[:data_dir] ||= File.join(@home_dir, 'data')
  if opts[:dist_dir] and ! opts[:jar_paths]
    # add the standard lib and dist directories to the :jar_paths
    opts[:jar_paths] = [File.join(opts[:dist_dir], 'lib'), File.join(opts[:dist_dir], 'dist')]
  end
  @opts = opts
end

Instance Attribute Details

#home_dirObject

Returns the value of attribute home_dir.



12
13
14
# File 'lib/rsolr/adapter/direct.rb', line 12

def home_dir
  @home_dir
end

#optsObject

Returns the value of attribute opts.



12
13
14
# File 'lib/rsolr/adapter/direct.rb', line 12

def opts
  @opts
end

Instance Method Details

#closeObject



42
43
44
45
46
47
# File 'lib/rsolr/adapter/direct.rb', line 42

def close
  if @connection
    @connection.close
    @connection=nil
  end
end

#connectionObject

loads/imports the java dependencies sets the @connection instance variable



34
35
36
37
38
39
40
# File 'lib/rsolr/adapter/direct.rb', line 34

def connection
  @connection ||= (
    require_jars(@opts[:jar_paths]) if @opts[:jar_paths]
    import_dependencies
    DirectSolrConnection.new(@home_dir, @opts[:data_dir], nil)
  )
end

#send_request(path, params = {}, data = nil) ⇒ Object

send a request to the connection request ‘/update’, :wt=>:xml, ‘</commit>’



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rsolr/adapter/direct.rb', line 51

def send_request(path, params={}, data=nil)
  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($!.message)
  end
  {
    :status_code=>nil,
    :body=>body,
    :url=>url,
    :path=>path,
    :params=>params,
    :data=>data,
    :headers=>nil
  }
end