Make search find stop words like 'while', 'if', 'for' and 'from' - #80
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_wordsboolean option to the search plugin (defaultfalse). Settingstop_words: truerestores the previous filtering behavior. The option is honored by all three index build paths: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 asiforinadditionally requiremin_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 anen+frmulti-language build.Related Issue
Fixes mkdocs/mkdocs#4167 (upstream issue; upstream is no longer maintained).
Checklist
docs/about/release-notes.mdupdated (if applicable)🤖 Generated with Claude Code
https://claude.ai/code/session_018Hw7x9BxxpuKiLkzjLczp9
Generated by Claude Code