Solr sunspot in different environments
So I have been using solr sunspot for a couple of days and have been going a little crazy over an issue with it. I have search many different sites for the answer, but a lot of people seem to have different ideas. I am trying to figure out how sunspot manages indexing/reindexing of models in different environments with auto indexing on. This is what I have concluded:
Dev/Prod: Saving/updating an object automatically updates the indexing of that object in solr
Test: Saving/updat开发者_如何学Going an object does not automatically update the index and you need to call object.reindex! in order for it to take effect.
Console: Same as testing. Reindex is required to properly update solr.
So does this look correct? It was killing me for so long whether something was wrong with my solr sunspot setup or if it just doesn't work the same in these different environments. Any help would be greatly appreciated!
After updating a document in Solr, you must issue a "commit" to tell Solr to write the changes to disk and have them start appearing in search results. Sunspot::Rails takes care of this automatically in the course of a Rails request, but outside of that (in tests, from the console), you need to do it explicitly. It's a simple Sunspot.commit
.
There are three main ways to update an index:
- object.index: marks the object for indexing, but might not be immediately indexed
- object.index!: indexes the object immediately
- Class.reindex: indexes all objects on the model immediately
It sounds like you should be using the .index! method instead of the .index method on console.
精彩评论