Moodle global search on Meilisearch
Moodle's global search needs Solr or a slow database engine. Our free search_meilisearch runs it on Meilisearch: one small server, typo-tolerant, no Java.
Short answer: Moodle’s global search (the search box in the page header) can search every forum post, page, book and glossary a user is allowed to see. Out of the box it runs on the database, which is slow and literal on a big site, or on Solr, which means running and tuning a Java server. Our free plugin, search_meilisearch, runs it on Meilisearch instead: an open source search engine that is a single small program, forgives typos and answers in milliseconds.
This is the eighteenth plugin in our series: one plugin for each Moodle plugin type, each one teaching DevLMS Studio, our AI plugin builder, how that type works. We checked the Moodle plugins directory first: it lists five search engines (Elastic, Typesense, Algolia, Azure and Postgres full text), and none for Meilisearch.
Setting it up
- Run Meilisearch with a master key, for example with Docker:
docker run -d -p 127.0.0.1:7700:7700 -e MEILI_MASTER_KEY='a-long-random-key' -v meili_data:/meili_data getmeili/meilisearch:v1.57.0. - In Moodle, Site administration > Plugins > Search > Meilisearch: enter the server URL, the key and an index name.
- In Manage global search, choose Meilisearch as the engine, enable global search, and let the indexing task run.
Searches then forgive small typos (“photosyntesis” finds photosynthesis), keep words in double quotes together, and leave out words with a minus sign. It supports Moodle 4.5 LTS to 5.3. The code is on GitHub.
Permissions come first
A search engine for Moodle has one job that matters more than speed: never show a student something they cannot open. Meilisearch first narrows results to the courses and activities the user can reach and to documents that are not private to someone else. Then Moodle checks every result again before showing it, like with any other engine. If results are dropped by that check, the plugin reads further pages, so a page of results stays full.
How a search engine plugin works
From Moodle 5.3’s own Solr and database engines:
- A search engine is one class that stores the documents Moodle’s search areas produce and answers queries with filters for the user’s contexts, courses, areas and dates.
- Meilisearch could not guess the id field of Moodle’s documents, because other fields (areaid, contextid) also end in “id”. The plugin creates the index itself with the right key and settings.
- Meilisearch saves documents in the background. Searches see them about a second later, so the tests wait for that before searching.
- Moodle blocks web requests to private addresses by default, and a search server usually lives on one. Only site administrators can set the server address, so the plugin skips that block for it, as Moodle’s Solr engine does.
We tested it against a real Meilisearch server: 12 PHPUnit tests (indexing, filters, private documents, deletes, batches, a wrong key) and a browser test in which a student’s forum post is indexed by Moodle’s own scheduled task and found from the header search box. GitHub runs the same tests with a Meilisearch server on every Moodle version.
Need a plugin like this for your own Moodle?
Describe it in DevLMS Studio and watch it built and tested in a real Moodle, or ask our team for a fixed price.
Open DevLMS Studio