Skip to content
Select theme

Write your own search engine

What you end up with: a search engine you can point at a folder of documents, that indexes them, ranks results the way Elasticsearch’s BM25 does, supports phrase queries, and answers over HTTP.

The finished engine: an index saved and reloaded, then queries ranked by BM25

Search is the most useful thing you can build once you understand indexes. It is also a topic where the theory and the code fit together unusually well: every ranking change is measurable against a real document set.

  • Tokenisation and normalisation (case folding, Unicode, stop words)
  • Stemming, and why “running” should match “run”
  • An inverted index stored on disk, with postings lists
  • BM25 scoring, with the parameters you can tune
  • Phrase queries and boolean filters
  • The same index served over HTTP with snapshot isolation for readers
  • An evaluation harness: precision, recall, and the queries your ranking gets wrong

Reading order matters more here: finish Collections and strings and Closures and iterators first — most of this track is data wrangling before it is search.