我尝试使用 Sunspot_Solr 将搜索功能添加到一个简单的应用程序中,但是连接不断被拒绝。
这是我从错误页面得到的结果:
Showing /Users/danieluribe/code/other/shouter2/app/views/searches/_search.html.erb where line #2 raised:
Connection refused - {:data=>"fq=type%3AShout&start=0&rows=30&q=*%3A*", :method=>:post, :params=>{:wt=>:ruby}, :query=>"wt=ruby", :headers=>{"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}, :path=>"select", :uri=>#<URI::HTTP http://localhost:8983/solr/development/select?wt=ruby>, :open_timeout=>nil, :read_timeout=>nil, :retry_503=>nil, :retry_after_limit=>nil}
Extracted source (around line #11):
def shouts
# Shout.text_shouts.where(content_id: text_shouts)
Shout.search do
fulltext @term
end.results
end
Trace of template inclusion: app/views/searches/show.html.erb
我添加了 Sunspot_Solr 和 Sunspot_Rails gem。我继续运行生成器,在 config 文件夹中创建了 Sunspot.yml 文件。
错误指向我的名为 Search.rb 的模型文件。这是上面部分内容的完整文件引用,已删除注释。
class Search
include ActiveModel::Conversion
attr_reader :term
def initialize options = ()
@term = options.fetch(:term, "")
end
def shouts
Shout.search do <--- Error points here
fulltext @term
end.results
end
end
我继续使用 rake 任务来启动 Sunspot_Solr。然后我进入控制台重新索引我的数据库。我还遵循了此处回答的一些问题并更改了端口,但无济于事。
有人知道问题出在哪里吗?
最佳答案
可能您的 solr 服务器未启动,请使用此命令
rake 太阳黑子:solr:开始
关于ruby-on-rails - Sunspot Solr 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35977576/