I have two models
class User < ActiveRecord::Base
has_many :posts
searchable do
text :post_titles
end
def post_titles
posts.map &:title
end
end
class Post < ActiveRecord::Base
belongs_to :user
end
the problem is that when I update title of the Post sunspot doesn’t update index for related user and it is not searchable by new data. If I do User.index it solves problem but takes too much time. Are there any better solutions to update parent record index on child record change(like reindex just parent record and not all users)?
Sunspot provides an instance
index()method, for indexing one record.What I did was
If you are running this in console, and want to see results immediately, call
Sunspot.commit