Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
How a search engine works: crawling the web, building an inverted index, ranking with PageRank and relevance signals, and answering queries in milliseconds.
Quick answer: A search engine does almost all of its work before you type anything. It crawls the web continuously, downloading pages by following links. It indexes them, building an inverted index that maps every word to the list of pages containing it. When you search, it does not scan the web; it looks up your words in that index, intersects the lists, and ranks the matching pages using hundreds of signals about relevance and quality. The index is split across thousands of machines that are queried in parallel, which is how results come back in a fraction of a second.
Google describes these same three stages (crawling, indexing, serving) in its guide to how Search works. The ranking details are proprietary; this article covers the well-established principles.
There is no central list of web pages. A crawler (Google's is called Googlebot) discovers them:
Sitemaps submitted by site owners are another source of URLs.
The crawler has to make choices:
robots.txt, a file where sites say which paths crawlers may visit.Each fetched page is processed:
Then comes the central data structure.
A normal ("forward") index says: document 1 contains these words. An inverted index flips it:
database -> [doc 3, doc 17, doc 42, doc 108, ...]
index -> [doc 3, doc 9, doc 42, doc 77, ...]
tutorial -> [doc 9, doc 42, doc 300, ...]
Each list is called a posting list. It stores document IDs in sorted order, along with word positions and other data.
To answer database index tutorial:
This is the same idea as an index at the back of a book, applied to the whole web. It is closely related to database indexes, and it is what search engines like Elasticsearch use too.
Posting lists are heavily compressed, and rare words have short lists, so the engine starts with the rarest term to keep the work small.
Millions of pages may match. The value of a search engine is in ordering them.
In 1998, Larry Page and Sergey Brin described the idea that made Google stand out in The Anatomy of a Large-Scale Hypertextual Web Search Engine. PageRank treats a link from page A to page B as a vote for B. Votes from important pages count more, and importance is computed recursively over the whole web's link graph.
The insight was that the web's own structure reveals which pages people consider worth pointing to. Links remain a signal today, among many others.
Keyword matching fails when the query and the page use different words. Modern engines use machine learning to bridge the gap:
Running the most sophisticated models on millions of candidates would be too slow. Ranking is a funnel: a cheap scoring pass selects the top few thousand candidates, and progressively more expensive models re-rank smaller sets. The same pattern appears in recommendation systems.
Once the top documents are chosen, the engine builds the page: titles, snippets showing your query words in context, and special features such as direct answers, maps, images, knowledge panels and, increasingly, AI-generated summaries. Ads are selected by a separate auction system that runs alongside.
Search engine optimisation follows directly from the pipeline:
A data structure that maps each word to the list of documents containing it, so that finding all pages with a given word is a direct lookup.
An algorithm that scores a page's importance from the number and importance of the pages linking to it.
No. It searches its own index, built in advance from crawled pages. That is why a new page takes time to appear and a deleted one can linger.
A crawler discovers it through a link or a sitemap, fetches and renders it, and adds it to the index. This can take from hours to weeks.
A search engine is fast because the hard work happens ahead of time. Crawling gathers the web, the inverted index turns "find these words" into a lookup, and layered ranking narrows millions of matches to ten. Splitting the index over thousands of machines and querying them in parallel does the rest.