Text Processing and Indexing

Turning raw files into index terms and organizing those terms into an inverted index. Decoding, tokenization, stop words, normalization, stemming, spelling correction, and how indexes are built and compressed.

In Foundations, the thesis student's four Arctic documents were clean English sentences, and three simple steps turned them into index terms. A real collection arrives as files of bytes, in many encodings, formats, and languages. This topic follows such a collection until it is an index that a query can search, and records what each step loses along the way.

Text processing turns each file into a sequence of index terms. Indexing organizes those terms into an inverted index, the data structure behind nearly every search engine, and makes it buildable and storable at scale. A retrieval model can only rank documents by what the index recorded, and the index records only what text processing produced. Every later topic depends on decisions made here.

Those decisions fail silently. A mis-decoded character or an overly aggressive stemmer raises no error; queries just miss relevant documents or match wrong ones. The central trade-off is the one from What information retrieval is: every normalization that helps a query match more relevant documents also risks matching irrelevant ones.

The topic follows the pipeline in order:

  1. First it turns bytes into documents.
  2. Then it cuts the text into tokens and counts them. Zipf's law and Heaps' law explain why a few words dominate every collection and why the vocabulary never stops growing.
  3. Next it decides which tokens become terms: which words to drop, which variants to merge, and how to match misspellings.
  4. Finally it builds the inverted index, at a scale larger than memory, and compresses it.

The architecture article showed this pipeline on the Arctic sentences; here each stage gets its full treatment. Many measurements are made on one collection, Reuters-21578: 10,788 news stories from 1987, about 1.3 million tokens.

Articles

From bytes to text

  • From bytes to documents: establishes how bytes on disk become text and what counts as one document. Character encodings and how decoding fails, worked bit by bit on résumé. Format identification and text extraction, language identification worked by hand, and choosing the document unit.

Tokens and terms

  • Tokenization: establishes that where one token ends and the next begins is a choice with no neutral answer, and what each choice costs. Words, tokens, types, and terms. Hard English cases run through four tokenizers and counted on Reuters. Languages without spaces, long compounds, and subword tokenization.
  • Term statistics: Zipf's law and Heaps' law: establishes how unevenly a few words carry most of the text and how the vocabulary keeps growing with the collection. Both laws stated and fitted to Reuters, how far their predictions hold, and a proof that vocabulary growth of Heaps' form follows from a Zipf-like distribution.
  • Stop words: establishes what dropping the most common words saves and what it costs. How stop lists are built, what two published lists save and cost on Reuters, the course text's measurement on a larger collection, and why web search largely abandoned them.
  • Token normalization: establishes which tokens can safely count as the same term and what each merge costs. Equivalence classes against asymmetric query expansion, case folding measured on Reuters, accents, and the Unicode normalization forms worked code point by code point.
  • Stemming and lemmatization: establishes when reducing words to a common form helps a search and when it hurts. Stemming against lemmatization, the main stemmers and their errors measured on the Reuters vocabulary, what retrieval experiments show, and one sentence through the whole pipeline.
  • The Porter stemmer: establishes the rules by which the algorithm strips warming to warm but leaves warmer alone. The measure of a stem, the five steps of rules with worked traces and an interactive demo, and the algorithm run over the Reuters vocabulary.
  • Spelling correction and phonetic matching: establishes how a system finds the word a user meant to type. Edit distance and its dynamic-programming table (with an interactive demo), k-gram indexes on the Reuters dictionary, the noisy channel model worked through, and Soundex for names.
  • Wildcard queries: establishes how a dictionary is searched for patterns such as m*n, with the permuterm index and the k-gram index compared.

The inverted index

  • The inverted index: establishes the structure that answers a query without reading the text again. From the term-document incidence matrix to dictionaries and postings lists. An index built by sorting on the Arctic sentences, dictionary lookup by binary search, and what each posting can store.
  • Index construction: establishes how to sort far more (term, document) pairs than fit in memory. Blocked sort-based and single-pass in-memory indexing, each traced on the Arctic sentences and measured on Reuters. Distributed indexing with MapReduce, and keeping an index current, with the merge costs simulated.
  • Dictionary compression: establishes how small the dictionary can be made while it stays searchable in memory. Fixed-width entries, the dictionary as a string, blocked storage and front coding, each sized for RCV1 and for the Reuters vocabulary.
  • Index compression: establishes how small the postings can be made without losing anything. Gaps, and variable byte, Elias gamma and delta codes worked bit by bit on two Reuters postings lists, with Golomb and Rice codes. Every code measured on the whole collection, and why compression makes search faster as well as smaller.

Building one

  • Building an indexing pipeline: shows this topic's decisions inside an ordinary indexer. The stages of a working indexer, illustrated with my course homework and measured on Reuters, and what I would change.

Course materials

My indexer for the course is HW01 on GitHub. It tokenizes and stems a document collection, builds an inverted index, and reports its memory use.

References

  • Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, chapters 2–5. Cambridge University Press. record · 102 pages
  • Croft, W. B., Metzler, D., and Strohman, T. (2010). Search Engines: Information Retrieval in Practice, chapters 3–5. Addison-Wesley. record · 12 pages
  • Zobel, J., and Moffat, A. (2006). Inverted files for text search engines. ACM Computing Surveys, 38(2), article 6. record · 2 pages

Reviewed: verified, 16 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 16 Nov 2026 · 7 revisions