IndexDen

This add-on is operated by IndexDen

hosted, super-fast, full-text search engine tuned for searching textual data

IndexDen

Last Updated: 19 March 2014

The IndexDen add-on is currently in beta.

Table of Contents

IndexDen is an add-on that provides hosted full-text search.

IndexDen allows developers to easily add search to their applications, without having to deal with Solr or Lucene, and without the hassle of managing your own search infrastructure. IndexDen is fast. Most search queries will be answered in under 100 milliseconds. IndexDen offers true real-time search, so documents added are immediately searchable. IndexDen is a drop-in replacement for existing IndexTank users.

IndexDen has client libraries for Ruby, Python, Java, PHP, and others, all of which communicate with IndexDen’s REST API.

Installing the add-on

IndexDen can be attached to a Heroku application via the CLI:

A list of all plans available can be found here.

$ heroku addons:add indexden
-----> Adding indexden to mycoolapp... done

This will create an account on IndexDen associated with the Heroku user, with one empty index called “idx”. You may use this “idx” index or delete it and create a new one anytime.

Once IndexDen has been added a INDEXDEN_API_URL setting will be available in the app configuration and will contain the private API URL used to access the newly-provisioned IndexDen service from within your application. This can be confirmed using the heroku config command.

$ heroku config | grep INDEXDEN_API_URL
INDEXDEN_API_URL    => http://:secret@xyz.api.indexden.com

After installing IndexDen the application should be configured to fully integrate with the add-on.

Local workstation setup

After provisioning the add-on it’s necessary to locally replicate the config vars so your development environment can operate against the service.

Though less portable it’s also possible to set local environment variables using export INDEXDEN_API_URL=http://....

Use Foreman to configure, run and manage process types specified in your app’s Procfile. Foreman reads configuration variables from an .env file. Use the following command to add the INDEXDEN_API_URL values retrieved from heroku config to .env.

$ heroku config -s | grep INDEXDEN_API_URL >> .env
$ more .env

Credentials and other sensitive configuration values should not be committed to source-control. In Git exclude the .env file with: echo .env >> .gitignore.

Use with Ruby

Installing the IndexTank Gem (Ruby)

Ruby/Rails applications should add the following entry into their Gemfile specifying the IndexTank client library required to access IndexDen:

$ gem 'indextank'

For local development, install the indextank gem:

$ gem install indextank

Now the client can be used to add documents to your index and perform searches. The following code sample demonstrates basic document indexing and searching, and may be copied for use in apps you develop.

require 'rubygems'
require 'indextank'

# Obtain an IndexTank client
client = IndexTank::Client.new(ENV['INDEXDEN_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

Deleting an index

client = IndexTank::Client.new(ENV['INDEXDEN_API_URL'] || '<API_URL>')
index = client.indexes('<INDEX_NAME>')
index.delete()

Creating a new index

client = IndexTank::Client.new(ENV['INDEXDEN_API_URL'] || '<API_URL>')
index = client.indexes('<INDEX_NAME>')
index.add()

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

Further Reading

For more information on Ruby client library please see the Ruby client documentation. Also you can checkout Ruby client tutorial

Use with Python

Instantiate the Client

Import the IndexDen client library to the Python interpreter by typing the following command at the Python prompt:

import indextank.client as itc
url_str = os.environ.get('INDEXDEN_API_URL', 'YOUR_API_URL')
api_client = itc.ApiClient(url_str)

Now the client can be used to add documents to your index and perform searches. The following code sample demonstrates basic document indexing and searching, and may be copied for use in apps you develop.

import indextank.client as itc
url_str = os.environ.get('INDEXDEN_API_URL', 'YOUR_API_URL')
api_client = itc.ApiClient(url_str)

test_index = api_client.get_index('<INDEX_NAME>')
test_index.add_document('post1', {'text':'I love Bioshock'})
test_index.add_document('post2', {'text':'Need cheats for Bioshock'})
test_index.add_document('post3', {'text':'I love Tetris'})

test_index.search('Bioshock OR Tetris')

Deleting an index

import indextank.client as itc
url_str = os.environ.get('INDEXDEN_API_URL', 'YOUR_API_URL')
api_client = itc.ApiClient(url_str)
api_client.delete_index('<INDEX_NAME>')

Creating a new index

import indextank.client as itc
url_str = os.environ.get('INDEXDEN_API_URL', 'YOUR_API_URL')
api_client = itc.ApiClient(url_str)

index = api_client.create_index('<INDEX_NAME>')

Further Reading

For more information on Python client library please see the Python client documentation. Also you can checkout Python client tutorial

Use with Java

Instantiate the Client

If you already have created an index you’ll need to use your index name to instantiate the client:

import com.flaptor.indextank.apiclient.IndexTankClient;
import com.flaptor.indextank.apiclient.IndexTankClient.Index;
import com.flaptor.indextank.apiclient.IndexTankClient.Query;

String uri = System.getenv("INDEXDEN_API_URL");
if (uri == null) uri = "<YOUR API URL HERE>";
IndexTankClient client = new IndexTankClient(uri);
Index index = client.getIndex("<INDEX_NAME>");

Now the client can be used to add documents to your index and perform searches. The following code sample demonstrates basic document indexing and searching, and may be copied for use in apps you develop.

import com.flaptor.indextank.apiclient.IndexTankClient;
import com.flaptor.indextank.apiclient.IndexTankClient.Index;
import com.flaptor.indextank.apiclient.IndexTankClient.Query;
import com.flaptor.indextank.apiclient.IndexTankClient.SearchResults;

String uri = System.getenv("INDEXDEN_API_URL");
if (uri == null) uri = "<YOUR API URL HERE>";
IndexTankClient client = new IndexTankClient(uri);
Index index = client.getIndex("<INDEX_NAME>");

String documentId = "<YOUR DOCUMENT ID>";
String documentText = "<THE TEXTUAL CONTENT>";

Map<String, String> fields = new HashMap<String, String>();
fields.put("text", documentText);

index.addDocument(documentId, fields);

String query = "<YOUR QUERY STRING>";

SearchResults results = index.search(Query.forString(query));

System.out.println("Matches: " + results.matches);

for (Map<String, Object> document : results.results) {
    System.out.println("doc id: " + document.get("docid"));
}

Deleting an index

String uri = System.getenv("INDEXDEN_API_URL");
if (uri == null) uri = "<YOUR API URL HERE>";
IndexTankClient client = new IndexTankClient(uri);
client.deleteIndex("test_name");

Creating a new index

String uri = System.getenv("INDEXDEN_API_URL");
if (uri == null) uri = "<YOUR API URL HERE>";
IndexTankClient client = new IndexTankClient(uri);
Index index = client.createIndex("<INDEX_NAME>");

Further Reading

For more information on Java client library please see the Java client documentation.

Testing your application

Using the code pattern above, you should be able to test applications both locally and running on Heroku. Keep in mind that your tests affect the live index. An index may be deleted and re-created anytime to clean it up, either from code as shown below or from IndexDen’s dashboard:

Pushing to Heroku

You should be able to use IndexDen from within applications running on Heroku after the usual push commands:

$ git commit
$ git push heroku master

Migrating between plans

If you require a plan larger than those listed, we can provide custom plans. Please contact us at indexden@indexden.com.

If you outgrow the limits of your current IndexDen plan, it’s easy to change to a larger plan. Any data in your search indexes is preserved – no data is lost.

Use the CLI to migrate to a new plan.

$ heroku addons:upgrade indexden:plus
-----> Upgrading indexden:plus to myapp... done ($49/mo)
       Your plan has been updated to: indexden:plus

Dashboard

The IndexDen dashboard allows you to manage indexes, allowing you to create, delete, and search indexes. Custom scoring functions can also be configured. The dashboard can be accessed by visiting the Heroku apps web interface and selecting IndexDen from the add-ons menu.

Further Reading

For more information on the features available from IndexDen, including faceting, geolocation, snippets, autocomplete, and custom scoring functions, please see the documentation at www.indexden.com/documentation.