Created
          March 10, 2011 14:25 
        
      - 
      
- 
        Save ezodude/864155 to your computer and use it in GitHub Desktop. 
    Will turn this snippet into a rake task
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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