Indexing Class with UUID Primary Key with Sunspot Solr on Ruby on Rails
Major pain when indexing classes with UUID primary keys with Sunspot Solr. Essentially because integer is still assumed as the data type for primary keys. While this issue is still open https://github.com/sunspot/sunspot/issues/225 we have to do a quick work around.
Now there is already a pull request that might (haven't tested yet myself) resolve this issue: https://github.com/sunspot/sunspot/pull/373
But for the moment, the suggested workaround from Tad (https://github.com/rthbound) worked for me. So here's how it goes:
- Comment out the "searchable" block in your class or classes.
- Reindex, rake sunspot:solr:reindex
- Uncomment the "searchable" block in your class or classes.
- Go to the console, rails c
- Execute, Sunspot.index(ModelClass.all); Sunspot.index!(ModelClass.last)
Exit the console and your search engine should work. Now the major setback of this is if you're executing this on a production server with millions of items to index (I personally haven't tried that, the last index I did was only around 2,000+).
The Gems:
gem "sunspotrails", "~> 2.0.0"
and
gem "sunspotsolr", "~> 2.0.0" (in development group)
I'm on Heroku (Cedar) with WebSolr addon.
UPDATE 04/22/2014
Updating to "sunspotrails" and "sunspotsolr" 2.1.0 resolves this issue.
Stop solr via rake sunspot:solr:stop then reindex by rake sunspot:solr:reindex
Also, add this line to your sunspot.yml: solr_home: solr
Placed it inside the development config, so it looks like this:
development:
solr:
solr_home: solr
hostname: localhost
port: 8982
log_level: INFO