Techโ—โ—โ—โ—โ—Difficulty 3 of 5

How can a search engine find one word among billions of pages in a blink?

It doesn't search the pages at all. Before you ever type, it has already turned the web inside out.

โ–ถ Start the story

A search engine answers quickly because it does not read the web when you search. It reads it beforehand, and writes down, for every word, a list of the pages where that word appears. When you type a word, it simply opens that word's list. This is called an , and it is the most popular data structure in document retrieval systems.

Think of the at the back of a textbook. You don't reread the whole book to find where "volcano" is mentioned; you look up the word and get page numbers. A search engine does the same with pages of the web instead of pages of a book. Without an index it would have to scan every document for every question: an index of 10,000 documents can be queried within milliseconds, while a scan of every word in 10,000 large documents could take hours.

The trick is in the name. First, the engine makes a forward , which stores a list of words for each document. Then it flips this around into an , which lists the documents for each word. A tiny made-up example: if page 1 says "cats purr", page 2 says "dogs bark" and page 3 says "cats and dogs", the entry for "cats" says pages 1 and 3.

The same three pages, two ways (a made-up example)

Forward index: words per page

  • Page 1: cats, purr
  • Page 2: dogs, bark
  • Page 3: cats, and, dogs

Inverted index: pages per word

  • cats: pages 1, 3
  • dogs: pages 2, 3
  • purr: page 1
  • bark: page 2

People were doing this long before computers. In pre-computer times, concordances to important books were assembled by hand, and they were effectively inverted indexes. A computer simply does the same job on a vast scale, and without tiring.

Quiz me

0/3

  1. 1.Why is the inverted index called "inverted"?
  2. 2.Why can a search engine answer in milliseconds instead of scanning pages?
  3. 3.What extra information lets an engine handle a phrase search in quotation marks?

Recap

A forward index lists the words in each page; flipping it gives the inverted index, which lists the pages for each word.

๐Ÿ’ก A trick to remember it ยท Like the index at the back of a book: look the word up, and out come the page numbers.

Surprising fact ยท Concordances made by hand for important books before computers were effectively inverted indexes.

Sources (2)

No source, no claim. Every fact in this lesson (13 claims) cites at least one of these.

  1. [1]Search engine indexing ยท Wikipedia
  2. [2]Inverted index ยท Wikipedia
More lessons in ๐Ÿ’ป Tech (3) See all tech lessons โ†’

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson โ†—