Web crawling and meta-search
Practical notes on web crawling (how crawlers discover, fetch, and schedule pages) and meta-search (how multiple search engines' results are combined), with key formulas, examples, common mistakes and exam guidance.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Web crawling is the process search engines and many data pipelines use to discover and download web pages at scale; engineers build crawlers when they need fresh copies of web content, to populate indices (see "The retrieval process" and "Dynamic inverted indices"). Meta-search is used where you must combine results from several search engines or sources (for example, a vertical search aggregator or a privacy-preserving search service) so engineers use meta-search methods to merge, deduplicate and rank results efficiently.
Key ideas
Start from first principles: the web is a directed graph of pages connected by hyperlinks. Crawling and meta-search solve two related problems: (1) how to find and maintain copies of pages you care about; (2) how to combine multiple ranked lists from different systems.
- Define: Web crawler — a program or system that automatically downloads web pages by following hyperlinks and URLs from seed lists. It performs discovery, fetching, parsing, and scheduling.
- Define: Frontier — the data structure (usually a queue or priority queue) holding URLs discovered but not yet fetched; frontier controls order of fetches.
- Define: Politeness — a set of rules to avoid overloading remote sites (e.g., limits per host, delays between requests). Politeness is an operational constraint, not a ranking rule.
- Define: robots.txt — a standard (Robot Exclusion Protocol) file hosted at a site's root that tells crawlers which URL paths are disallowed. A polite crawler must read and respect robots.txt before fetching other URLs from that host. It may include Allow and Sitemap directives; Crawl-delay is non-standard and not universally honored.
- Define: URL normalization — the process of converting URLs to a canonical form (for example, removing default ports, normalizing case where appropriate, decoding percent-encodings) so the same resource is not fetched multiple times under different strings.
- Define: Duplicate detection — methods to avoid storing or indexing identical or near-identical pages (for example, hashing document content or using shingling + minhash). Duplicate detection reduces storage and processing.
- Define: Focused crawling — crawling strategy that prioritizes URLs likely to be relevant to a specific topic using a relevance estimator (e.g., classifier or heuristics) rather than general-purpose crawling.
- Define: Change rate (λ) — the expected number of changes per unit time of a page (modelled as a Poisson process in many analytic models). This drives how often a crawler should revisit a page to keep a fresh copy.
- Define: Freshness — the probability that a local copy matches the live page; with Poisson changes and revisit interval t, freshness = e^{-λ t}.
Architecture and design principles (step-by-step):
- Seeds: provide initial URLs to start discovery. Also use XML Sitemaps (Sitemap protocol) as a source of URLs and optional change-frequency/lastmod hints.
- Fetching: use HTTP (GET) respecting robots.txt and politeness (per-host queues and delays), and leverage conditional requests (If-Modified-Since/If-None-Match) to avoid refetching unchanged content.
- Parsing: extract hyperlinks and data; perform URL normalization.
- Frontier management: insert new URLs (subject to filters) into frontier with priorities.
- Scheduling: choose next URL from frontier (BFS, priority-based, focused). For large scale, maintain per-host queues to respect politeness and allow parallelism across hosts.
- Storage: store raw pages, metadata (fetch time, content hash), and passes to downstream indexing (e.g., for inverted index construction).
Scheduling and prioritization: draw and label a diagram showing a multi-queue frontier: many per-host queues feeding a global scheduler that enforces politeness. Label: (a) Host queues with next-fetch-time; (b) Global priority queue of host-ready queues; (c) Fetcher workers.
Meta-search principles:
- Define: Meta-search engine (metasearcher) — system that submits a user query to multiple independent search engines, collects their result lists and merges them into a single result set.
- Main challenges: heterogeneous score ranges, latency and partial replies, duplicate documents across engines, and result selection when engines are many (resource selection).
- Steps for meta-search: (1) Resource selection — choose which engines to query (often based on query profiles); (2) Query dispatch — send queries in parallel and collect replies; (3) Score normalization — convert engine-specific scores to a comparable scale; (4) Merger / aggregation — combine normalized scores and/or ranks; (5) Duplicate detection and tie-breaking.
Common score-normalization methods:
- Min-max normalization: rescales scores to [0,1].
- Z-score (standard score): rescales by mean and standard deviation.
- Rank-based: convert rank positions to scores (Borda count).
Combining methods (definitions):
- CombSUM: sum of normalized scores across engines.
- CombMNZ: CombSUM multiplied by the number of non-zero contributions: CombMNZ(d) = CombSUM(d) * freq(d), where freq(d) is number of engines that returned d.
- Borda count: assign points based on rank positions then sum.
Assumptions made in these models: independence of engines (often false), that scores are monotonically related to relevance, and that engines return comparable result lists.
Formulas
throughput = pages_downloaded / time — pages_downloaded: number of pages fetched (unit: pages); time: elapsed time (unit: seconds); result units: pages/s. Applies when measuring crawler speed.
bandwidth_used = sum(size_i) / time — size_i: bytes of page i (unit: bytes); time: seconds; result units: bytes/s. Applies when calculating average network usage.
P_not_changed(t) = e^{-λ t} — λ: change rate (per unit time, e.g., s^-1 or day^-1); t: time since last fetch in the same time units as λ^{-1}. Gives probability a page has not changed in interval t under a Poisson change model.
z = (s - μ) / σ — s: score to normalize (unitless), μ: mean score (unitless), σ: standard deviation (unitless). Produces z-score; applies when scores approximate a normal distribution.
minmax(s) = (s - s_min) / (s_max - s_min) — s_min, s_max: min and max scores in the engine's result set. Produces values in [0,1].
CombSUM(d) = sum_{e in engines} norm_score_e(d) — norm_score_e(d): normalized score of document d from engine e (unitless). Applies after normalization.
CombMNZ(d) = CombSUM(d) * count_nonzero(d) — count_nonzero(d): number of engines that returned document d (integer).
Borda(d) = sum_{e} (N_e - rank_e(d) + 1) — N_e: number of results returned by engine e; rank_e(d): position of d in engine e (1-based). Borda gives higher points to higher-ranked documents.
Worked examples
Example 1 — numerical: freshness after a revisit interval. Problem: A page changes according to a Poisson process with λ = 0.1 changes per day. You revisit it after t = 7 days. What is the probability your copy is still fresh (unchanged)? Steps:
- Convert λ to per-day units: λ = 0.1 day^-1 (already per day).
- Use the Poisson-derived freshness formula:
P_not_changed(t) = e^{-λ t}. - Compute:
P_not_changed(7) = e^{-0.1 * 7} = e^{-0.7}. - Numerically: e^{-0.7} ≈ 0.4966. Answer: Approximately 0.497 (49.7%) chance the copy is unchanged after 7 days.
Example 2 — programming: simple meta-search merger in Python using CombSUM with min-max normalization. The program simulates two engines returning score lists.
Python program:
# Simple meta-search merger using min-max normalization and CombSUM
engines = {
'A': [('doc1', 3.0), ('doc2', 1.5), ('doc3', 0.2)],
'B': [('doc2', 120), ('doc4', 60), ('doc1', 30)]
}
# Normalize using per-engine min-max, then CombSUM
norm_scores = {}
for e, results in engines.items():
scores = [s for (_, s) in results]
smin, smax = min(scores), max(scores)
for doc, s in results:
if smax == smin:
ns = 1.0
else:
ns = (s - smin) / (smax - smin)
norm_scores.setdefault(doc, []).append(ns)
# CombSUM
comb = {}
for doc, vals in norm_scores.items():
comb[doc] = sum(vals)
# Sort by descending CombSUM
merged = sorted(comb.items(), key=lambda x: -x[1])
print('doc_id\tCombSUM')
for doc, score in merged:
print(f"{doc}\t{score:.3f}")
Sample input: (program contains its inputs inline) Sample output (exact):
doc_id CombSUM doc2 1.464 doc1 1.000 doc4 0.333 doc3 0.000
Explanation: Engine A normalized scores: doc1=1.0, doc2≈0.464..., doc3=0.0; Engine B normalized: doc2=1.0, doc4≈0.333..., doc1=0.0. CombSUM: doc2≈1.464..., doc1=1.0, doc4≈0.333..., doc3=0.0. The program prints three decimals as shown.
Example 3 — short model-answer theory question (exam style): Question: Explain robots.txt handling and its limitations. Model answer: robots.txt is a text file at https://example.com/robots.txt that uses directives like User-agent and Disallow to instruct crawlers which URL paths not to fetch. A polite crawler first retrieves and parses robots.txt and applies its rules per host before fetching other URLs. Limitations: (1) robots.txt is voluntary and not enforced by servers; (2) it only controls crawling, not indexing (some crawlers may still index disallowed URLs from other signals); (3) different crawlers interpret wildcards differently; (4) it is fetched over HTTP so it can be unavailable or stale; (5) does not prevent access via direct links or via other hosts.
Common mistakes
- Not normalizing URLs (leading to duplicate fetches due to issues like redundant trailing slashes, default ports, inconsistent case where not significant, or query-parameter ordering). Note: http and https are different schemes and must not be merged by normalization.
- Confusing score normalization methods: using min-max when scores contain outliers can compress most values; forgetting z-score assumes approximate normality.
- Using CombSUM without normalization (summing raw scores from different engines with different scales).
- Ignoring network/bandwidth limits and assuming infinite parallel fetchers.
- Treating freshness and frequency as the same: frequency of change (λ) is a model parameter; freshness is a derived probability e^{-λ t}.
For your exam
- Short notes: explain crawler architecture or meta-search pipeline. Full marks: diagram description, mention of per-host queues, frontier, parsers, politeness and storage.
- Derivations: derive freshness under Poisson model. Full marks: state Poisson assumption, derive P(no change in t) = e^{-λ t}.
- Numericals: compute freshness or throughput given rates and sizes. Full marks: units, stepwise computation, final numeric with correct units.
- Programs: write a small meta-search merger or a crawler frontier simulator. Full marks: runnable code, sample I/O.
- Diagrams: draw frontier/host-queue diagram and label components. Full marks: show host queues, global scheduler, fetchers, and arrows for politeness timing.
Quick check
- What file at a site's root tells a crawler which URL paths it should not fetch?
- In the Poisson change model, if λ is the change rate per day, what is the probability the page remains unchanged after t days?
- Name two combination methods used in meta-search.
Answers: robots.txt; e^{-λ t}; CombSUM and CombMNZ (also Borda).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?