sunspot_rails 不读取 sunspot.yml 的配置

发布于 2025-01-03 09:11:23 字数 815 浏览 3 评论 0原文

我正在尝试将 sunspot 与 mongoid 一起使用,但 sunspot 未连接到 Solr。尝试连接到 Solr 时 Rails 报告以下错误。

Errno::ECONNREFUSED (Connection refused - connect(2))

,我已确认 Solr 正在开发端口 (8982) 上运行(如 config/sunspot.yml 中定义)

我使用 bundle exec rake sunspot:solr:start 来运行 Solr,并且当我运行 时 在 Rails 控制台中的 Sunspot.config 中,我看到:

   @properties={:url=>"http://127.0.0.1:8983/solr"}

然后我将开发/生产端口更改为 8984/8985,Solr 从新的开发端口启动(8984) 但 Rails 控制台中的 Sunspot.config 仍然返回 http://127.0.0.1:8983/solr (既不是 8984 也不是 8985,这意味着它根本不读取 sunspot.yml

)我错过了 Rails 中 Sunspot 的一些初始化步骤?

我使用以下版本:

  • ruby​​ 1.9.3
  • Rails (3.2.1)
  • sunspot (1.3.0)
  • sunspot_rails (1.3.0)
  • sunspot_mongoid (0.4.1)

I'm trying to use sunspot with mongoid, but sunspot is not connecting to Solr. Following error reported by Rails when trying to connect to Solr.

Errno::ECONNREFUSED (Connection refused - connect(2))

I use bundle exec rake sunspot:solr:start to run Solr and I've confirmed that Solr is running on the development port (8982) as defined in config/sunspot.yml

When I run Sunspot.config in Rails console, I see that:

   @properties={:url=>"http://127.0.0.1:8983/solr"}

Then I changed the development/production ports to 8984/8985, Solr starts from the new dev port (8984) but Sunspot.config in Rails console still returns http://127.0.0.1:8983/solr (neither 8984 or 8985, which implies it doesn't read sunspot.yml at all)

Am I missing some intialization steps for Sunspot in Rails?

I'm using the following versions:

  • ruby 1.9.3
  • rails (3.2.1)
  • sunspot (1.3.0)
  • sunspot_rails (1.3.0)
  • sunspot_mongoid (0.4.1)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩物 2025-01-10 09:11:23

回答我自己的问题。实际上我的问题是sunspot_mongoid,当作为gem安装时它不支持rails,我必须将它作为rails插件添加到thr Rails项目中,然后正确加载config/sunspot.yml

Answering my own question. Actually my problem turned out to be sunspot_mongoid, which isn't rails-aware when installed as a gem, I had to add it into thr rails project as a rails plugin, which then loads config/sunspot.yml correctly

﹉夏雨初晴づ 2025-01-10 09:11:23

您是否退出控制台,重新启动并检查?

Have you exit you console, start it again and checked?

小霸王臭丫头 2025-01-10 09:11:23

当我尝试在控制台中使用 sunspot_index_queue 时,我遇到了类似的问题,结果发现 sunspot 没有从 sunspot_rails 获取所需的配置(从 sunspot.yml 获取它),对environments.rb 文件进行一些轻微的修改应该可以做到诡计。这就是我在我的情况下必须做的事情(如果有人从谷歌找到此页面,请发布它):

<code>
SunspotConfig = Sunspot::Rails::Configuration.new
Sunspot.session = Sunspot::IndexQueue::SessionProxy.new(
  Sunspot::IndexQueue.new(
    :session => Sunspot::Session.new{|config| config.solr.url = "http://#{SunspotConfig.hostname}:#{SunspotConfig.port}/solr"}
  )
)
</code>

要在没有队列的情况下使用,本地线程代理应该自动从您的 sunspot.yml 恢复,因此您无需担心。如果您对 sunspot.yml 文件中的任何内容感兴趣,请尝试使用 Sunspot::ConfigurationSunspot::Rails::Configuration 。 (记住要实例化!)

I had a similar problem when trying to use sunspot_index_queue form the console and it turned out that sunspot was not getting the configuration it needed from sunspot_rails (which gets it from your sunspot.yml) Some slight modification to your environments.rb file should do the trick. This is what I had to do in my case (posting it if anyone finds this page from google):

<code>
SunspotConfig = Sunspot::Rails::Configuration.new
Sunspot.session = Sunspot::IndexQueue::SessionProxy.new(
  Sunspot::IndexQueue.new(
    :session => Sunspot::Session.new{|config| config.solr.url = "http://#{SunspotConfig.hostname}:#{SunspotConfig.port}/solr"}
  )
)
</code>

To use without the queue, the local thread proxy should recover from your sunspot.yml automatically, so you won't need to worry. Try Sunspot::Configuration or Sunspot::Rails::Configuration instead if you're interested in anything thats in your sunspot.yml file. (Remember to instantiate!)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文