The Architecture of a Search Engine

The indexing process and the query process, a four-document collection carried through every stage, and why the contents of the index decide which ranking models are possible.

A search engine is two processes sharing an index (Croft, Metzler, and Strohman, 2010, §2.2): offline indexing (acquisition, text analysis, index creation) and online query processing (analysis, ranking, presentation), with logs for evaluation. Whatever does not depend on the query is computed in advance; in BM25 even each term's contribution to a document's score is, which is why this site's instant results rank exactly as its server does. On four Arctic sentences, the query arctic climate warming gives the Boolean set {d1, d2}; TF-IDF scores them 0.551 and this site's BM25F ($k_1 = 1.2$, $b = 0.5$) 0.6182, with the same order. The stages constrain one another: ranking can use only what the index stored, and cannot recover a match the stemmer lost (warmer against warm).

A search engine answers most queries in well under a second, over a collection far too large to scan in that time. What Information Retrieval Is put a number on it: reading a petabyte of web pages once, at a gigabyte per second, takes about 11.6 days. So where does the time go instead, and what has to happen to a document before a query can find it in milliseconds?

The answer is that nearly all of the work happens before the query arrives. The documents are gathered, analyzed and organized into an index in advance, and the query is answered by consulting the index, not the documents. That division of labor, between what is done ahead of time and what must be done at query time, determines the architecture of every search engine. It holds from a desktop file search to a web engine.

Here is the route. First we describe the standard architecture as two processes that share an index, and why the work is split that way. Then we carry four short documents, a cut-down version of the thesis student's Arctic literature, through every stage by hand. Next we feed the same four documents to this site's own search engine and see where a working engine differs from the hand calculation. Finally we examine how the stages constrain one another. The later topics of the course each take one stage and treat it in depth; here the aim is to see the whole system.

Two processes

Croft, Metzler, and Strohman (2010, §2.2) describe a search engine as two processes that share an index.

The indexing process runs offline, ahead of any query:

  1. Text acquisition gathers the documents: crawling the web, reading a file system, or receiving a feed from a database or content system.
  2. Text transformation converts each document into index terms. It extracts text from formats such as HTML and PDF, splits the text into tokens, and normalizes them.
  3. Index creation builds the data structures that map terms to documents, records the statistics that ranking will need, and stores everything in a form that can be searched quickly.

The query process runs online, once for each query:

  1. User interaction accepts the query, transforms it into terms using the same analysis applied to the documents, and later presents the results.
  2. Ranking uses the index to find candidate documents and orders them by an estimate of relevance.
  3. Evaluation logs queries and interactions. Mostly offline, it measures effectiveness and efficiency from those logs, so that the system can be monitored and improved.

The same structure is often drawn as a single pipeline:

crawl → parse and analyze → index → parse and expand query → retrieve and rank → present results

The first three stages form the document's path into the system. The last three form the query's path.

The two processes of a search engine. The indexing process (top) turns documents into an index before any query arrives; the query process (bottom) consults only the index. Notice the dashed line: it marks the one piece of code both share, text analysis, which must treat a query exactly as it treated the documents. The gray labels name the functions of this site's own search engine that do each job, traced later in this article.
The two processes of a search engine. The indexing process (top) turns documents into an index before any query arrives; the query process (bottom) consults only the index. Notice the dashed line: it marks the one piece of code both share, text analysis, which must treat a query exactly as it treated the documents. The gray labels name the functions of this site's own search engine that do each job, traced later in this article.

The search box at the top of this site is a complete, small instance of the diagram:

  • When the site starts, app/wiki.py reads the article files (acquisition).
  • app/search.py strips their Markdown and analyzes the text (transformation).
  • The SearchIndex class builds an inverted index with term positions, stored separately for the title, summary, headings and body of each article (index creation).
  • A query is parsed by app/query.py, analyzed by the same function used on the articles, scored with BM25F, and returned with highlighted snippets.

Its evaluation runs offline. A file of about sixty known-item queries, each paired with the article it should find, scores the ranking whenever its parameters are tuned (tools/search/evaluate.py). The build fails if any article is not the top result for its own title. Because nothing in it is hidden, it can be traced stage by stage, which a later section does. How this search works describes the engine in full on its real index, from fields and positional postings to spelling correction and the tests that keep the instant results in step with the server.

Why the work is split this way

The split exists because the two processes face different constraints. Indexing can be slow, because it runs in the background, ahead of any query, and can be spread across many machines. Query processing must be fast, because a person is waiting. Anything that does not depend on the query should therefore be computed at indexing time:

  • tokenizing documents and counting terms;
  • computing document lengths and collection statistics;
  • on the web, computing link-based authority scores.

The query process is left with only the work that genuinely depends on the query.

The principle can be pushed further than it first appears. In BM25 and its relatives, the contribution a term makes to a document's score depends only on the term and the document, not on the other words of the query. The formula in the scoring section below shows why. A term's contribution is built from the term's document frequency, the number of documents, the term's frequency in the document, the document's length and the average length, and the score is the sum of such contributions over the query's terms. No quantity in one term's contribution refers to another term. It can therefore be computed once, at indexing time, for every term and every document that contains it.

This site does exactly that for the instant results that appear as a reader types. The server exports, for each term, the list of articles containing it with each article's precomputed contribution. The browser answers a query by adding up the numbers for its terms. The browser contains no stemmer and no scoring formula; a typed word is mapped to its index term through an exported word list. Yet for any word the wiki uses it ranks exactly as the server does, because every part of the score that could be computed in advance was. The price is flexibility: changing a ranking parameter means recomputing the exported weights.

The same principle separates the two neural designs named in the history: a dense retriever encodes each document with no query in view, so its vectors are computed at indexing time (Karpukhin et al., 2020), while a re-ranker that reads the query and the document together can precompute nothing about the pair and is applied only to a short list of candidates (Nogueira and Cho, 2019). Sentence and passage encoders sets the two designs, called bi-encoders and cross-encoders, side by side. Learned sparse retrieval applies the principle to a trained model in another way: the model sets each term's weight in each document at indexing time, so a query is still answered from an inverted index of precomputed weights.

The split is less clean in practice. A news search engine must make new articles searchable within minutes, so indexing becomes a continuous process that merges small fresh indexes into a large main one. Caches store the results of frequent queries, which in effect precomputes part of the query process; caching in search engines derives how often such a cache answers when query popularity follows a Zipf law. The article on search at scale covers these mechanisms. The conceptual division still holds: work that can be moved before the query arrives should be.

The diagram names the stages. To see what each one actually produces, we need data small enough to follow by hand.

A small collection, end to end

Consider four documents, a miniature of the thesis student's literature on the Arctic and a warming climate:

ID Text
d1 Arctic sea ice is declining as the climate warms.
d2 A warming climate threatens Arctic seabirds and their food.
d3 Climate models predict warmer winters in Europe.
d4 Seabirds of the Arctic: a field guide.

The query we will follow is arctic climate warming.

Acquisition and parsing

In a real system, acquisition is a substantial problem in itself. A crawler must find documents, decide which to fetch and how often to revisit them, and avoid overloading the servers it visits; this is the subject of web crawling.

Parsing must then extract clean text from each format, and each format has its own trap:

  • With HTML, it has to strip markup and scripts and separate a page's main content from its navigation menus.
  • With PDF files, it must reconstruct reading order. A naive extractor reading a two-column scientific paper line by line across the page interleaves sentences from both columns and produces text that matches nothing.
  • Character encodings must be identified correctly, or non-English text is corrupted before it reaches the index.

Here the documents are already plain sentences, so parsing is trivial.

Text analysis

Text analysis turns each document into a list of index terms. This example uses three common steps, each covered properly in text processing and indexing:

  • Tokenization: lowercase the text and split it into words, discarding punctuation.
  • Stop-word removal: drop very frequent function words, here a, and, as, in, is, of, the, their.
  • Stemming: reduce each word to a stem with the Porter stemmer (Porter, 1980), so that inflected forms of a word match one another.

The result, computed with the Porter algorithm as originally published:

ID Index terms
d1 arctic, sea, ic, declin, climat, warm
d2 warm, climat, threaten, arctic, seabird, food
d3 climat, model, predict, warmer, winter, europ
d4 seabird, arctic, field, guid

Several features of this output are worth noting, because they recur in every real system.

  • Stems are not words. Climate becomes climat, and ice becomes ic. That does no harm, because the same rules are applied to queries. The stem only needs to be consistent, not readable.
  • Variants join. Warms and warming both become warm, which is the purpose of stemming.
  • Some variants do not. Warmer stays warmer, because the Porter rules do not remove -er from so short a stem.

Example (a match the stemmer loses). d3 is about winters getting warmer, and it does not match the query word warming. Warming becomes warm and warmer stays warmer, so the two never meet in the index. Stemming trades errors in both directions. It fails to join some related words, as here, and it joins some unrelated ones: the Porter stemmer reduces both university and universe to univers.

Index construction

The inverted index maps each term to its postings list: the documents that contain the term. Here each posting also records the number of occurrences of the term in the document (its term frequency, $tf$). The number of documents in a term's postings list is its document frequency, $df$.

Term $df$ Postings (document: $tf$)
arctic 3 d1: 1, d2: 1, d4: 1
climat 3 d1: 1, d2: 1, d3: 1
seabird 2 d2: 1, d4: 1
warm 2 d1: 1, d2: 1
declin, europ, field, food, guid, ic, model, predict, sea, threaten, warmer, winter 1 each one document each

The index is "inverted" because it reverses the natural organization of the collection. A document lists its words; the index lists, for each word, its documents. That reversal lets a query touch only the postings of its own terms rather than every document. For a query of three terms over a web-scale collection, that is the difference between reading three lists and reading billions of documents.

Query processing

The query arctic climate warming goes through the same analysis as the documents and becomes arctic, climat, warm. This consistency is essential. If documents were stemmed and queries were not, warming would match nothing, because the index contains only warm. Every normalization that changes the form of index terms, such as case folding or stemming, must be mirrored at query time.

Query processing in real systems does more than this. It may correct spelling, recognize phrases and named entities, expand the query with synonyms, or rewrite it entirely. The article on web search describes these steps.

Retrieval and ranking

The simplest retrieval model is Boolean: return exactly the documents that contain every query term.

Example (the Boolean result). Only d1 and d2 satisfy arctic AND climat AND warm. Intersecting the three postings lists of the table gives

$$\{d1, d2, d4\} \cap \{d1, d2, d3\} \cap \{d1, d2\} = \{d1, d2\}.$$

The result is a set, with no order and no partial credit. d3, which is about a warming climate, and d4, which is about the Arctic, are both excluded. Intersecting postings lists covers how such intersections are computed efficiently.

A ranked model instead scores every document that contains at least one query term. Here is the idea in one sentence: each query term a document contains adds points, and rarer terms add more. A term found in many documents says little about any one of them. The simplest score of that kind sums, over the query terms in a document, the term frequency times a weight for the term's rarity:

$$\text{score}(q, d) = \sum_{t \in q \cap d} tf_{t,d} \cdot \log_{10} \frac{N}{df_t},$$

where $N = 4$ is the number of documents, $tf_{t,d}$ is the term frequency of term $t$ in document $d$, and $df_t$ is its document frequency. The logarithmic factor is the inverse document frequency (IDF). A term found in every document gets weight $\log_{10} 1 = 0$, because its presence tells the system nothing. For this collection:

Term $df$ IDF $= \log_{10}(4/df)$
arctic 3 0.125
climat 3 0.125
warm 2 0.301

Each term appears at most once per document, so each score is the sum of the IDF weights of the query terms the document contains:

Document Query terms present Score
d1 arctic, climat, warm 0.125 + 0.125 + 0.301 = 0.551
d2 arctic, climat, warm 0.551
d3 climat 0.125
d4 arctic 0.125

The ranking is d1 and d2 tied, then d3 and d4 tied. Even this tiny example shows the main problems of ranking:

  • Warm counts more than arctic because it is rarer in this collection, not because it is more important to the searcher.
  • The ties need breaking. A real system might prefer shorter documents, fresher ones, or more authoritative ones.
  • d3 is penalized for a stemming decision, not for its content.

This score is the simplest form of TF-IDF weighting. The vector space model develops it properly, with length normalization and alternative weightings, and BM25 refines it further.

Presentation

The final stage turns the ranking into something a person can use. Each result is shown with a title, a link and a snippet. The best snippets are query-dependent: rather than showing the first lines of the document, the system selects passages that contain the query terms. For a query such as symptoms of influenza, a snippet listing the symptoms lets the searcher judge the result, or even satisfy the need, without opening the page. Generating snippets requires access to the document text at query time. Search engines therefore keep the text of each document, as a cached copy or in a separate document store, alongside the index.

The hand calculation used a formula chosen to be easy to compute. The next section measures how close it is to what a working engine does: on this query the engine's scores differ and its order is the same.

The same collection in this site's search engine

A working engine differs from the walk-through in its details, and seeing exactly where is the best preparation for the later topics. This section feeds the same four sentences to this site's own search code (app/search.py) and records what every stage produces. Each sentence is placed in the body field of an otherwise empty article. The numbers come from tools/experiments/foundations/site_engine_trace.py, which builds the index with the site's own classes. Scores are rounded to four decimal places.

Analysis

The engine folds accents and case and splits the text into runs of letters and digits. It then drops the words on a 33-word stop list and stems the rest with the Porter algorithm. Its stop list is longer than the eight words used above. For these sentences it removes the same words, so the index terms are identical to the table in Text analysis:

ID Tokens (stop words in brackets) Length
d1 arctic sea ice [is] declining [as] [the] climate warms 9
d2 [a] warming climate threatens arctic seabirds [and] [their] food 9
d3 climate models predict warmer winters [in] europe 7
d4 seabirds [of] [the] arctic [a] field guide 7

One detail is easy to miss. The engine removes stop words from the index but still counts their positions. A document's length is therefore its number of tokens including stop words, and the term climat sits at position 7 of d1, not position 4. Counting positions this way keeps phrase queries correct when a phrase contains a stop word, as phrase queries explains. The average length of the four documents is $(9 + 9 + 7 + 7)/4 = 8$.

Index

The index stores, for each term, each document that contains it and the positions where it occurs, per field. For the query's three terms, with every occurrence in the body field:

Term $df$ Postings (document: positions)
arctic 3 d1: [0], d2: [4], d4: [3]
climat 3 d1: [7], d2: [2], d3: [0]
warm 2 d1: [8], d2: [1]

The term frequencies of the earlier table are the lengths of these position lists. The whole vocabulary is 16 terms, the same 16 as before.

Parsing the query

The query arctic climate warming goes first to the query parser. The parser recognizes the site's query language: quoted phrases, + and - signs, field prefixes such as title:, and the Boolean operators AND, OR and NOT. This query has none of them, so the parser returns a free-text query, in which any document containing at least one term is a candidate. Analysis then turns the three words into the index terms arctic, climat and warm, by the same function that analyzed the documents. Had the query been typed as arctic AND climate AND warming, the parser would have built a Boolean tree instead. Then only d1 and d2, the intersection computed earlier, would have matched.

Scoring

The engine ranks with BM25F, a variant of BM25 for documents with several fields. With only a body field it reduces to BM25 with $k_1 = 1.2$ and $b = 0.5$.

Here is the idea before the formula. BM25 keeps the hand calculation's rule: each matching term adds points, rarer terms more. It adds two corrections. A match in a short document counts a little more than one in a long document, and repeated occurrences of a term add less and less. Each term contributes

$$\text{IDF}(t) \cdot \frac{tf'}{k_1 + tf'}, \qquad tf' = \frac{tf}{1 - b + b \cdot L_d / \bar L},$$

where $L_d$ is the document's length, $\bar L$ the average length, $k_1$ sets how quickly repeated occurrences stop adding, and $b$ sets how strongly length is normalized. The formula is stated here, not derived. Okapi BM25 derives the saturating factor and the length normalization from a probabilistic model of term frequencies, and BM25F derives the form for several fields. Three differences from the hand-worked TF-IDF score are visible in this formula, and the trace shows each of them.

A different IDF. The engine uses $\text{IDF}(t) = \ln\left(1 + \frac{N - df_t + 0.5}{df_t + 0.5}\right)$, the form used by Lucene. It never reaches zero, so even a term found in every document counts a little. The reason is one line: $df_t \le N$ makes the fraction at least $0.5/(N + 0.5)$, which is positive, so the logarithm's argument exceeds 1 and the logarithm is positive. For arctic and climat, $\ln(1 + 1.5/3.5) = 0.3567$; for warm, $\ln(1 + 2.5/2.5) = \ln 2 = 0.6931$. The rarer term still counts about twice as much.

Length normalization. The divisor $1 - b + b L_d/\bar L$ is $1.0625$ for d1 and d2, which are longer than average, and $0.9375$ for d3 and d4, which are shorter. A single occurrence in a short document is worth slightly more than one in a long document.

Saturation. $tf'/(k_1 + tf')$ grows with term frequency but can never exceed 1, so the tenth occurrence of a word adds far less than the first.

Document Divisor $tf'$ $tf'/(k_1 + tf')$ Term contributions Score
d1 1.0625 0.9412 0.4396 arctic 0.1568, climat 0.1568, warm 0.3047 0.6182
d2 1.0625 0.9412 0.4396 arctic 0.1568, climat 0.1568, warm 0.3047 0.6182
d3 0.9375 1.0667 0.4706 climat 0.1678 0.1678
d4 0.9375 1.0667 0.4706 arctic 0.1678 0.1678

Each figure is rounded separately. The three printed contributions of d1 add to 0.6183, while the score, 0.61824 before rounding, prints as 0.6182.

The ranking agrees with the hand computation: d1 and d2 tied above d3 and d4 tied. (The engine breaks exact ties alphabetically by title; these documents have no titles, so they keep their original order.) On this query the refinements change the scores but not the order.

Example (a query on which the two scores disagree). For the one-word query arctic, TF-IDF gives d1, d2 and d4 the same score of 0.125, and BM25F puts d4 first, with 0.1678 against 0.1568 for d1 and d2. All three contain arctic once, but d4 is shorter: one occurrence among 7 tokens counts for more than one among 9. Whether that is the right call is exactly the kind of question evaluation exists to answer.

Snippets and spelling

Each result is shown with the sentence that contains the most distinct query terms, with the matching words highlighted. Here every document is a single sentence, so d2's snippet is the whole sentence with warming, climate and Arctic marked. The highlighter stems each word of the sentence and marks those whose stems are query terms, so the query word warming also lights up warms in d1.

The engine also corrects spelling before it gives up on a word. Take the query arctic climat warmng:

  • The stem of warmng is not in the index, so the engine looks for an indexed word within a small edit distance and finds warming, one insertion away.
  • climat is a subtler case. It stems to an indexed term, so it would match, but no document ever uses the word as typed, and the engine offers the usual spelling climate.

It runs the corrected query arctic climate warming and says so above the results ("Showing results for ..."). That is the second of the three rewriting policies described in how a web search engine answers a query. Spelling correction covers the methods.

The pipeline as a demo

The demo below runs the same pipeline on the same four documents, for any query. It shows the stop words dropped, the stems, the postings each term retrieves, the Boolean intersection, and the ranking under both the article's TF-IDF score and the site's BM25F. Three queries show the main points, and the worked problems below compute the second:

  • warmer winters, which only d3 matches, because the stemmer keeps warmer apart from warm;
  • the seabirds of europe, whose Boolean intersection is empty while the ranked list still has three documents;
  • arctic, where the two scores disagree.

The demo treats every query as free text. It has no query parser, so quotes, signs and the words AND, OR and NOT are not operators here (the last three are stop words and vanish). Its stemmer gives the same stems as the site's on every word the wiki uses, and tools/experiments/foundations/pipeline_trace_check.py compares its scores with the engine's.

The search pipeline stage by stage on the four-document collection. Type a query or choose an example; every stage updates. The scores agree with this site's search engine on the same documents to every printed digit.

At full size

The same code indexes the whole site when it starts. Two snapshots show how the index grows with the collection. Early in November 2026 the wiki held 152 articles and topic pages. The index then had roughly 9,600 distinct terms, 97,000 postings (term and article pairs) and 330,000 recorded positions, built from about 460,000 tokens in a second or two. A query such as how a search engine answers a query matched every article, because how occurs in nearly all of them. It was ranked in a few milliseconds on a laptop, with this article's neighbor how a web search engine answers a query first.

By mid-November 2026 the indexed pages, course articles and library pages together, numbered about 680. All the figures for this second snapshot are approximate. The index had about 27,000 distinct terms, 470,000 postings and 1.7 million recorded positions, from about 2.4 million tokens. The pages grew by a factor of about 4.5 and the tokens by about 5.2, while the vocabulary grew by a factor of only about 2.8: new pages mostly reuse words the index already has, the pattern that term statistics describes as Heaps' law. The same query matched all but a few of the pages and was ranked in about ten milliseconds, with the same article first. Building the index took on the order of ten seconds. Both sets of figures are snapshots and move as the site grows; the second part of site_engine_trace.py recomputes them for the current pages. A collection of this size needs none of the machinery of search at scale: one process holds the whole index in memory, and a query touches only a handful of postings lists.

The trace showed each stage doing its job. It also hinted at something the pipeline diagram hides: d3 lost its match on warming at the analysis stage, and no later stage could give it back.

How the stages constrain one another

The pipeline diagram suggests independent stages, each passing its output to the next. In practice each stage limits what the stages after it can do, and the most important limits are set at indexing time.

A ranking function can use only the document information that indexing stored. The scoring above needed term frequencies and document frequencies. An index that recorded only which documents contain each term could support Boolean retrieval but not this ranking. The requirements grow with the model:

Capability What the index must store
Boolean retrieval Document IDs in each postings list
Vector space ranking Term frequencies, document frequencies, document lengths or vector norms
BM25 Term frequencies, document frequencies, each document's length, the average document length
Phrase and proximity queries The position of each occurrence of each term
Field weighting (title versus body) Postings separated by field, or field information in each posting

None of these can be added at query time.

Example (a phrase query without positions). An index that stores document IDs and term frequencies but no positions cannot answer the phrase query "new york university" correctly from the index alone. It cannot distinguish a document containing the phrase from one that mentions new in one paragraph and York University in another, short of re-reading every candidate document. Adding the capability means rebuilding the index. A positional index is typically two to four times larger than one that records only document IDs and frequencies (Manning, Raghavan, and Schütze, 2008, §2.4.2). The decision trades storage and speed for query capability, and it has to be made before the system is in use.

Ranking cannot repair analysis errors. If the stemmer conflates university and universe and the index stores only stems, no ranking function can tell them apart, because the index no longer contains the distinction. If it fails to conflate warmer and warm, no ranking function can recover the match. Only a change outside ranking, such as query expansion, can add it back. Choosing stop words has the same character: removing the and who saves space but makes the band The Who unsearchable. These decisions sit at the start of the pipeline and are easy to overlook, but they bound the effectiveness of everything after them.

The query must be analyzed like the documents. Any unintended difference between document and query analysis produces silent mismatches: a different tokenizer, a different stemmer version, or a stop-word list applied to one but not the other. Well-designed systems define one analysis component and use it on both paths, a principle the article on modular design builds into the structure of the code.

Presentation feeds back into ranking. What people click, skip and reformulate is logged, and those logs become training data for ranking and query suggestion. Relevance feedback makes the loop explicit by asking the searcher to mark relevant results and re-running the query. The pipeline is therefore closer to a cycle: the output of the last stage changes the behavior of the earlier ones over time.

The consequence is that improving a search engine rarely means improving one stage in isolation. An excellent ranking function over an index that lost the relevant distinctions will still rank poorly. A carefully written query will fail if analysis and indexing cannot represent what it asks for.

What the diagram leaves out

The architecture described here is an abstraction, and real systems add a great deal to it. A web search engine:

  • distributes its index across thousands of machines and replicates it for capacity, so that a single query is answered by many servers working in parallel;
  • ranks in several stages, applying a cheap function to many candidates and expensive models to only the best few hundred;
  • detects spam and near-duplicate pages, personalizes results, and updates its index continuously.

Enterprise and domain-specific systems add access control, structured fields and specialized vocabularies. The web search and scale articles describe these additions, and search applications describes how the architecture is adapted to different settings.

Worked problems

These problems are posed on this article's four documents and its two scoring formulas; the course text's exercises on building and intersecting postings lists are worked in the topics that treat those subjects. Every number is recomputed by the reference-pass block of site_engine_trace.py, with the site's own index classes for Problems 1 and 2 and the engine's constants for Problems 3 and 4.

Problem 1 (a second query through every stage). Carry the query arctic seabirds through analysis, Boolean retrieval, the TF-IDF score and BM25F on the four documents. Find where the two rankings differ.

Solution. Both scores put d2 and d4 above d1, and they differ in the order of d2 and d4: TF-IDF ties them and BM25F puts d4 first.

  • Analysis: arctic is already a stem, and seabirds becomes seabird. Neither is a stop word.
  • Postings: arctic has d1, d2, d4 ($df = 3$) and seabird has d2, d4 ($df = 2$). The Boolean AND is $\{d1, d2, d4\} \cap \{d2, d4\} = \{d2, d4\}$.
  • TF-IDF: the weights are $\log_{10}(4/3) = 0.125$ and $\log_{10}(4/2) = 0.301$. d2 and d4 contain both terms once and score $0.125 + 0.301 = 0.426$. d1 contains only arctic and scores 0.125.
  • BM25F: the IDF values are 0.3567 for arctic and 0.6931 for seabird. The saturated frequency $tf'/(k_1 + tf')$ of a single occurrence is 0.4396 in the 9-token documents d1 and d2 and 0.4706 in the 7-token documents d3 and d4, as in the table of the scoring section.
Document arctic seabird BM25F score TF-IDF score
d4 $0.3567 \times 0.4706 = 0.1678$ $0.6931 \times 0.4706 = 0.3262$ 0.4940 0.426
d2 $0.3567 \times 0.4396 = 0.1568$ $0.6931 \times 0.4396 = 0.3047$ 0.4615 0.426
d1 0.1568 none 0.1568 0.125

The difference comes from length normalization alone. d2 and d4 contain the same query terms the same number of times, and d4 is two tokens shorter. For the searcher the preference happens to be reasonable, since d4 is a field guide to Arctic seabirds and d2 mentions them in passing, but the score does not know that. It knows only the lengths.

Problem 2 (an empty intersection and a ranked list). For the query the seabirds of europe, find the Boolean AND result and both rankings.

Solution. The AND result is empty, and both scores rank d3 first, then the two seabird documents: tied under TF-IDF, d4 above d2 under BM25F.

  • Analysis: the and of are stop words. The index terms are seabird and europ.
  • Postings: seabird has d2, d4 and europ has d3 only. No document has both, so the intersection is empty. A Boolean engine returns nothing, although three documents each match one of the two terms.
  • TF-IDF: europ occurs in one document of four, so its weight is $\log_{10}(4/1) = 0.602$. d3 scores 0.602, and d2 and d4 score 0.301 each.
  • BM25F: the IDF of europ is $\ln(1 + 3.5/1.5) = \ln(10/3) = 1.2040$. d3 scores $1.2040 \times 0.4706 = 0.5666$, d4 scores $0.6931 \times 0.4706 = 0.3262$, and d2 scores $0.6931 \times 0.4396 = 0.3047$.

Both formulas put d3 first because europ is the rarest term in the collection, not because d3 is about seabirds. It is not: the highest-ranked document is about European winters. Rarity is evidence that a term discriminates between documents, and it is no evidence about which term the searcher cared more about.

Problem 3 (a term in every document). Compute both IDF formulas for a term whose document frequency is 1, 2, 3 and 4 in a collection of four documents. Show that the engine's form stays positive for every collection size, and find its value for a term that occurs in all of a million documents.

Solution. The logarithmic form reaches zero at $df = N$ and the engine's form does not: at $df = N = 4$ it is 0.1054, and at $df = N = 10^6$ it is about $5 \times 10^{-7}$.

$df$ $\log_{10}(4/df)$ $\ln\left(1 + \frac{4 - df + 0.5}{df + 0.5}\right)$
1 0.602 $\ln(1 + 3.5/1.5) = 1.2040$
2 0.301 $\ln(1 + 2.5/2.5) = 0.6931$
3 0.125 $\ln(1 + 1.5/3.5) = 0.3567$
4 0.000 $\ln(1 + 0.5/4.5) = 0.1054$

For any $N$ and any $df \le N$, the fraction $(N - df + 0.5)/(df + 0.5)$ has a numerator of at least 0.5 and a positive denominator, so it is positive and the logarithm of one plus it is positive. It decreases as $df$ grows, because the numerator falls and the denominator rises, so its smallest value is at $df = N$: $\ln(1 + 0.5/(N + 0.5))$. For $N = 10^6$ that is $\ln(1 + 4.9999975 \times 10^{-7}) \approx 5.0 \times 10^{-7}$, using $\ln(1 + x) \approx x$ for small $x$. So a word in every document is not ignored, but in a large collection it counts for almost nothing. In four documents it counts for 0.1054, nearly a third of the weight of arctic.

Problem 4 (saturation in numbers). For a document of average length, so that $tf' = tf$, and $k_1 = 1.2$, compute the factor $tf/(k_1 + tf)$ for $tf = 1, 2, 5, 9$ and $10$. Compare what the first, second and tenth occurrences add.

Solution. The first occurrence adds 0.4545, the second 0.1705 and the tenth 0.0105, about one forty-third of the first.

$tf$ $tf/(1.2 + tf)$
1 $1/2.2 = 0.4545$
2 $2/3.2 = 0.6250$
5 $5/6.2 = 0.8065$
9 $9/10.2 = 0.8824$
10 $10/11.2 = 0.8929$

The second occurrence adds $0.6250 - 0.4545 = 0.1705$ and the tenth adds $0.8929 - 0.8824 = 0.0105$. The ratio of the first to the tenth is $0.4545/0.0105 \approx 43$. The factor stays below 1 for every $tf$, because the denominator exceeds the numerator by $k_1$. Under the hand formula of this article, in which the score is proportional to $tf$, the tenth occurrence would add exactly as much as the first. Saturation limits how far repetition alone can raise a score: fifty occurrences give a factor of $50/51.2 = 0.9766$, against 0.8065 for five.

What we have learned

A search engine is two processes sharing an index. The indexing process does everything that does not depend on the query: acquisition, analysis, and building postings with the statistics ranking will need. The query process analyzes the query the same way, retrieves candidates from the postings, ranks them and presents them. Four Arctic sentences showed each stage's output by hand, from stems such as climat to TF-IDF scores. This site's engine reproduced the same ranking with BM25F and showed where a working engine refines the hand formula. The stages are not independent: what indexing stores bounds what ranking can do, and an analysis decision such as keeping warmer apart from warm cannot be undone downstream.

The same structure persists in every engine. Documents become terms, terms become an index, a query becomes terms analyzed the same way, and a ranking function uses the index to order candidates. But four documents and a query typed by someone who knows exactly what they want are the easy case. The next article, How a Web Search Engine Answers a Query, follows one query through a web engine and shows what changes when the collection is billions of adversarial web pages and the query is two ambiguous words.

References

  • Croft, W. B., Metzler, D., and Strohman, T. (2010). Search Engines: Information Retrieval in Practice, chapter 2. Addison-Wesley. record · 12 pages
  • Karpukhin, V., Oğuz, B., Min, S., Lewis, P., Wu, L., Edunov, S., Chen, D., and Yih, W. (2020). Dense passage retrieval for open-domain question answering. In Proceedings of EMNLP 2020, 6769–6781. record · 15 pages
  • Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, chapters 1–2 and 6. Cambridge University Press. record · 102 pages
  • Nogueira, R., and Cho, K. (2019). Passage re-ranking with BERT. arXiv:1901.04085. record · 7 pages
  • Porter, M. F. (1980). An algorithm for suffix stripping. Program, 14(3), 130–137. record · 6 pages

Reviewed: verified, 16 Nov 2026 · checked against sources, 23 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 15 revisions