DEV Community

Emma Donery
Emma Donery

Posted on • Updated on

MeiliSearch: Next generation search API

Image description

For a long time, medium-sized datasets and smaller applications have gone through the nightmare of using insufficient search engines, which result in hidden costs in terms of user experience and retention due to poor search fulfillment.There are numerous search engines available on the internet, both open-source and commercial. Choosing the ideal search solution for your project is crucial, but it's also complicated. In this article, i am going to discuss why Meilisearch is the suitable choice among other search engines.

What is MeiliSearch?πŸ€”

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. It is a REST-based search API. It intends to be a ready-to-use solution for everyone who wishes to give a speedy and relevant search experience to their end-users.

  • Created by Meili SAS company based in paris in 2018
  • It is an open source search engine

It promises:

  • Blazingly fast and relevant search experience for the end user
  • Is scalable, mantainable, customizable and that is easy to get it setup for developers.

Image description

Why MeiliSearch ?

It is a free, open-source solution that can be used by anybody and is tailored to meet a variety of needs. It requires very little setting upon installation, but it is highly customizable. With features like typo correction, filters, custom ranks, and more, it gives an immediate search experience.

Features of MeiliSearchπŸ’‘

  • Search as you type - Also known as "quick search." While you're still typing in your query, you'll get results. When you type more text into the search box, the displayed results alter in real time.

  • Ultra relevant - MeiliSearch's default relevancy rules are designed to give a simple search experience with minimal setup. They can be tinkered with to get the best results for your dataset.

  • Typo tolerant - MeiliSearch will always find the results you're looking for, rather than letting typos ruin your search.

  • Synonyms - Synonyms allow you to make your search experience more personalized and intuitive.

  • Highlighting - Highlight query phrases to make matches stand out. It is not necessary for users to read the complete paragraph in order to find a match.

  • Filters - MeiliSearch allows you to apply filters to your search results to reduce them down based on user-defined criteria.

  • Faceting - It aids in the classification of search results and the creation of user-friendly navigation interfaces.

  • Sorting - By sorting search results at query time, users can pick which sorts of results they want to see first.

  • Placeholder search - If you search without any query words, MeiliSearch will return all of the documents in that index, organized by its custom ranking rules.

  • Phrase search - MeiliSearch will only return documents that contain your search phrases in the order you specify if you use double quotes (") around them. As a result, users will be able to conduct more precise searches.

  • API key management - The usage of API keys in MeiliSearch allows you to secure your instances. You may control which users have access to specific indexes, routes, and endpoints using API keys.

  • Comprehensive language support - MeiliSearch is a multilingual search engine! Every language spoken in the global community will be supported.

Module's Architecture

Divided into two main parts:

  • Service, which servers as a wrapper for MeiliSearch PHP library. It's purpose is making API calls to the MeiliSearch server.
  • Search API backend plugin extends the functionality of the search API module and provides a backend on which you can attach indexes.

Demo of SearchAPI MeiliSearch

Installation

There are many ways to install and run meilisearch. Be sure to check them out.

NB: you can also download MeiliSearch from Homebrew or APT or cURL or others. The link on how to install using all these ways is attached.

In this article, i will install using the pip3 commandline:

$ pip3 install meilisearch
Enter fullscreen mode Exit fullscreen mode

Getting Started : MeiliSearch Python

Add Documents

import meilisearch

client = meilisearch.Client('http://127.0.0.1:7700', 'masterKey')

# An index is where the documents are stored.
index = client.index('books')

documents = [
  { 'book_id': 123,  'title': 'Pride and Prejudice' },
  { 'book_id': 456,  'title': 'Le Petit Prince' },
  { 'book_id': 1,    'title': 'Alice In Wonderland' },
  { 'book_id': 1344, 'title': 'The Hobbit' },
  { 'book_id': 4,    'title': 'Harry Potter and the Half-Blood Prince' },
  { 'book_id': 42,   'title': 'The Hitchhiker\'s Guide to the Galaxy' }
]

# If the index 'books' does not exist, MeiliSearch creates it when you first add the documents.
index.add_documents(documents) # => { "updateId": 0 }
Enter fullscreen mode Exit fullscreen mode

Basic Search

# MeiliSearch is typo-tolerant:
index.search('harry pottre')
Enter fullscreen mode Exit fullscreen mode

Output

{
  "hits" => [{
    "book_id" => 4,
    "title" => "Harry Potter and the Half-Blood Prince"
  }],
  "offset" => 0,
  "limit" => 20,
  "processingTimeMs" => 1,
  "query" => "harry pottre"
}
Enter fullscreen mode Exit fullscreen mode

Custom Search

index.search(
  'prince',
  {
    'attributesToHighlight': ['title'],
    'filters': 'book_id > 10'
  }
)
Enter fullscreen mode Exit fullscreen mode

Output

{
    "hits": [
        {
            "book_id": 456,
            "title": "Le Petit Prince",
            "_formatted": {
                "book_id": 456,
                "title": "Le Petit <em>Prince</em>"
            }
        }
    ],
    "offset": 0,
    "limit": 20,
    "processingTimeMs": 10,
    "query": "prince"
}
Enter fullscreen mode Exit fullscreen mode

Module compatibility

  • meilisearch - v0.18.1

Take away

MeiliSearch comes with a lot of customizing options. These customizing choices, unlike those offered by other search engines, are only that: optional. Try out MeiliSearch now. Thank me later.

Feel free to connect with me on Twitter or LinkedIn. Please feel free to leave a feedback on the comment section.

Top comments (0)