How to use the Swiftype Full-text Search Heroku Add-on
The Swiftype Heroku Add-on is a simple way to start working with the Swiftype API from your Heroku app.
Step 1: Provision the Swiftype Add-on in your Heroku App
There is no need to sign up for a Swiftype account first — this step automatically creates a Swiftype account for you as part of the provisioning process.
$ heroku addons:add swiftype
Step 2: Check your Heroku config
If the Swiftype add-on was successfully provisioned, you should see a new configuration value in your Heroku config:
$ heroku config | grep SWIFTYPE_URL SWIFTYPE_URL => https://your-api-key:@api.swiftype.com/api/v1
Step 3: Replicate your configuration locally
After provisioning the add-on it’s necessary to locally replicate the config vars so your development environment can operate against the service.
Use Forman to reliably configure and run the process formation specified in your app's Procfile. Foreman reads configuration variables from an .env file.
Your Swiftype search engine is like a database, so we recommend creating separate Swiftype engines for each server environment and developer so updates and deletes do not conflict with each other.
Use the following command to add the
SWIFTYPE_URL value retrieved from heroku config to
$ heroku config -s | grep SWIFTYPE_URL >> .env $ more .env
Step 4: Add the Swiftype Gem to your Rails app
The easiest way to get started using Swiftype with Rails is to follow our Rails integration tutorial.
Ruby on Rails applications will need to add the following entry into their Gemfile specifying the Swiftype client library.
gem 'swiftype', '~> 1.0.0'
Update application dependencies with bundler.
$ bundle install
Create a configuration file at config/swiftype.rb, and add configuration information:
Swiftype.authenticated_url = ENV['SWIFTYPE_URL']
Step 5: Interact with the Swiftype API from your controllers and models
You're now ready to start making calls to the Swiftype API from controllers or model callbacks. See our Swiftype Ruby gem for examples, as well as the detailed API documentation for an exhaustive review of the available functionality.
For the Heroku add-on, your engine slug (used in API calls) will always be "engine". You'll need to create one or more DocumentTypes via the API to store your Documents.
The swiftype-rails-example project provides a good starting point for building a Rails-based application.
Step 6: Open the Swiftype Dashboard to customize your search engine
The dashboard can be accessed via the CLI:
$ heroku addons:open swiftype Opening swiftype for sharp-mountain-4005...