Searchify Heroku Add-on

Searchify is a cloud-based search solution. With it you can have your application's textual content searchable in a highly efficient, scalable and robust platform, without the hassle and cost of building, configuring, maintaining and hosting your own search implementation.

This Heroku Add-on allows you to use Searchify in your application, adding real-time search with very little effort.

Installing the Add-on

First you need to choose a plan that suits your needs, based on the number and the size of the documents you want to index and the number of queries per day that you expect to get. Visit the Searchify addon page to see the different plans available. Then run the following command, replacing <PLAN> with the name of the plan you choose:

$ heroku addons:add searchify:<PLAN>

This will create an account on Searchify and associate it with your Heroku user. You will see an empty index named "idx" on your account. You can choose to use it, or delete it and create a new one.

Local setup

To test the service locally you will need to retrieve the environment variables from Heroku using the following command:

$ heroku config --long

The SEARCHIFY_API_URL is your private API URL that you can use to talk to the Searchify service from within your application. You only need it when you are running locally (not on Heroku).

You will also need to install the IndexTank Ruby gem (or one of the other language clients) to develop locally.

Installing the IndexTank gem

$ gem install indextank

Now you can use the IndexTank client to add documents to your index and perform searches. You can grab the following sample code and use it in your application. Make sure you replace <API_URL> with the value of the SEARCHIFY_API_URL environment variable you got in the previous step, and <INDEX_NAME> with the name of your index (remember we already created the "idx" index for you when you signed up):

require 'rubygems'
require 'indextank'

# Obtain an IndexTank client
client = IndexTank::Client.new(ENV['SEARCHIFY_API_URL'] || '<API_URL>')
index = client.indexes('<INDEX_NAME>')

begin
    # Add documents to the index
    index.document("1").add({ :text => "some text here" })
    index.document("2").add({ :text => "some other text" })
    index.document("3").add({ :text => "something else here" })

    # Search the index
    results = index.search("some")

    print "#{results['matches']} documents found\n"
    results['results'].each { |doc|
        print "docid: #{doc['docid']}\n"
    }
rescue
    print "Error: ",$!,"\n"
end

Testing your application

Using the code above, you should be able to test your application both locally and running on Heroku. Keep in mind that your tests affect the live index. You can delete and re-create your index anytime to clean it up, either from the code as shown below or from Searchify's dashboard:

  Deleting an index

client = IndexTank::Client.new(ENV['SEARCHIFY_API_URL'] || '')
index = client.indexes('')
index.delete()

  Creating a new index

client = IndexTank::Client.new(ENV['SEARCHIFY_API_URL'] || '')
index = client.indexes('')
index.add()

print "Waiting for index to be ready"
while not index.running?
    print "."
    STDOUT.flush
    sleep 0.5
end
print "\\n"
STDOUT.flush

Pushing to Heroku

You should be able to use Searchify from within your application running on Heroku after the usual push commands:

$ git commit
$ git push heroku master

Further reading

To continue learning about how to manage your index, please read our Ruby Client documentation to see sample code about other features such as faceting and geolocation.

Complete documentation is available on our main page.