• Non ci sono risultati.

4 Index construction

Nel documento to Information Retrieval (pagine 89-93)

In this chapter, we look at how to construct an inverted index. We will call this process index construction or indexing for short and the process or

ma-INDEXING

chine that performs it the indexer.

INDEXER

To build an index, we essentially have to perform a sort of the postings file. This is non-trivial for the large data sets that are typical in modern information retrieval. We will first introduce blocked sort-based indexing, an efficient single-machine algorithm designed for static collections (Sec-tion 4.2). For very large collec(Sec-tions like the web, indexing has to be dis-tributed over large computer clusters with hundreds or thousands of ma-chines (Section 4.4). Collections with frequent changes require dynamic in-dexing so that changes in the collection are immediately reflected in the index (Section 4.5). Finally, we will cover some complicating issues that can arise in indexing – such as security and indexes for ranked retrieval – in Section 4.6.

Frequently, documents are not on a local file system, but have to be spi-dered or crawled, as we discuss in Chapter 20. Also, the indexer needs raw text, but documents are encoded in many ways, as we mentioned in Chap-ter 2. There are inChap-teractions between index compression (see ChapChap-ter 5) and construction because intermediate posting lists may have to be compressed and decompressed during construction. Finally documents are often en-capsulated in varied content management systems, email applications and databases (we give some examples in Section 4.7). While most of these appli-cations can be accessed via http, native APIs are usually more efficient. The reader should be aware that building the subsystem that feeds raw text to the indexing process can in itself be a challenging problem.

4.1 Hardware basics

Many decisions when building information retrieval systems are due to hard-ware constraints. We therefore begin this chapter with a brief review of as-pects of computer hardware that are important for IR system design.

Perfor-symbol statistic value

s disk seek 5 ms = 5×10−3 s

b block transfer from disk (per byte) 0.1 µs = 10−7s

processor’s clock cycle 10−9 s

p other processor ops (e.g., compare&swap words) 0.1 µs = 10−7s

Table 4.1 Tyical system parameters in 2007. A disk seek is the time needed to position the disk head in a new position. The block transfer rate is the rate of transfer when the head is in the right position.

mance characteristics typical of systems in 2007 are shown in Table 4.1. We now give a list of hardware basics that we will need in this book for system design.

• Access to data in memory is much faster than access to data on disk. It takes a few processor cycles (about 10−9seconds) to access an integer in memory, but 100 times as long to transfer it from disk (about 10−7 sec-onds). Consequently, we want to keep as much data as possible in mem-ory, especially those data that we need to access frequently.

• When doing a disk read or write, it takes a while for the disk head to move to the right track (5ms in Table 4.1). In order to maximize data transfer rates, chunks of data that will be read together should therefore be stored contiguously on disk. For example, using the numbers in Table 4.1 it will take as little as 100 seconds to transfer one GB from disk to memory if it is stored as one block, but up to 100+10,000× (5×10−3) =150 seconds if it is stored in 10,000 non-contiguous chunks because we need to move the disk head up to 10,000 times.

• Operating systems generally read and write entire blocks. So reading a single byte from a disk takes as much time as reading the entire block.

Block sizes of 8 KB, 16 KB, 32 KB and 64 KB are common in 2007.

• Data transfers from disk to memory are handled by the system bus, not by the processor. This means that the processor is available to process data while it is being read. We can exploit this fact to speed up data transfers by storing compressed data on disk: the total time of reading and then decompressing compressed data is less than reading uncompressed data.

4.2 Blocked sort-based indexing

The basic steps in constructing a non-positional index are depicted in Fig-ure 1.4 (page 8). We first make a pass through the collection assembling all

Figure 4.1 Document from the Reuters newswire.

postings (i.e., term-docID pairs). We then sort the entries with the term as the dominant key and docID as the secondary key. Finally, we organize the docIDs for each term into a posting list and compute statistics like term and document frequency. For small collections, all this can be done in memory.

In this chapter, we describe methods for large collections that require the use of secondary storage.

To make index construction more efficient, we represent postings as termID-docID pairs (instead of term-termID-docID pairs as we did in Figure 1.4). We can build the mapping from terms to termIDs on the fly while we are process-ing the collection; or, in a two-pass approach, we compile the vocabulary in the first pass and construct the inverted index in the second pass. The index construction algorithms described in this chapter use on-the-fly construction because it avoids the extra pass through the data and works well if the vo-cabulary is not too large. Section 4.7 gives references to algorithms that can handle very large vocabularies.

We will work with the Reuters-RCV1 collection as our model collection

REUTERS-RCV1

in this chapter, a collection with roughly one gigabyte of text. It consists of about 800,000 documents that were sent over the Reuters newswire dur-ing a one year period between August 20, 1996, and August 19, 1997. A typical document is shown in Figure 4.1, but note that we will ignore multi-media information like images in this book and only be concerned with text.

Reuters-RCV1 covers a wide range of international topics, including politics, business, sports and (as in the example) science. Some key statistics of the collection are shown in Table 4.2.1

1. The numbers in this table correspond to the third line (“case folding”) in Table 5.1, page 80.

For the definitions oftokenandtype, see Chapter 2, page 22.

symbol statistic value

N documents 800,000

dlenave avg. # tokens per document 200

M term types 400,000

avg. # bytes per token (incl. spaces/punct.) 6 avg. # bytes per token (without spaces/punct.) 4.5

avg. # bytes per term type 7.5

non-positional postings 100,000,000

Table 4.2 Collection statistics for Reuters-RCV1. Values are rounded for the com-putations in this chapter. The unrounded values are: 806,791 documents, 222 tokens per document, 391,523 term types (or distinct terms), 6.04 bytes per token with spaces and punctuation, 4.5 bytes per token without spaces and punctuation, 7.5 bytes per term type and 96,969,056 non-positional postings.

BLOCKMERGEINDEXCONSTRUCTION() 1 n0

2 while (all documents have not been processed) 3 do nn+1

4 blockPARSENEXTBLOCK() 5 INVERT(block)

6 WRITEBLOCKTODISK(block, fn) 7 MERGEBLOCKS(f1, . . . , fn; fmerged)

Figure 4.2 Blocked sort-based indexing. The algorithm stores inverted blocks in files f1, . . . , fnand the merged index in fmerged.

Reuters-RCV1 has 100 million postings. If we used 8 bytes per posting (4 bytes each for termID and docID), these 100 million postings will require 0.8 gigabyte of storage. Typical collections today are often one or two orders of magnitude larger than Reuters-RCV1. You can easily see how such collec-tions will overwhelm even large computers if we tried to sort their postings files in memory. If the size of the postings file is within a small factor of avail-able memory, then the compression techniques introduced in Chapter 5 can help; but the postings file of many large collections cannot fit into memory even after compression.

With main memory insufficient, we need to use an external sorting

algo-EXTERNAL SORTING

rithm, i.e., one that uses disk. For acceptable speed, the central requirement of such an algorithm is that it minimize the number of random disk seeks during sorting (sequential disk reads are far faster than seeks as we explained above). One solution is the blocked sort-based algorithm in Figure 4.2, which

brutus d1,d3 caesar d1,d2,d4 noble d5

with d1,d2,d3,d5

brutus d6,d7 caesar d8,d9 julius d10 killed d8

posting lists

Nel documento to Information Retrieval (pagine 89-93)