Technical manuscript · 2026 edition

Building a search engine from first principles.

Every structure in this book is implemented here, in TypeScript, running in your browser — an inverted index over 28 real documents, BM25 with the arithmetic shown, Levenshtein automata, minimized automata, FSTs with outputs, BKD trees, a byte-level segment format with real checksums, and a cluster you can break.

Nothing on this site is a recorded screenshot. Every number is computed when you load the page, by the same engine the chapter is describing.

Build the simple version → discover the bottleneck → replace one component → understand why the advanced structure exists.

The two jobs

A search engine builds structures that make retrieval fast, then uses those structures to find and rank documents. Everything in the book sits on one side of that line or the other.

Build structures that make retrieval fast
Documents
Analysis
Terms
Term dictionary
Inverted index
Point index
Segments
Use them to find and rank
Query
Parse & analyze
Candidate retrieval
Filtering
BM25 scoring
Top K
Fetch

There is not one search data structure

This table is the spine of the whole book. Different questions need different structures, and confusing them is where most search bugs come from.

QuestionStructureChapter
Does this term exist?Term dictionary19
Which documents contain this term?Postings4
Where does the term occur?Positions5
What terms start with this prefix?Trie / FST / term dictionary16
Which terms are within edit distance 1?Levenshtein automaton + dictionary14
Which prices are between 100 and 200?Point index20
Which geo points are inside a region?BKD22
Which matching documents are most relevant?BM258
How is the index persisted?Segments / files23
How is it distributed?Shards / replicas31

FST is not postings. BKD is not a text dictionary. BM25 does not find documents; it scores candidates.

Thirteen parts, forty-three chapters

II

The First Search Engine

A hash map, a set of document ids, and suddenly you no longer scan every document.

VI

Term Dictionaries

Prefix sharing, then suffix sharing, then outputs. Each step is a measurable size reduction.

VII

Numeric & Spatial Search

Sorting solves one dimension. Two dimensions need you to partition space itself.

XI

Cluster & Operations

Refresh, flush and commit are three different promises. Failure is part of the architecture.

XIII

The Seeker Project

The build order, the testing strategy, and the map back to Lucene and OpenSearch.

The build order

Fifteen stages, each replacing exactly one component. Do not skip an intermediate structure merely because you already know the name of the final one — experience the problem first.

StageBuildReplace later withChapter
1documents + tokenizerreal analyzer3
2term → set(docID)compressed postings25
3positionsposition codecs5
4AND/OR/phraseiterator execution6
5toy scoreBM258
6sorted termstrie16
7trieminimized automaton17
8automaton + outputsFST18
9term blocksBlockTree-style dictionary19
10sorted numeric valuesBKD22
11simple filesversioned segment codec24
12file readsmmap reader26
13single nodeshards31
14shardsreplicas / recovery36
15basic metricsproduction observability40

Seeker — building a search engine from first principles. The goal is not to reproduce Lucene line for line; it is to make Lucene and OpenSearch understandable.

Reference documentation: lucene.apache.org · docs.opensearch.org