Lucene's Search Execution: impacts, WAND and MAXSCORE

The previous post covered the performance fight. This one goes inside the executor: how a query runs from Weight to Scorer to DocIdSetIterator, and what impacts, WAND and MAXSCORE each solve. 1. The execution skeleton Lucene executes a query as a tree: Query → Weight (reusable scoring logic) → Scorer (one per segment) → DocIdSetIterator (iterate docs) + score function Weight: segment-independent “how to score”; Scorer: segment-specific “which docs to score”; DISI: only nextDoc() / advance(doc). The naive execution: walk each clause’s postings, intersect/union, score each doc. Slow but correct. ...

October 20, 2026 · 3 min · daviszhen

Writing a Search Engine from Scratch: Rewriting Lucene in C++

A search engine looks like “inverted index plus TF-IDF” — until you try to make it agree with Lucene bit for bit. This series records an attempt to rewrite Lucene 10.4 in C++. Not a toy: Java must be able to read a C++-written index (CheckIndex OK), the same queries must return the same documents and the same score bits, and performance must land in the same ballpark. 1. Why rewrite The point isn’t reinventing a wheel. It’s three things: ...

October 20, 2026 · 3 min · daviszhen

Rewriting Lucene in C++ (Part 3): From 128 to 592 QPS — The Search Performance Fight

The first two posts were about “is it right.” This one is about “is it fast” — and not a 10% difference, but 5x. 1. Baseline: 128 vs 634 QPS 1M docs, luceneutil task set, Top-10: Scale C++ Java 250K docs 483 QPS 1,886 QPS 1M docs 128 QPS 634 QPS The gap isn’t constant — it grows with data size, which means the bottleneck is the per-document processing path, not startup overhead. ...

October 20, 2026 · 4 min · daviszhen

Rewriting Lucene in C++ (Part 2): Bit-Exact Scoring — The Floating-Point Traps of BM25

The previous post covered format compatibility: an index Java can read and verify. This one covers the harder part — scores must be bit-exact. Why so strict? Because verification is reconciliation: the same queries must return the same Top-N documents and the same score bits. If a score differs by one ULP (unit in the last place), documents can swap places at the boundary, the reconciliation never lines up, and you lose your only source of truth. ...

October 20, 2026 · 4 min · daviszhen

Rewriting Lucene in C++ (Part 1): Byte-Level Compatibility — When Java Reads a C++-Written Index

The easiest way to go wrong when porting Lucene to C++ is to say: “I’ll invent my own index format, and just be self-consistent.” That works, but it has no verification standard: you can’t prove your implementation is correct, only that it agrees with itself. I chose the other path: byte-level compatibility. The goal is that Java Lucene 10.4 can read a C++-written index (CheckIndex OK), C++ can read a Java-written index, and the dumps from both sides are byte-for-byte identical. ...

October 20, 2026 · 3 min · daviszhen