Skip to content

Make search find stop words like 'while', 'if', 'for' and 'from' - #80

Merged
shenxianpeng merged 3 commits into
mainfrom
claude/mkdocs-issue-4167-15dhse
Aug 9, 2026
Merged

Make search find stop words like 'while', 'if', 'for' and 'from'#80
shenxianpeng merged 3 commits into
mainfrom
claude/mkdocs-issue-4167-15dhse

Conversation

@shenxianpeng

Copy link
Copy Markdown
Member

Searching for words that happen to be English stop words (while, if, for, from, when, ...) returned no results, because lunr.js filters them out of the search index. These words are meaningful keywords in technical documentation, so the built-in search plugin now keeps them in the index by default.

This adds a stop_words boolean option to the search plugin (default false). Setting stop_words: true restores the previous filtering behavior. The option is honored by all three index build paths:

  • the default in-browser index build (worker.js)
  • prebuild_index: node (prebuild-index.js)
  • prebuild_index: python (lunr.py)

For non-English / multi-language configurations, the language-specific stop word filters are removed as well.

Note: queries shorter than min_search_length (default 3) are still ignored, so two-letter keywords such as if or in additionally require min_search_length: 2. This is called out in the new documentation section.

Verified end-to-end by building a test site and querying the index with the bundled lunr.js for each combination of stop_words × build path (in-browser, node prebuild, python prebuild), plus an en+fr multi-language build.

Related Issue

Fixes mkdocs/mkdocs#4167 (upstream issue; upstream is no longer maintained).

Checklist

  • New tests added for new behavior (if applicable)
  • Documentation updated (if applicable)
  • Release notes docs/about/release-notes.md updated (if applicable)

🤖 Generated with Claude Code

https://claude.ai/code/session_018Hw7x9BxxpuKiLkzjLczp9


Generated by Claude Code

lunr.js applies an English stop word filter when building the search
index, so searching for words that happen to be English stop words
returned no results, even though many of them (while, if, for, from,
when, ...) are meaningful keywords in technical documentation.

Add a 'stop_words' option to the search plugin and disable stop word
filtering by default, keeping those words searchable. Setting
'stop_words: true' restores the previous behavior. The option is
honored by all three index build paths: the in-browser build
(worker.js), 'prebuild_index: node' (prebuild-index.js) and
'prebuild_index: python' (lunr.py).

Note that queries shorter than 'min_search_length' (default 3) are
still ignored, so two-letter keywords such as 'if' or 'in' also require
lowering that option.

Fixes upstream issue mkdocs/mkdocs#4167.
@shenxianpeng shenxianpeng added the enhancement New feature or request label Aug 9, 2026
@shenxianpeng shenxianpeng added this to the v1.8.0 milestone Aug 9, 2026
@shenxianpeng
shenxianpeng merged commit 22504d7 into main Aug 9, 2026
21 checks passed
@shenxianpeng
shenxianpeng deleted the claude/mkdocs-issue-4167-15dhse branch August 9, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Searching for words that match Python keywords won't return anything

1 participant