我尝试使用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。然后我进入控制台重新索引我的数据库。我也跟着这里回答的一些问题并改变了端口,但没有用。
有人会知道问题是什么吗?
答案 0 :(得分:1)
试试这个:
将Sunspot.config.solr.url = 'http://localhost:8983/solr'
添加到config/production.rb
您可以重新编制索引
rake sunspot:solr:reindex RAILS_ENV=production
如果那不起作用......
rm solr/pids/production/sunspot-solr-production.pid
start solr
rake sunspot:solr:start RAILS_ENV=production
再次重新索引
rake sunspot:solr:reindex RAILS_ENV=production
答案 1 :(得分:0)
Maye是你的solr服务器未启动使用此命令
rake sunspot:solr:start