2012-12-12 51 views
1

我刚安装了Sunspot宝石:我每次运行Rails应用程序时都必须启动Sunspot/Solr?

gem 'sunspot_rails' 

group :development do 
    gem 'sunspot_solr' 
end 

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

如果我不这样做sunspot:solr:startrails 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请求(例如创造职位,在我的应用程序投票)。

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

编辑:

这里是 * 创建行动 *和模式,以防万一:

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 
+0

如果你真的想跳过启动solr(可能是慢速开发机器),将可搜索块包装在'if Rails.env.production?'中,或者使用delayed_job或其他排队系统来推迟索引,但总的来说,将它添加到Foreman或让初始化器启动服务器。 – Unixmonkey

回答

4

Is this a normal behavior of the gem? Is there of skipping or automating this step?

是的,你需要开始的Solr如果你想使用它,即使它是预先包装的。为了让你的生活更轻松,你可以使用类似Foreman的东西。

相关问题