I am using Sunspot rails(1.1.0). Everything works when I run my Rails application and the Solr server on the same machine. When I run Solr server on a different machine, I get the following error:
Errno::ECONNREFUSED: Connection refused - Connection refused
from /opt/tibco/jruby-1.4.0RC1/lib/ruby/1.8/net/http.rb:560:in `initialize'
from /opt/tibco/jruby-1.4.0RC1/lib/ruby/1.8/net/http.rb:560:in `new'
from /opt/tibco/jruby-1.4.0RC1/lib/ruby/1.8/net/http.rb:560:in `open'
After debugging through Sunspot code, I realized that the Solr::Client is connecting to localhost
rather than the remote host configured in sunspot.yml
. My sunspot.yml file is as follows:
production:
solr:
hostname: kingkong
port: 8983
log_level: WARNING
The build_session
method(sunspot_rails-1.1.0/lib/rails.rb:line 24) tries to establish a slave session. The slave_config method ignores the configuration provided in sunspot.yml file. Here is the slave_config
method:
def slave_config(sunspot_rails_configuration)
config = Sunspot::Configuration.build
config.solr.url = URI::HTTP.build(
:host => configuration.hostname,
:port => configuration.port,
:path => configuration.path
).to_s
config
end
Is this the intended behavior? Also, has anybody successfully connected to Solr running remotely?
Note:
I was able to work around this issue by monkey patching the Sunspot::Rails.slave_config method. I added file called sunspot.rb in configurations/initializers directory.
module Sunspot::Rails
def slave_config(sunspot_rails_configuration)
config = Sunspot::Configuration.build
config.solr.url = URI::HTTP.build(
:host => sunspot_rails_configuration.hostname,
:port => sunspot_rails_configuration.port,
:path => sunspot_rails_configuration.path
).to_s
config
end
end
Sunspot.session = Sunspot::Rails.build_session
I am not sure if this is the correct approach. Please let me know if I am missing something basic.