This is a simple Rails 4 application that publishes changes to a Swiftype search engine via the API using the swiftype gem and displays results using the jQuery search plugin and jQuery auto-complete plugin.
We have also written a full tutorial using this application as an example.
- Sign up for a Swiftype account, then create an API based engine with a Document Type called "post".
- Clone this repository and run
bundle install
,rake db:create
, andrake db:migrate
. - Create a
.env
file with your Swiftype API key, engine key, engine slug, and default host (see.env.example
). - Install the
foreman
gem usinggem install foreman
. - Run the demo with
foreman start
.
This demo uses SQLite but with some minor modifications you can get it running on Heroku.
- Remove the
sqlite3
gem and replace it with thepg
gem. - Add the Swiftype Add-on to your app:
heroku addons:add swiftype
- Add the configuration variables
SWIFTYPE_ENGINE_KEY
,SWIFTYPE_ENGINE_SLUG
, andDEFAULT_HOST
to your Heroku app withheroku config:add
. - Create the document type with
heroku run rake app:create_document_type
- Deploy your application.
The demo uses delayed_job
for API calls, so you will need to add a worker with heroku ps:scale worker=1
.
If you would like to skip this, you can set Delayed::Worker.delay_jobs = false
in application.rb
You should create a separate engine for each environment so that queries do not match documents that don't exist in an application. You can use the same API key but different engine slugs for this purpose.