Skip to content

Instantly share code, notes, and snippets.

@ezodude
Created March 10, 2011 14:25
Show Gist options
  • Save ezodude/864155 to your computer and use it in GitHub Desktop.
Save ezodude/864155 to your computer and use it in GitHub Desktop.
Will turn this snippet into a rake task
def index_in_batches(klass, criteria={})
offset = 0
while true do
list = klass.all(criteria.merge(:limit => 30, :offset => offset))
break if list.empty?
Sunspot.index(list)
Sunspot.commit
offset += 30
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment