Skip to main content

A MeiliSearch backend for Wagatil

Project description

Wagtail MeiliSearch

This is a (beta) Wagtail search backend for the MeiliSearch search engine.

Installation

poetry add wagtail_meilisearch or pip install wagtail_meilisearch

Configuration

See the MeiliSearch docs for info on the values you want to add here.

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail_meilisearch.backend',
        'HOST': os.environ.get('MEILISEARCH_HOST', 'http://127.0.0.1'),
        'PORT': os.environ.get('MEILISEARCH_PORT', '7700'),
        'MASTER_KEY': os.environ.get('MEILI_MASTER_KEY', '')
    },
}

Update strategies

Indexing a very large site with python manage.py update_index can be pretty taxing on the CPU, take quite a long time, and reduce the responsiveness of the MeiliSearch server. Wagtail-MeiliSearch offers two update strategies, soft and hard. The default, soft strategy will do an "add or update" call for each document sent to it, while the hard strategy will delete every document in the index and then replace them.

There are tradeoffs with either strategy - hard will guarantee that your search data matches your model data, but be hard work on the CPU for longer. soft will be faster and less CPU intensive, but if a field is removed from your model between indexings, that field data will remain in the search index.

One useful trick is to tell Wagtail that you have two search backends, with the default backend set to do soft updates that you can run nightly, and a second backend with hard updates that you can run less frequently.

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail_meilisearch.backend',
        'HOST': os.environ.get('MEILISEARCH_HOST', 'http://127.0.0.1'),
        'PORT': os.environ.get('MEILISEARCH_PORT', '7700'),
        'MASTER_KEY': os.environ.get('MEILI_MASTER_KEY', '')
    },
    'hard': {
        'BACKEND': 'wagtail_meilisearch.backend',
        'HOST': os.environ.get('MEILISEARCH_HOST', 'http://127.0.0.1'),
        'PORT': os.environ.get('MEILISEARCH_PORT', '7700'),
        'MASTER_KEY': os.environ.get('MEILI_MASTER_KEY', ''),
        'UPDATE_STRATEGY': 'hard'
    }
}

Stop Words

Stop words are words for which we don't want to place significance on their frequency. For instance, the search query tom and jerry would return far less relevant results if the word and was given the same importance as tom and jerry. There's a fairly sane list of English language stop words supplied, but you can also supply your own. This is particularly useful if you have a lot of content in any other language.

MY_STOP_WORDS = ['a', 'list', 'of', 'words']

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail_meilisearch.backend',
        [...]
        'STOP_WORDS': MY_STOP_WORDS
    },
}

Or alternatively, you can extend the built in list.

from wagtail_meilisearch.settings import STOP_WORDS

MY_STOP_WORDS = STOP_WORDS + WELSH_STOP_WORDS + FRENCH_STOP_WORDS

WAGTAILSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'wagtail_meilisearch.backend',
        [...]
        'STOP_WORDS': MY_STOP_WORDS
    },
}

Contributing

If you want to help with the development I'd be more than happy. The vast majority of the heavy lifting is done by MeiliSearch itself, but there is a TODO list...

TODO

  • Faceting
  • Implement boosting in the sort algorithm
  • Write tests
  • Performance improvements - particularly in the autocomplete query compiler which for some reason seems slower than the regular one.
  • Implement stop words
  • Search results
  • Add support for the autocomplete api
  • Ensure we're getting results by relevance

Thanks

Thank you to the devs of Wagtail-Whoosh. Reading the code over there was the only way I could work out how Wagtail Search backends are supposed to work.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail-meilisearch-0.1.3.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_meilisearch-0.1.3-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file wagtail-meilisearch-0.1.3.tar.gz.

File metadata

  • Download URL: wagtail-meilisearch-0.1.3.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for wagtail-meilisearch-0.1.3.tar.gz
Algorithm Hash digest
SHA256 43f003aa3c819d0a7129df9340b718c29bafa4f0f0fdd3a30cc98f691b65e73c
MD5 c29e4a2f52538998f517070d2b47cf7b
BLAKE2b-256 d1adde6c9b744cb462e785713fb030e9b78c65e7f03c3cadccf31decc01e9e15

See more details on using hashes here.

File details

Details for the file wagtail_meilisearch-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: wagtail_meilisearch-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.43.0 CPython/3.7.3

File hashes

Hashes for wagtail_meilisearch-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f271378e80b097fb7ce06d9a86f6f8f1c326fd0da5a3dc67584a8edd9ab291f2
MD5 b8a4e46d3759fc3f7280e141d63cff7f
BLAKE2b-256 d36eef1ac2215d5dd120c20da5709253a40905692105d48e62b11cd24618187c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page