Type a word into any search box — the results appear before your finger leaves the key. Billions of documents. Milliseconds. How?
The naive answer is embarrassingly wrong: read every document, check if the word is there, repeat. For a billion pages that would take minutes even on the fastest hardware. Nobody does this.
The real answer is a pre-built map called an inverted index. Instead of "document → words it contains," you flip it: word → list of documents that contain it. Each entry in that list is called a postings list, and each item in the list is a posting — a document identifier, sometimes with extra data like the word's position or how often it appears.
Building the index is expensive — you read every document exactly once, tokenize it, and record where each token appears. But once the index is built, answering a query is just a lookup: find the term, grab its postings list. For a multi-word query you intersect the lists of each term. Intersection of two sorted lists of length and takes time — fast, regardless of how many documents you never had to touch.
The inverted index is not a new idea. Early information-retrieval systems from the 1960s used it. What changed is scale: modern engines hold indexes measured in petabytes, sharded across thousands of machines. The core idea, however, is identical to what you will build in the demo below.
Comments
Loading comments...