Method: ActsAsSolr::Post.execute

Defined in:
lib/acts_as_solr.rb

.execute(request, core = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/acts_as_solr.rb', line 42

def self.execute(request, core = nil)
  begin
    if File.exists?(RAILS_ROOT+'/config/solr.yml')
      config = YAML::load_file(RAILS_ROOT+'/config/solr.yml')
      url = config[ENV['RAILS_ENV']]['url']
      # for backwards compatibility
      url ||= "http://#{config[ENV['RAILS_ENV']]['host']}:#{config[ENV['RAILS_ENV']]['port']}/#{config[ENV['RAILS_ENV']]['servlet_path']}"
    else
      url = 'http://localhost:8982/solr'
    end
    url += "/" + core if !core.nil?
    connection = Solr::Connection.new(url)
    return connection.send(request)
  rescue 
    raise "Couldn't connect to the Solr server at #{url}. #{$!}"
    false
  end
end