An inverted index maps a term to the documents containing it. This lets a search engine find candidate documents without reading every document from beginning to end for each search.
Think of the index at the back of a book: look up a word, then go to the listed pages. For a search engine, document identifiers take the place of page numbers.
1. Start with a small collection
Suppose we have three documents and use a simple analyzer that lowercases text and separates words. An analyzer is the set of steps that turns text into searchable terms.
D1: Red apple
D2: Green apple
D3: Red car
apple -> D1, D2
car -> D3
green -> D2
red -> D1, D3
