algolia- A client implementing the Algolia search API

Safe HaskellNone



Algolia is not based on traditional search solutions like Lucene or Solr. Algolia was built from the ground up specifically for searching through semi-structured data to power user-facing search.

Speed In order to provide the best user experience, we focus on performance - milliseconds matter, and we developed an engine capable of delivering results in a few milliseconds, fast enough to power a seamless, “as-you-type” experience - the de facto consumer-grade search experience.

Our ability to achieve unparalleled speed relies on a multitude of factors, many of which are outlined in this blog post. For instance, the Algolia engine handles the vast majority of computation at indexing time, as opposed to at query time. Beyond this, we control the full stack end-to-end. We’ve obsessed over every detail, from obtaining high quality infrastructure (bare-metal servers!) to crafting our own Ubuntu-based OS painstakingly modified for search engine performance.

Beyond speed, we focus on providing all the features necessary to build a full-fledged search experience out-of-the-box: prefix search, typo-tolerance, faceting, highlighting, and more.


Performance is important; however, in order for search to be successful, results need to be relevant to the user. Varying from the traditional TF-IDF approach to relevancy, we built a modern tie-breaking algorithm tuned specifically for semi-structured data. Rather than calculating one “score” per result and sorting based solely off a magic number, Algolia calculates N scores and then applies N successive sorting. In layman’s terms, this means “buckets” of results are sorted by a cascade of varying criteria. When matches occur in the first criterion, the second criterion is considered to help break the tie, and so on in succession. This approach is meant to mimic how our brains naturally search for information - and as a consequence, is far easier to debug.

The Algolia engine provides various criteria for building stellar textual relevancy. On top of these, additional rules can be set to further hone the relevancy for a specific dataset. For example, a numeric “popularity” attribute could be leveraged as a potential tie-breaker rule to help more popular items rank higher. By enabling business relevance metrics to be added at will and via API, this forms the foundation for handling advanced search experiences like personalization, merchandising and more.



mkAlgoliaClient :: ApiKey -> ApplicationId -> AlgoliaClient Source #

Make an algolia client from the provided API key and application id.

newtype ApiKey Source #



simpleAlgolia :: (MonadIO m, Has AlgoliaClient c) => c -> ReaderT c m a -> m a Source #

Given a data type c that implements Has AlgoliaClient c, perform an algolia request.

algoliaFromEnv :: MonadIO m => ReaderT AlgoliaClient m a -> m a Source #

Create an algolia client from ALGOLIA_APP_ID and ALGOLIA_KEY environment variables.

type Result a = forall c m. (Has AlgoliaClient c, MonadReader c m, MonadThrow m, MonadIO m) => m a Source #

class Reconstrain f where Source #

Convert a coercible type f


reconstrain :: f a -> f b Source #

reconstrain :: Coercible (f a) (f b) => f a -> f b Source #

listIndices Source #


:: Maybe Int

Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When Nothing, will retrieve all indices (no pagination).

-> Result ListIndicesResponse 

List existing indexes.

generateSecuredApiKey :: ApiKey -> Query -> Maybe ByteString -> ByteString Source #

You may have a single index containing per-user data. In that case, you may wish to restrict access to the records of one particular user. Typically, all your records would be tagged with their associated user_id, and you would add a filter at query time like filters=user_id:${requested_id} to retrieve only what the querying user has access to.

Adding that filter directly from the frontend (browser or mobile application) will result in a security breach, because the user would be able to modify the filters you’ve set, e.g. by modifying the JavaScript code.

In order to keep sending the query from the browser (which is recommended for optimal latency) but only target secured records, you can generate secured API keys from your backend and use them in your frontend code. The backend will then automatically enforce the security filters contained in the key; the user will not be able to alter them.

A secured API key is used like any other API key via the X-Algolia-API-Key request header.

Generate a secured API key Secured API keys are generated by hashing (HMAC SHA-256) the following criteria together:

a private API key (can be any API Key that is not the admin API Key), used as the secret for HMAC SHA-256;

a URL-encoded list of query parameters defining the security filters.

The result of the hashing is concatenated to the URL-encoded query parameters, and this content is encoded in Base64 to generate the final secured API key.

searchIndex :: FromJSON a => IndexName a -> SearchParameters -> Result (SearchResults a) Source #

Return objects that match the query.

You can find the list of parameters that you can use in the POST body in the Search Parameters section.

Alternatively, parameters may be specified as a URL-encoded query string inside the params attribute.

deleteIndex :: IndexName a -> Result DeleteIndexResponse Source #

Delete an existing index.

clearIndex :: IndexName a -> Result IndexOperationResponse Source #

Delete an index’s content, but leave settings and index-specific API keys untouched.

addObjectWithoutId :: ToJSON a => IndexName a -> a -> Result (AddObjectWithoutIdResponse a) Source #

Add an object to the index, automatically assigning it an object ID.

addObjectById :: ToJSON a => IndexName a -> ObjectId a -> a -> Result (AddObjectByIdResponse a) Source #

Add or replace an object with a given object ID. If the object does not exist, it will be created. If it already exists, it will be replaced.

Be careful: when an object already exists for the specified object ID, the whole object is replaced: existing attributes that are not replaced are deleted.

If you want to update only part of an object, use a partial update instead.

retrieveObject Source #


:: FromJSON a 
=> IndexName a 
-> ObjectId a 
-> [Text]

Attributes to retrieve. An empty list denotes retriving all attributes. Note that the FromJSON instance might not succeed if you exclude attributes, so it might be necessary to use reconstrain on the index and id to use a different FromJSON instance

-> Result (Maybe (RetrieveObjectResponse a)) 

waitTask :: IndexName a -> TaskId -> Result () Source #

Wait for a task to be processed by Algolia

getTaskStatus :: IndexName a -> TaskId -> Result TaskStatusResult Source #

Get the status of a task. This can be used to wait for a task to be processed via polling.

See waitTask for an implementation of this behavior.

data SynonymType Source #



Multi-way synonyms (a.k.a. “regular synonyms”). A set of words or phrases that are all substitutable to one another. Any query containing one of them can match records containing any of them.


One-way synonym. Alternative matches for a given input. If the input appears inside a query, it will match records containing any of the defined synonyms. The opposite is not true: if a synonym appears in a query, it will not match records containing the input, nor the other synonyms.


Alternative corrections. Same as a one-way synonym, except that when matched, they will count as 1 (respectively 2) typos in the ranking formula.


A placeholder is a special text token that is placed inside records and can match many inputs. For more information on synonyms, please read our Synonyms guide.

data SynonymSearch Source #




searchSynonyms :: IndexName a -> SynonymSearch -> Result SynonymSearchResponse Source #

Search or browse all synonyms, optionally filtering them by type.

getLogs Source #


:: Maybe Int


-> Maybe Int


-> Maybe (IndexName a) 
-> Maybe LogType 
-> Result LogsResponse 

data AlgoliaError Source #


JsonParseError String

The response was a JSON value, but the library does not know how to handle it properly.

NonConformingResult Request (Response ()) Value String

The response was not JSON.


A JSON object was expected as the response, but it was some other JSON type.