Give each language edition its own search index - #25
Conversation
`mkdocs-static-i18n` merges every edition into one `search/search_index.json`, and Material resolves that file against `__config.base`, which is the site root on every page. Searching from a translated page therefore returns hits in the other languages, and the top results are often not in the language being read. Split the merged index per locale after the build and repoint `__config.base` on each edition's pages at the edition root — the only value Material derives the index URL from. The hook aborts the build when an edition ends up with no entries, when the merged index is absent, or when a page carries no `__config` script, so a change in any of those mechanisms fails loudly instead of silently restoring site-wide search. Ported from hatlabs/halpi2, where it is in production. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe PR adds an MkDocs post-build hook that splits the merged i18n search index into locale-specific indexes, updates locale search settings, rewrites translated page base paths, and preserves the default-language index. ChangesInternationalized search processing
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to The change gives each language edition its own search index and preserves the documented site behavior; the supplied validation is clean, so no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant MkDocs
participant on_post_build
participant MergedSearchIndex
participant LocaleSearchIndex
participant GeneratedPages
MkDocs->>on_post_build: Run post-build hook
on_post_build->>MergedSearchIndex: Read merged index
MergedSearchIndex-->>on_post_build: Return locale documents
on_post_build->>LocaleSearchIndex: Write per-locale index and stemmer settings
on_post_build->>GeneratedPages: Rewrite __config.base
on_post_build->>MergedSearchIndex: Retain default-language documents
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Searching from a translated page returns hits in the other nine languages.
mkdocs-static-i18nmerges every edition into onesearch/search_index.jsonby design, and Material resolves that file asnew URL("search/search_index.json", __config.base)wherebaseis the site root on every page, translated or not. Itsreconfigure_searchoption does not separate them — it only adds each locale to lunr'slanglist and drops duplicates.hooks/i18n_search.pysplits the merged index by locale after the build, strips the locale prefix from each entry'slocation, and repoints__config.baseon that edition's pages at the edition root.baseappears three times in the whole Material bundle: twice for the search index URL, once for a sitemap stream only subscribed undernavigation.instant, which this site does not enable — so the repoint changes nothing but search.Measured here after the change:
langnbfalls back toen, which has no lunr stemmer)mkdocs build --strictclean,check_anchors.py siteresolving 1220 links across 82 pages, and every locale page carries the edition-rootbase— checked programmatically against the expected depth rather than by eye.The hook fails the build when an edition ends up with no entries, when the merged index is missing, or when a page carries no
__configscript. Those are the three ways it could silently revert to site-wide search while the build stayed green; each guard was exercised on halpi2 rather than assumed.Ported unchanged from
hatlabs/halpi2, where it has been in production since this morning —docs.hatlabs.fi/halpi2serves per-edition indexes now.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes