A search backend for Wagtail using MeiliSearch.
Caution
This package is still in development and until version 1.0.0, I will not maintain a DeprecationWarning pattern. I built the integration with meilisearch about 2 years ago for a project and decided to make it a public package to improve it and integrate more features.
Tip
If you need support or require help with a Wagtail project, you can hire me 😊
en - https://softquantum.com/resources/wagtailmeili-integrating-a-blazing-fast-search-engine-with-wagtail
Wagtailmeili requires the following:
- Python >= 3.11
- Wagtail >= 5.2
Install Meilisearch python client e.g., using pip
pip install meilisearch
Add wagtailmeili
to your INSTALLED_APPS
INSTALLED_APPS = [
# ...
"wagtailmeili",
# ...
]
add the search backend to your WAGTAILSEARCH_BACKENDS
import os
WAGTAILSEARCH_BACKENDS = {
"default": {
"BACKEND": "wagtailmeili.backend",
"HOST": os.environ.get("MEILISEARCH_HOST", "http://127.0.0.1"),
"PORT": os.environ.get("MEILISEARCH_PORT", "7700"),
"MASTER_KEY": os.environ.get("MEILISEARCH_MASTER_KEY", "your-master-key"),
# "STOP_WORDS": ...
# "RANKING_RULES: ...
# "SKIP_MODELS": ...
# "SKIP_MODELS_BY_FIELD_VALUE": ...
},
}
- STOP_WORDS: see defaults in settings.py
- RANKING_RULES: see defaults in settings.py
- SKIP_MODELS: "skip_models" is a list of models that you want to skip from indexing no matter the model setup.
WAGTAILSEARCH_BACKENDS = {
"default": {
"SKIP_MODELS": ["app_label.Model1", "app_label.Model2",],
# ...
}
}
- SKIP_MODELS_BY_FIELD_VALUE: A convenient way to skip instances based on attributes
WAGTAILSEARCH_BACKENDS = {
"default": {
# add this to not index pages that are not published for example
"SKIP_MODELS_BY_FIELD_VALUE": {
"wagtailmeili_testapp.MoviePage": {
"field": "live",
"value": False,
},
},
# ...
}
}
To declare sortable attributes or add ranking rules for the model, just add, for example:
from wagtail.models import Page
class MySuperPage(Page):
"""A Super Page to do incredible things."""
sortable_attributes = [
"published_last_timestamp",
# ...
]
ranking_rules = [
"published_last_timestamp:desc",
# ...
]
{% load meilisearch %}
{% get_matches_position result %}
-
Adding tests - Refactoring index.py to be with easier testing
- Exploring Meilisearch and bringing more of its features for Wagtail
- Getting a leaner implementation (looking at Autocomplete and rebuilder)
- Giving more love to the Sample project with a frontend
- official documentation
The Wagtail Movie Database (WMDB) is a sample project for testing purposes. To run the project, follow these steps:
- start the local meilisearch instance
meilisearch --master-key=<your masterKey>
- copy the directory wagtail_moviedb wherever you want
- create a virtualenv and activate it (instructions on linux/macOS)
python -m venv .venv
source .venv/bin/activate
- install the dependencies
pip install -r requirements.txt
- add an .env file
MEILISEARCH_MASTER_KEY="your masterKey"
- apply migrations
python manage.py migrate
- Create a superuser (optional)
python manage.py createsuperuser
- load movies & start local web server
python manage.py load_movies
python manage.py runserver
- visit your meilisearch local instance: https://127.0.0.1:7700, give it your master-key. You should see some movies loaded.
- update index (optional):
python manage.py update_index
Welcome to all contributions!
- Install Meilisearch locally following their documentation
- Start Meilisearch instance in your favorite terminal
meilisearch --master-key correctmasterkey
To make changes to this project, first clone this repository:
git clone git@github.com:softquantum/wagtailmeili.git
cd wagtailmeili
With your preferred virtualenv activated, install testing dependencies:
pip install "pip>=21.3"
pip install -e '.[dev]' -U
You can run tests as shown below:
pytest
or with tox
tox
This project is released under the 3-Clause BSD License.