By Kappa Category webdev
Tags meilisearch search pelican static site generator ssg blog
Estimated Read Time: 14 min read
Ninja Level:

Photo credit: SI Janko Ferlic (Unsplash license)
In my previous post, I mentioned about MeiliSearch. Let's have a short article on how to integrate it with my theme.
Edit: This post was edited for MeiliSearch version 0.13.
Part I: MeiliSearch
Meilisearch is written in Rust. Possible solutions for hosting it are VPS, serverless hosting and docker. Here is the link for official installation guide.
Steps for setting up Rust
- Get a release binary from the official web site
- Start up the service
There are three keys: master key, public key and private key. Specifying the master key and the public key and private key would be generated. Public key and private key are not shown in the console log if you start it in production mode. There are two ways to get the public key and private key:
- Start it as development mode to get the keys from the console log
- After starting in production mode, perform a query to get the public and private keys by providing your master key, like below
Each key has specific usage.
- The master key is used for starting the MeiliSearch server
- The public key is used by clients to authenticate with master server, for search queries. docs-searchbar.js would use this key
- The private key is used by developers to perform administrative tasks for MeiliSearch server. You should use the docs-scraper with this key
Part II: docs-scraper
docs-scraper is written in Python. Here is the link for the official installation guide. It supports installation with pipenv or Docker.
I would use pipenv to use it:
Here is a sample config for the docs_scraper.conf that I am using for my website.
Thanks to Clémentine, she explained to me about how to configure the docs scraper and provided some reference configuration. The related discussion is in here.
The above config is specific to my theme. It relies on the '.navbar-nav .active' classes. These are the active item in the top navigation bar, used as the selector.
Edit: For docs-scraper version 0.10.1. If you have problem running it like:
The problem is discussed in Github issue #61.
Here's my workaround. Use Scrapy version < 2.3.0
Part III: docs-searchbar.js
docs-searchbar.js is written in JavaScript. It is used in the front end or used by the client browser.
The docs-searchbar.js project website provides a simple example on how to use it. I had integrated it into my theme, the related source code or template is in GitHub.
Actually, the template was included in the base.html template. If the parameter MEILISEARCH is enabled or not empty (in pelicanconf.py), this template would be included. Also, the related JavaScript and CSS for doc-searchbar.js from CDN would also be included.
For pelicanconf.py, you need:
- For the SERVER_URL, point to your MeiliSearch Server. For production usage, it is recommended to enable HTTPS and use the standard TCP port 443.
- You should put your public key we had mentioned before into the template that call docs-seacherbar.js. You should not expose your master key or private key.
Now regenerate your static web pages in Pelican. You should be able to use the MeiliSearch. MeiliSearch is instant search and searches as you type.