1

我刚刚安装了太阳黑子gem:

gem 'sunspot_rails'

group :development do
  gem 'sunspot_solr'
end

group :development, :test do
  gem "sunspot_test"
end

如果我在做sunspot:solr:start之前不做,rails server我会收到这个错误:

> OLR Request (1.3ms)  [ path=#<RSolr::Client:0xa9a3f6c>
> parameters={data: <?xml version="1.0"
> encoding="UTF-8"?><add><doc><field name="id">Post 36</field><field
> name="type">Post</field><field
> name="type">ActiveRecord::Base</field><field
> name="class_name">Post</field><field boost="5"
> name="title_text">sadads</field><field
> name="content_text">asdasdasdasdsadsdsd</field></doc></add>, headers:
> {"Content-Type"=>"text/xml"}, method: post, params: {:wt=>:ruby},
> query: wt=ruby, path: update, uri:
> http://localhost:8982/solr/update?wt=ruby, open_timeout: ,
> read_timeout: } ]
>      (0.4ms)  rollback transaction
>     Completed 500 Internal Server Error in 639ms
>     
>     Errno::ECONNREFUSED (Connection refused - connect(2)):
>       app/controllers/posts_controller.rb:41:in `create'

每次我做一个 POST 请求(例如在我的应用程序中创建帖子和投票)。

这是宝石的正常行为吗?是否有跳过或自动化这一步?

编辑:

这是帖子* create action * 和model,以防万一:

  def create
    @post = current_user.posts.build(params[:post])
    if @post.save
      flash[:success] = "Post created!"
      redirect_to @post
    else
      render 'new'
    end
  end

class Post < ActiveRecord::Base

  searchable do
    text :title, boost: 5
    text :content
    text :replies do
      replies.map { |reply| reply.content }
    end
  end
4

1 回答 1

4

这是宝石的正常行为吗?是否有跳过或自动化这一步?

是的,如果你想使用 Solr,你需要启动它,即使它是预打包的。为了让你的生活更轻松,你可以使用像Foreman这样的东西。

于 2012-12-12T15:32:22.847 回答