Skip to content
ferhatsb edited this page Jun 27, 2012 · 3 revisions

HoundSleuth 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 HoundSleuth in your application, adding real-time search with very little effort.

The HoundSleuth Add-on leverages existing IndexTank libraries to provide clients for Ruby, Python, Java and PHP.

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 addon page to see the different plans available. Then run the following command, replacing with the name of the plan you chose:

$ heroku addons:add houndsleuth:<PLAN>

This will create an account on HoundSleuth 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 HOUNDSLEUTH_URL is your private key that you can use to talk to the IndexTank service from within your application. You only need it when you are running locally (not on Heroku).

You will also need to install the HoundSleuth IndexTank-API gem to develop locally.

Installing the HoundSleuth IndexTank-API gem

$ gem install indextank

Now you can use the HoundSleuth IndexTank-API 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 HOUNDSLEUTH_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['HOUNDSLEUTH_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 your HoundSleuth dashboard in Heroku:

Deleting an index

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

Creating a new index

client = IndexTank::Client.new(ENV['HOUNDSLEUTH_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 HoundSleuth 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.