Web / Apache Lucene Interview questions
What is an inverted index in Lucene?
An inverted index flips the natural document-to-word relationship: instead of storing "document 1 contains these words," it stores "this word appears in these documents." That's what makes searching millions of documents for a term nearly instant instead of scanning each one.
For every unique term, Lucene keeps a postings list - the document IDs (and often positions and frequencies) where that term occurs.
| Term | Postings (Doc IDs) |
| lucene | 1, 3, 7 |
| search | 1, 2, 3, 9 |
At query time, Lucene intersects or unions the relevant postings lists rather than touching every stored document, which is the fundamental reason full-text search scales the way it does.
More Related questions...