2012-12-12 49 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的東西。

相關問題