If you want unpublished articles to never be included in the search index, you can do this as follows:
class Article < ActiveRecord::Base searchable :if => :published? do text :title text :body end end
Then the model will be indexed only after publication.
My approach is less interesting if you also want administrators to be able to search for articles, including unpublished ones.
Note: call article.index! will add an instance to the index regardless of the parameter :if => :method .
source share