Ruby on Rails
The official meilisearch-rails gem indexes your Active Record models and searches them. Point it at your CelerSearch instance and it works as it would with any Meilisearch.
1. Install
gem 'meilisearch-rails'
bundle install
2. Configure
Copy the Endpoint URL and API key from your instance's Connection
details at app.celersearch.com, and expose
them as environment variables (MEILISEARCH_HOST, MEILISEARCH_API_KEY) or
Rails credentials.
Meilisearch::Rails.configuration = {
meilisearch_url: ENV.fetch('MEILISEARCH_HOST'),
meilisearch_api_key: ENV.fetch('MEILISEARCH_API_KEY')
}
Server-side only
The API key has full access to your instance. Keep it in your server's environment or credentials. Never render it into views or JavaScript.
3. Index a model
class Book < ApplicationRecord
include Meilisearch::Rails
meilisearch enqueue: true do
attribute :title, :author, :genre
filterable_attributes [:genre]
sortable_attributes [:title]
end
end
enqueue: true moves indexing into Active Job (on a meilisearch queue), so
saving a record never waits on a network call. Drop it to index inline.
Import the records you already have:
Book.reindex!
New, changed and deleted records are synced automatically after that.
4. Search
# Typo-tolerant search, returning Book records
Book.search('harry pottre')
# Filter, sort and page size
Book.search('harry', filter: ['genre = fantasy'], sort: ['title:asc'], hits_per_page: 10)
Plans and limits
Each indexed record is one document toward your plan's document limit. Searches are always unlimited. At the limit, new writes are refused until you delete documents or move to a larger plan. See Connect Any App.
Next steps
- Connect Any App: connection details, platform responses and browser search
- Migrate to CelerSearch: move an existing index from another Meilisearch
- Pricing: plans by document count