4.3 Single-pass in-memory indexing
Blocked sort-based indexing has excellent scaling properties, but it needs
a data structure for mapping terms to termIDs. For very large collections,
this data structure does not fit into memory. A more scalable alternative is
single-pass in-memory indexing or SPIMI. SPIMI uses terms SINGLE-PASS instead of termIDs,
IN-MEMORY INDEXING writes each block’s dictionary to disk, and then starts a newdictionary for the
next block. SPIMI can index collections of any size as long as there is enough
disk space available.
The SPIMI algorithm is shown in Figure 4.4. The part of the algorithm that
parses documents and turns them into a stream of term–docID pairs, which
we call tokens here, has been omitted. SPIMI-INVERT is called repeatedly on
the token stream until the entire collection has been processed.
Tokens are processed one by one (line 4) during each successive call of
SPIMI-INVERT. When a term occurs for the first time, it is added to the
dictionary (best implemented as a hash), and a new postings list is created
(line 6). The call in line 7 returns this postings list for subsequent occurrences
of the term.
A difference between BSBI and SPIMI is that SPIMI adds a posting directly
to its postings list (line 10). Instead of first collecting all termID–docID
pairs and then sorting them(aswe did in BSBI), each postings list is dynamic
(i.e., its size is adjusted as it grows) and it is immediately available to collect
postings. This has two advantages: It is faster because there is no sorting
required, and it saves memory because we keep track of the term a postings