Anatomy of a search drew the inverted index as an idea: terms on the left, document lists on the right. This essay opens the hood. The idea only works because of three pieces of ruthless engineering: a term dictionary that finds one term among millions in a handful of steps, posting lists compressed to a few bits per entry, and intersections that skip instead of walk. Each one below is running live.
Before any posting list can be read, the term itself must be found, among tens of millions. Storing them as a sorted list would work; Lucene does something better: a finite state transducer (FST), a graph in which every term is a path, and shared beginnings and endings are stored once. Type to walk it, and press Enter to add your own term:
Found the term; now the list of documents. Stored naively, each document id costs 4 bytes, and a term appearing in 100 million documents costs 400 MB, for that one term. The fix exploits a gift: posting lists are sorted, so instead of ids you store the gaps between them, and small numbers need few bits. Lucene cuts the list into blocks of 128 gaps and packs each block at the width of its largest gap. Drag the term's popularity:
An AND query intersects two posting lists, and the naive way walks both, entry by entry. But the lists are sorted, and sorted data invites skip pointers: express lanes over every few entries. When one list says "my next document is 63," the other doesn't crawl toward 63, it leaps. How far apart should the lanes be? Find out:
Term dictionary, compressed postings, skip lists: three structures, one contract. Everything expensive happens once, at write time inside a segment; every query after that is arc walks, bit unpacks and leaps. And when the terms carry weights instead of just presence, these same lists power the ranking shortcuts in Ranking: the science of first.