By default, the sunspot solr gem issues an index command to the solr server as part of the save callback. This behavior is acceptable in most of my app, but there are some parts of it (especially those in rake tasks for bulk processing) where I want to save instances of my model without any interaction whatsoever with the solr server. How do I achieve this?
Asked
Active
Viewed 1,574 times
2 Answers
5
According to the docs I think you should add auto_index: false
to your searchable block, i.e.:
class Foo < ActiveRecord::Base
searchable auto_index: false do
# your search fields here
end
end
Then you can use the following methods to manually reindex records:
# On a class itself
Person.reindex
Sunspot.commit # or commit(true) for a soft commit (Solr4)
# On mixed objects
Sunspot.index [post1, item2]
Sunspot.index person3
Sunspot.commit # or commit(true) for a soft commit (Solr4)
# With autocommit
Sunspot.index! [post1, item2, person3]

Flavio Wuensche
- 9,460
- 1
- 57
- 54

zrl3dx
- 7,699
- 3
- 25
- 35
-1
To disable it add auto_commit_after_request: false
to your sunspot.yml
.

Maurizio In denmark
- 4,226
- 2
- 30
- 64
-
No, this is not right. I already have auto_commit_after_request: false, but this governs whether the solr server commits after the request. Even when set to false, the app still makes a request to the solr server to index the instance of the model. It just doesn't commit it right away. – alpheus Sep 10 '13 at 04:51