Everyday technology / How search engines work

How search engines work

What happens between typing two words and seeing a list of links: crawling, an inverted index, query processing and ranking, shown on a toy web of four pages.

Beginner7 steps~6 min
Page — a document on the web, with a number
Crawler — follows links and saves copies of pages
Index entry — one word and the pages that contain it
Query — the words someone searches for
// THE SHORT VERSION

In 30 seconds

A search engine does most of its work before you type anything. Programs called crawlers follow links from page to page and save a copy of each one.

From those copies it builds an inverted index: for every word, the list of pages that contain it, like the index at the back of a book.

When you search, it looks up your words, keeps the pages found on every list, and ranks them by how well they match and how trusted they are. Reading a few ready-made lists is why answers arrive in a fraction of a second.

How search engines work, step by step

STEPS01 / 07

Common words such as “at” and “a” are left out of this toy index. Real engines also record where each word appears, handle typos and synonyms, and weigh hundreds of ranking signals.

STEP 01 / 07 A web with no contents page
THE MATH
pages: billions query: a few words time allowed: under 1 second
  1. Step 1: A web with no contents page. The web is a huge pile of pages that point to each other with links. Nobody keeps a master list. A search engine has to find the pages, work out what each is about, and answer a query of a few words in a fraction of a second. Here is a toy web of four pages, and the query “Baking bread”.
  2. Step 2: Crawling: follow the links. A program called a crawler starts from a page it already knows, here page 2. It downloads the page, saves a copy, and notes every link on it. The link leads to page 1, whose links lead to pages 3 and 4. Page 3 links back to page 1, which is already saved, so that link is skipped. Crawlers run all the time, because pages change.
  3. Step 3: Build the inverted index. Reading every saved page for every search would be far too slow. So the engine turns the copies inside out. For each word it stores the list of pages that contain it. This is an inverted index, the same idea as the index at the back of a book: look up a word, get the page numbers.
  4. Step 4: Process the query. Now someone searches for “Baking bread”. The engine first tidies the query the same way it tidied the pages: lowercase letters, and words cut back to a common form, so “Baking” becomes “bake”. Then it looks up each term in the index. Two quick lookups return two ready-made lists of pages. No page is opened.
  5. Step 5: Match: pages on both lists. A page that answers the query should contain both terms, so the engine keeps the pages that appear on both lists. Page 3 only bakes cake and page 2 never says bake, so they drop out. Pages 1 and 4 remain. Because each list is stored in page order, one pass down the two lists finds what they share.
  6. Step 6: Rank the matches. Which match goes on top? The engine scores each page on how well it fits the query and how much it is trusted. One classic sign of trust is links: a link from another page counts as a vote. Both pages contain both terms, but two pages link to page 1 and only one to page 4, so page 1 is listed first.
  7. Step 7: Why the answer is instant. The slow jobs, crawling and indexing, were finished before the query arrived. Answering it meant reading two short lists, six entries in all, and never the pages themselves. On the real web the same holds: the index is split across many machines that search their parts at once, and results for common queries are kept ready.
VALUES SO FAR
toy web4 pagesinput
crawl····order
bake····index
bread····index
terms····query
match····both
ranking····result
read····fast
// BEFORE

Learn this first

Nothing. This concept starts from scratch.

// AFTER

Learn next

Nothing builds on this one yet. See every everyday technology concept.

Spotted a mistake on this page?