Add stemming, stopwords, and TF-IDF to search index#33
Merged
Conversation
Co-authored-by: iwillspeak <1004401+iwillspeak@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for stemming and stopword removal in search
Add stemming, stopwords, and TF-IDF to search index
Mar 6, 2026
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.
Search only matched exact words, making
compile/compiler/compilersthree separate non-overlapping terms. Common words bloated the index and all terms were weighted by raw frequency with no cross-document normalisation.Index build (
src/search.rs)binary_search; tokens < 3 chars are also droppedrust-stemmers; stored key is the stem (compile→compil,compilers→compil)write_search_indicescollects all pages, builds a per-term document-frequency map, pre-computes an IDF map (ln((1+N)/(1+df))), then writesTF × IDFweights; terms appearing in every page get IDF ≤ 0 and are omitted entirelyQuery side (
assets/search.js)Embeds a self-contained Porter 1 stemmer. Query tokens < 3 chars are dropped and the rest are stemmed before index lookup, keeping client and server in sync:
Tests
search.rs: new cases for stemming merging word forms, stopword exclusion, and short-token exclusiondoctree.rs: assertions updated to stemmed key forms ("distance"→"distanc","orange"→"orang")Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.