English 中文(简体)
Error while connecting to a remote solr instance from Sunspot
原标题:

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.

问题回答

暂无回答




相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签