Rust · inverted index · TF-IDF
Trailhead is a full-text search engine in Rust, built from scratch and small enough to read end to end. Tokenizer, inverted index, TF-IDF ranking, no black box. Here is the real thing, running in your browser.
tokenized, indexed, and ranked entirely in this page
Four pieces turn a folder of text files into ranked search results.
Lowercases text, splits on non-alphanumeric characters, and optionally filters a small stopword list.
Maps each term to the documents it appears in, with per-document term counts, so lookups skip everything that does not match.
Scores documents by term frequency times inverse document frequency, so rare and repeated terms carry more weight.
Two commands, index a directory of text files, then search it with a ranked top-N list of results.
The index is saved as plain JSON so you can open it and see exactly what got indexed.
trailhead index ./my-notes trailhead search "inverted index ranking" --top 5