Recommendable is an engine for Rails 3 applications to quickly add the ability for your users to Like/Dislike items and receive recommendations for new items. It uses Redis to store your recommendations and keep them sorted by how good the recommendation is.
- Ruby 1.9.x
- Rails 3.x or 4.x
- Sidekiq or Resque (or DelayedJob)
Bundling one of the queueing systems above is highly recommended to avoid having to manually refresh users' recommendations. If running on Rails 4, the built-in queueing system is supported. If you bundle Sidekiq, Resque, or DelayedJob, Recommendable will use your bundled queueing system instead. If bundling Resque, you should also include 'resque-loner' in your Gemfile to ensure your users only get queued once (Sidekiq does this by default, and there is no current way to avoid duplicate jobs in DelayedJob).
Add the following to your Rails application's Gemfile
:
gem 'recommendable'
After bundling, run the installation generator:
$ rails g recommendable:install
Double check config/initializers/recommendable.rb
for options on configuring your Redis connection. After a user likes or dislikes something new, they are placed in a queue to have their recommendations updated. If you're using the basic Rails 4.0 queue, you don't need to do anything explicit. If using Sidekiq, Resque, or DelayedJob, start your workers from the command line:
# sidekiq
$ bundle exec sidekiq -q recommendable
# resque
$ QUEUE=recommendable rake environment resque:work
# delayed_job
$ rake jobs:work
In your Rails model that will be receiving recommendations:
class User < ActiveRecord::Base
recommends :movies, :shows, :other_things
# ...
end
That's it! Please note, however, that you may only do this in one model at this time.
For more details on how to use Recommendable once it's installed and configured, check out the more detailed README or see the documentation.
Recommendable requires Redis to deliver recommendations. The collaborative filtering logic is based almost entirely on set math, and Redis is blazing fast for this. NOTE: Your redis database MUST be persistent.
For Mac OS X users, homebrew is by far the easiest way to install Redis. Make sure to read the caveats after installation!
$ brew install redis
For Linux users, there is a package on apt-get.
$ sudo apt-get install redis-server
$ redis-server
Redis will now be running on localhost:6379. After a second, you can hit ctrl-\
to detach and keep Redis running in the background.
Oops, did you kill your Redis database? Not to worry. Likes, Dislikes, Ignores, and StashedItems are stored as models in your regular database. As long as these still exist, you can regenerate the similarity values and recommendations on the fly. But try not to have to do it!
Users.all.each do |user|
user.send :update_similarities
user.send :update_recommendations
end
Once you've made your great commits:
- Fork recommendable
- Create a feature branch
- Write your code (and tests please)
- Push to your branch's origin
- Create a Pull Request from your branch
- That's it!
- Code:
git clone git://github.com/davidcelis/recommendable.git
- Home: http://github.com/davidcelis/recommendable
- Docs: http://rubydoc.info/gems/recommendable/frames
- Bugs: http://github.com/davidcelis/recommendable/issues
- Gems: http://rubygems.org/gems/recommendable
Copyright © 2012 David Celis. See LICENSE.txt for further details.