OCR H446, section 1.3.4 (b)
The web has billions of pages. When you search, the results come back in a fraction of a second, because the search engine doesn't search the web at that moment. It searches its own index, which it has built in advance.
There are three steps: crawling, indexing and ranking.
1. Crawling
A web crawler (also called a spider or bot) is a program that automatically visits web pages and follows the links on them to discover more pages.
- It starts from a list of known web addresses (seed URLs).
- It downloads each page.
- It extracts all the links on the page and adds new ones to its list.
- It repeats, continuously, revisiting pages to find changes.
Page owners can guide crawlers:
- A
robots.txtfile tells crawlers which parts of the site they may or may not visit. - Sitemaps list the pages that the owner wants to be found.
- Pages with no links to them (and not in a sitemap) may never be found.
2. Indexing
For each page, the search engine analyses the content and stores it in an index: a huge database organised so that it can be searched very quickly.
It records things such as:
- the words on the page, and where they appear (the title, headings and main text count differently);
- the title, headings, links, image descriptions (
alttext), and meta tags (such as the page description); - how recent the page is, and how many other pages link to it.
The inverted index
The index is usually an inverted index: instead of listing the words in each page, it lists, for each word, the pages that contain it.
| Word | Pages that contain it (and the word's positions) |
|---|---|
cat |
page 1 (words 4, 19), page 3 (word 2), page 7 (word 11) |
dog |
page 2 (word 8), page 3 (word 3) |
fish |
page 4 (word 1) |
To answer a search for cat dog, the engine looks up each word, and finds the pages in both lists (page 3), instead of reading every page. This is like the index at the back of a book.
Storing each word's position lets the engine find phrases and words that are close together: on page 3, cat is word 2 and dog is word 3, so a search for "cat dog" as a phrase matches it.
3. Ranking
Many pages match a search, so the engine must put them in order, with the most useful first. It calculates a ranking score from many factors:
- How well the page matches the query: whether the search words are in the title and headings, how often, and how close together.
- The importance of the page, mainly measured by the links to it from other pages (see PageRank, 1.3.4 (c)).
- Quality and trustworthiness of the site.
- Freshness (how recent it is).
- Page speed and whether it works well on mobile devices.
- The user: their location, language and past searches.
Then the engine returns the ranked list of results.
How the whole process fits together
Influencing the index: search engine optimisation (SEO)
SEO is the practice of making a page easier for search engines to find and understand, so that it appears higher in results. Good practice includes:
- a clear, descriptive title and headings;
- relevant keywords used naturally;
alttext on images;- a meta description (a
<meta>tag in the<head>) that sums up the page; - a fast, mobile-friendly page, with a good structure;
- useful content that other sites link to.
Bad practice, such as keyword stuffing (repeating words), hidden text or buying lots of links, can get a site penalised.
Issues
- The index can be out of date, as pages change after they have been crawled.
- Some content (the "deep web": pages behind logins, paywalls or forms) isn't indexed.
- Results can be biased by paid placement and ranking choices.
- Privacy: personal information in indexed pages can be hard to remove.
Worked example
Task: a new bakery launches a website. Explain how it could get found by search engines.
- It must be crawled: make sure that other sites link to it, and submit a sitemap, so that the crawler discovers it. Check that
robots.txtdoesn't block it. - It must be indexed: use a clear title ("Smith's Bakery, Leeds"), headings and text that contains the words people search for (such as "sourdough" and "wedding cakes"), and alt text on the photos, so the engine knows what the page is about.
- To rank well: make the site fast and mobile friendly, and get links from respected sites (such as a local news site), because links from other pages are a strong signal of quality.
Exam tip: name the three stages (crawl, index, rank) and give a job for each. Describe the index as a database of words and the pages that contain them, searched in advance so results are fast. Mention that links from other pages influence ranking.
Check yourself
What does a web crawler do?
It automatically visits web pages and follows the links on them to discover more pages, downloading them so that they can be indexed.
What is an inverted index?
An index that lists, for each word, the pages that contain it, so that search results can be found quickly without reading every page.
Why are results returned so quickly?
The search engine searches its own pre-built index, and doesn't search the live web when you make the query.
What does a robots.txt file do?
It tells web crawlers which parts of a website they may or may not visit.