3

I am working on a rails project that involves the solr sunspot gem. I left the default behavior to auto update the index on model saves, but I was wondering if there was a way to temporarily disable the indexing when mass creating objects, such as during a rake db:seed process. When using the seed command I was hoping it would add all of the objects and then perform one big reindex call to update the entire table. Any ideas?

Thanks!

Danny
  • 4,724
  • 6
  • 42
  • 55

2 Answers2

6

You could set Sunspot's session to a StubSessionProxy.

outoftime
  • 2,190
  • 1
  • 16
  • 17
  • 1
    Awesome! So I do Sunspot::Rails::StubSessionProxy.new(Sunspot.session). Do I need to reenable the session once the seeding is done? I'm not sure how to do that. Can ya help? – Danny May 03 '11 at 18:40
1

There's also this.

Basically, you should be able to add this to sunspot.yml:

development:
    disabled: true

This works great if you're running some tasks or queries directly on the DB. However, if you are running your app with this setting, and anywhere in your code you have something like:

Sunspot.config.pagination.default_per_page = 50

Then you'll hit an error like this:

undefined method `config' for #<Sunspot::Rails::StubSessionProxy:0x007ff6ee33df28>
yuяi
  • 2,617
  • 1
  • 23
  • 46