sunspot_rails 不读取 sunspot.yml 的配置
我正在尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
回答我自己的问题。实际上我的问题是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
您是否退出控制台,重新启动并检查?
Have you exit you console, start it again and checked?
当我尝试在控制台中使用 sunspot_index_queue 时,我遇到了类似的问题,结果发现 sunspot 没有从 sunspot_rails 获取所需的配置(从 sunspot.yml 获取它),对environments.rb 文件进行一些轻微的修改应该可以做到诡计。这就是我在我的情况下必须做的事情(如果有人从谷歌找到此页面,请发布它):
要在没有队列的情况下使用,本地线程代理应该自动从您的 sunspot.yml 恢复,因此您无需担心。如果您对 sunspot.yml 文件中的任何内容感兴趣,请尝试使用
Sunspot::Configuration
或Sunspot::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):
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
orSunspot::Rails::Configuration
instead if you're interested in anything thats in your sunspot.yml file. (Remember to instantiate!)