Meilisearch video tutorial: Discovering Meilisearch

In this video I invite you to discover Meilisearch, a tool that will allow you to set up a fast and efficient search system for your site / application.

Written in Rust, this tool comes in the form of a simple executable (running on Windows, Mac and Linux) which will start a database with which it will be possible to communicate through an HTTP API. This API can also be secured thanks to a system of keys and permissions.

Features

By default, Meilisearch offers most of the functionality one may need to set up a search system on a site.

These features make Meilisearch a good solution for setting up a secondary database that serves as the basis for setting up search functionality.

Restrictions

Like many tools, certain compromises have been made in the design of Meilisearch in order to provide the desired functionality. These compromises lead to limitations that must be known to avoid unpleasant surprises. To sum up

  • Searches cannot contain more than 10 words.
  • Texts cannot contain more than 65,535 words.
  • The server cannot receive more than 1024 simultaneous requests.
  • Values ​​in filterable fields cannot exceed 500 bytes.
  • By default, a maximum of 1000 results will be returned.
  • The index cannot exceed 500GB.

These limitations will mainly concern applications that have a very large amount of information to store, but at this stage it is worth investing in a more complex solution / adapted to these needs.

Next, it’s important to note that most API entry points are asynchronous and just return a task, which can be troublesome for capturing errors.

Comparison

Now, one can wonder the place of Meilisearch with respect to what already exists in terms of research-oriented databases. The documentation offers a comparative table with respect to the different solutions (be careful, the table risks being oriented in favor of Meilisearch since they are the author).

PostgreSQL and MySQL

It is possible to obtain full text search functionalities with classic relational databases (with MATCH AGAINST for Mysql and search type for PostgreSQL). Unfortunately, the operation is not necessarily obvious with complex SQL queries.

/** Création du vecteur de recherche lors d'une mise à jour **/
CREATE FUNCTION update_forum_document() RETURNS trigger AS $$
begin 
    new.search_vector := setweight(to_tsvector('french', coalesce(new.name, '')), 'A')
|| setweight(to_tsvector('french', coalesce(new.content, '')), 'B');
return new;
end
$$ LANGUAGE plpgsql;
CREATE TRIGGER update_forum_document_trigger BEFORE INSERT OR UPDATE ON forum_topic FOR EACH ROW EXECUTE PROCEDURE update_forum_document();

/* Requête de recherche */
SELECT 
    ts_headline('french', content, $tsQuery, 'MaxWords=70, MinWords=30, StartSel=<mark>, StopSel=</mark>') as excerpt,
    t.id,
    ts_headline('french', name, $tsQuery, 'MaxWords=70, MinWords=30, StartSel=<mark>, StopSel=</mark>') as name,
    t.solved,
    t.message_count,
    t.created_at,
FROM forum_topic t
WHERE t.search_vector @@ $tsQuery
ORDER BY ts_rank(t.search_vector, $tsQuery) DESC
OFFSET :offset
LIMIT 10

In addition to that, by default searches are often slow and require a lot of optimizations to have a satisfactory result.

ElasticSearch

ElasticSearch remains the reference tool when talking about research, but its use is in my opinion much too complex for simple cases. This complexity often translates, due to a lack of expertise, into a poorly configured and inefficient index (which results in a search that does not find the right results…).

Typesense

Typesense offers a solution similar to Meilisearch with a simple executable (written in Golang) and an HTTP API. However Typesense is not yet available in a stable version. Also, its use seemed a little more complex to me because of the need to create the diagrams upstream and I had some problems during my short experience with the tool (to see how it evolves).

  • Data is stored in memory (which can be limiting)
  • Limited control for highlighting keywords and cropping text around the highlight.

Algolia

Algolia is a third-party service specializing in research. Unfortunately, it is not possible to host their solution, which makes them dependent on their service. With Meilisearch you can choose whether or not to use their cloud service (which also seems cheaper than Algolia).