【问题标题】:Sunspot Solr Connection Refused太阳黑子 Solr 连接被拒绝
【发布时间】:2016-03-14 00:12:18
【问题描述】:

我正在尝试使用 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 的模型文件。这是上面部分删除了 cmets 的完整文件参考。

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。然后我进入控制台重新索引我的数据库。我还关注了此处回答的一些问题并更改了端口,但无济于事。

有人知道问题可能是什么吗?

【问题讨论】:

  • 你能把Sunspot.config.solr.url = 'http://localhost:8983/solr'加到config/production.rb吗

标签: ruby-on-rails ruby solr sunspot


【解决方案1】:

可能是你的 solr 服务器没有启动使用这个命令

耙太阳黑子:solr:start

【讨论】:

    【解决方案2】:

    试试这个:

    将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
    

    【讨论】:

    • 我的配置文件中确实有 Sunspot.config.solr.url = 'http://localhost:8983/solr' 。我没有运气就完成了其他步骤。我得到以下信息:RSolr::Error::ConnectionRefused: Connection refused 后跟一个长哈希。
    • 您是否添加了任何您希望索引的可搜索块?可以看教程railscasts.com/episodes/278-search-with-sunspot
    • 我正在关注 Upcase 的教程,他们最初做了自己的搜索功能,效果很好。然后他们切换到太阳黑子宝石。这是一个 twitter 克隆,所以我正在搜索喊叫(推文)。
    • github.com/sunspot/sunspot 还提到了可搜索块。您需要为要搜索的每个模型添加它。
    • 当我添加 Shout 方法时,我相信这就是我在模型中所做的。
    猜你喜欢
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2014-03-29
    • 1970-01-01
    相关资源
    最近更新 更多