-->

Connection refused using Sunspot and Solr in Rails

2019-02-26 01:59发布

问题:

I'm having an issue wherein I get an ECONNREFUSED error when I try to perform a search using sunspot_rails. The gems (sunspot_rails and sunspot_solr) both seem to be installed properly. I'm running version 1.3.3 and I have the server running correctly.

I've found another post about this, but the post only recommended starting the sunspot solr server. I've definitely done that, but the error persists.

I believe the problem is due to the port the server is on. When I look at the output from RAILS_ENV=development rake sunspot:solr:run, it shows that the server is running on port 8983. I've also tried the command RAILS_ENV=production rake sunspot:solr:run with the same effect.

If I examine the sunspot.yml config file, it shows the following:

production:
  solr:
    hostname: localhost
    port: 8983
    log_level: WARNING

development:
  solr:
    hostname: localhost
    port: 8982
    log_level: INFO

test:
  solr:
    hostname: localhost
    port: 8981
    log_level: WARNING

Notice that it's supposed to be on port 8982 for development, but no matter what I do it seems to keep restarting the server on port 8983. Any idea how this could be happening?

Thanks!

Update: I've found a potential cause. In my project folder, the file /solr/conf/scripts.conf contains the following: solr_port=8983. This seems to imply a hardcoded port no matter what Rails environment is active.

回答1:

Turns out it was a bug in Sunspot. Here's a link to the issue I filed for a full description:

https://github.com/sunspot/sunspot/issues/262

My workaround was to edit the .yml file and change all ports (test, development, and production) to 8983.