This gem let you easily integrate the Algolia Search API to your favorite ORM. It’s based on the algoliasearch-client-ruby gem. Rails 3.x, 4.x and 5.x are all supported.

You might be interested in the sample Ruby on Rails application providing a autocomplete.js-based auto-completion and InstantSearch.js-based instant search results page: algoliasearch-rails-example.


gem install algoliasearch-rails

Add the gem to your Gemfile:

gem "algoliasearch-rails"

And run:

bundle install


Create a new file config/initializers/algoliasearch.rb to setup your APPLICATION_ID and API_KEY.

AlgoliaSearch.configuration = { application_id: 'YourApplicationID', api_key: 'YourAPIKey' }

The gem is compatible with ActiveRecord, Mongoid and Sequel.


You can configure a various timeout thresholds by setting the following options at initialization time:

AlgoliaSearch.configuration = {
  application_id: 'YourApplicationID',
  api_key: 'YourAPIKey',
  connect_timeout: 2,
  receive_timeout: 30,
  send_timeout: 30,
  batch_timeout: 120,
  search_timeout: 5


This gem makes extensive use of Rails’ callbacks to trigger the indexing tasks. If you’re using methods bypassing after_validation, before_save or after_commit callbacks, it will not index your changes. For example: update_attribute doesn’t perform validations checks, to perform validations when updating use update_attributes.

All methods injected by the AlgoliaSearch module are prefixed by algolia_ and aliased to the associated short names if they aren’t already defined.

Contact.algolia_reindex! # <=> Contact.reindex!

Contact.algolia_search("jon doe") # <=>"jon doe")