Search code examples
ruby-on-rails-3sunspotsunspot-railssunspot-solr

Rails 3 Sunspot Limit Objects to be indexed


I am using Rails 3 sunspot solr. I want to restrict Objects to be indexed. e.g. Index Posts where ids ranges from 1..1000. After that it should not be index.


Solution

  • Finally I found my answer

    searchable :if => :id_less_than_1000? do
    ...
    end
    def id_less_than_1000?
      self.id < Post.maximum(:id)
    end