Vlad Zloteanu
Vlad Zloteanu

Reputation: 8512

Rails - Sunspot conditional model indexing

Is there any way to determine on runtime if a model should be indexed or not? Something like:

class Article < ActiveRecord::Base

  searchable :if => :indexable? do 
    ...
  end

  private
  def indexable?
    ...
  end

end

Upvotes: 4

Views: 1059

Answers (2)

Andy Triggs
Andy Triggs

Reputation: 1305

Here's a good article on conditional indexing: http://mikepackdev.com/blog_posts/19-conditional-indexing-with-sunspot

That is, exactly the API you propose in your question.

Upvotes: 2

macarthy
macarthy

Reputation: 3069

Answered here

Exclude draft articles from Solr index with Sunspot

Upvotes: 5

Related Questions