Adding Full-Text Search to MkDocs
A docs site without working search forces readers to guess at nav paths, and the larger the site the worse the guessing gets. MkDocs ships a client-side search that is genuinely good up to a point, and swaps to a server-backed index when a site outgrows it. This how-to configures the built-in search well, then shows when and how to move to a heavier backend. It extends MkDocs for Internal Docs within Developer Portal Architecture & Frameworks.
Prerequisites
- MkDocs with Material for MkDocs installed, which provides the richest search experience.
- A site large enough that nav alone is not enough — typically dozens of pages or more.
- If you plan to move beyond client-side search, a place to host an index (a small service or a hosted search product).
- Content written with real headings, since search quality depends on document structure.
Exact Configuration
-
Enable and tune the built-in search plugin. Material’s search supports separators, prebuilt indexing, and language tuning.
# mkdocs.yml # Requires mkdocs-material >= 9.0 plugins: - search: separator: '[\s\-,:!=\[\]()"/]+|(?!\b)(?=[A-Z][a-z])' lang: - en theme: name: material features: - search.suggest - search.highlight - search.share -
Boost important pages with front-matter so key docs rank first.
--- search: boost: 3 --- # Getting Started -
When client-side search stops scaling, exclude the built-in index and point at a backend instead.
# mkdocs.yml — large sites moving to a hosted index plugins: - search: # keep for local dev; disable indexing in CI build for prod prebuild_index: true
Validation
# Requires a built site and python
# 1. The search index was generated
mkdocs build && test -f site/search/search_index.json && echo "index present"
# Expected: index present
# 2. The index contains a term you know exists
grep -q "onboarding" site/search/search_index.json && echo "term indexed"
# Expected: term indexed
# 3. Index size is sane for client-side search
du -h site/search/search_index.json
# Expected: comfortably under ~1MB; larger suggests moving to a backend
Edge Cases & Troubleshooting
| Symptom | Root Cause | Resolution |
|---|---|---|
| Search finds nothing | Plugin disabled or index not built | Confirm search is in plugins; rebuild |
| CamelCase terms not matched | Default separator does not split them | Add the camel-split pattern to separator |
| Search slow on first query | Large index downloaded lazily | Enable prebuild_index, or move to a backend |
| Non-English terms missed | Language not configured | Add the language code under lang |
| Irrelevant page ranks first | No boosting | Add search.boost front-matter to key pages |
Frequently Asked Questions
Do I need an external search service at all?
Most internal docs sites never do. Material’s client-side search is fast and offline-friendly up to hundreds of pages, and it needs zero infrastructure. Only reach for a backend when the index grows large enough to slow the first query, or when you want to unify docs search with the wider portal search covered elsewhere in the portal.
How does this relate to portal-wide search?
MkDocs search covers one docs site; portal-wide search indexes docs alongside services and APIs. When docs are published through TechDocs, the portal’s own collators index them into the shared search, so this page’s tuning matters most for the standalone MkDocs experience rather than the unified portal box.