- 2073 Bhadra · 10 marks
Lucene architecture and indexing approach
Short answer
Lucene is a Java search library built around Document, Analyzer, IndexWriter, and IndexSearcher. Indexing creates an inverted index from tokenized text and stores immutable segments. Searching reads all segments and ranks documents using BM25 scoring.
Explain LUCENE architecture and its data indexing approach.
Apache Lucene is a high-performance, open-source full-text search library written in Java. It has no crawler and no user interface: it provides the core API to index and search text. Solr and Elasticsearch are built on it.
Architecture
Data source -> Document -> IndexWriter -> Index (Directory)
(Fields) + Analyzer |
v
User query -> QueryParser -> Query -> IndexSearcher -> TopDocs
+ Analyzer (IndexReader) (hits)
Main classes:
- Document: the unit of indexing and search; a set of Fields (name/value pairs such as title, content, date). Fields can be stored, indexed and tokenized.
- Analyzer: converts field text into tokens (a tokenizer plus filters such as lower-casing, stop-word removal and stemming).
- IndexWriter: creates and updates the index; it adds, deletes and updates documents.
- Directory: where the index lives (
FSDirectoryon disk,RAMDirectoryin memory). - IndexReader / IndexSearcher: open the index and run searches.
- QueryParser / Query: parses the user's query string into Query objects (TermQuery, BooleanQuery, PhraseQuery, WildcardQuery, RangeQuery).
- TopDocs / ScoreDoc: the ranked results with their scores.
Indexing approach: the inverted index
Lucene uses an inverted index: a mapping from each term to the documents that contain it (like the index at the back of a book), instead of a map from each document to its words.
Steps:
- Create a
Documentwith fields from the source record. - The
Analyzertokenizes the text, lower-cases it, removes stop words and stems the words. IndexWriterbuilds the term dictionary and the postings lists (doc id, term frequency, positions) and writes them to the index.
Example: Doc1 = "Big data tools", Doc2 = "Data is big", Doc3 = "Hadoop tools".
| Term | Postings |
|---|---|
| big | Doc1, Doc2 |
| data | Doc1, Doc2 |
| hadoop | Doc3 |
| tools | Doc1, Doc3 |
A query "big AND tools" intersects the postings lists of big and tools and returns Doc1.
Segments
The index is made of immutable segments. New documents are buffered in memory and flushed to disk as a new small segment. Background merging combines segments into larger ones and removes deleted documents. This makes writing fast; a search reads all the segments.
Scoring
Each hit is scored by relevance using TF-IDF (in older versions) or BM25 (the current default): terms that are frequent in the document but rare in the collection give a higher score.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Short note: Lucene analyzers · Big Data Technologies, chapter 5
- Components of indexing and searching · Big Data Technologies, chapter 5 · asked 2×
- Google File System architecture · Big Data Technologies, chapter 2 · asked 2×
- HBase architecture · Big Data Technologies, chapter 4 · asked 2×
- Data warehouse architecture and components · Data Mining, chapter 1
- National data warehouse process architecture · Data Mining, chapter 1
- Architecture of data mining system · Data Mining, chapter 1
- Short note: Likelihood approach to anomalies · Data Mining, chapter 6