I just installed the Sunspot gem:
gem 'sunspot_rails'
group :development do
gem 'sunspot_solr'
end
group :development, :test do
gem "sunspot_test"
end
If I don’t do sunspot:solr:start before doing rails server I get this error:
> 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'
Each time I do a POST request (e.g. creating posts and votes in my app).
Is this a normal behavior of the gem? Is there of skipping or automating this step?
EDIT:
Here is the post *create action* and model, just in case:
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
Yes, you need to start Solr if you want to use it, even if it’s prepackaged. To make your life easier, you can use something like Foreman.