Index generation and access.
This package contains the classes that handle index generation and access. The interval iterators defined in {@link it.unimi.di.big.mg4j.search} build upon the classes of this package to provide answer to queries using interval semantics, but it is also possible to access an index directly.
You can easily build indices using the tools in {@link it.unimi.di.big.mg4j.tool}. Once an index has been built, it can be opened using an {@link it.unimi.di.big.mg4j.index.Index} object, which gathers metadata that is necessary to access the index. You do not create an {@link it.unimi.di.big.mg4j.index.Index} with a constructor: rather, you use the static factory {@link it.unimi.di.big.mg4j.index.Index#getInstance(CharSequence)} (or one of its variants) to create an instance. This is necessary so that different kind of indices can be treated transparently: for example, the factory may return a {@link it.unimi.di.big.mg4j.index.cluster.IndexCluster} if the index is actually a cluster, but you do not need to know that.
From an {@link it.unimi.di.big.mg4j.index.Index}, you can easily obtain either an {@link it.unimi.di.big.mg4j.index.IndexReader}, which allows to scan sequentially or randomly the index. In turn from an {@link it.unimi.di.big.mg4j.index.IndexReader} you can obtain a {@link it.unimi.di.big.mg4j.index.IndexIterator} returning the documents containing a certain term and the position of the term within the document.
But there is more: an {@link it.unimi.di.big.mg4j.index.IndexIterator} is a kind of {@link it.unimi.di.big.mg4j.search.DocumentIterator}, and {@link it.unimi.di.big.mg4j.search.DocumentIterator}s can be combined in several ways using the classes of the package {@link it.unimi.di.big.mg4j.search}: for instance, you can combine document iterators using AND/OR. Note that you can combine document iterators on different indices, but of course the operation is meaningful only if the two indices contain different information about the same document collection (e.g., title and main text).
More importantly, if the index is full text (the default) for each document containing the term you can get interval iterators that return intervals representing extents of text satisfying the query: for instance, in case of an AND of two terms, the intervals will contain both terms.
An inverted index is made by a sequence of inverted lists (one inverted list for each term). Inverted lists are made by document records: each document record contains information about the occurrences of the term within a certain document.
The number of documents in which a term appear, that is, the length of the inverted list of the term, is called the {@linkplain it.unimi.di.big.mg4j.index.IndexIterator#frequency() frequency}.
Each document record contains the (document) {@linkplain it.unimi.di.big.mg4j.index.IndexIterator#document() pointer}, which identifies the document within the collection; optionally, the {@linkplain it.unimi.di.big.mg4j.index.IndexIterator#count() count}, that is, the number of times the term appears in the given document (it is also common to call the count “within-document frequency”, but we find this usage confusing); finally, optionally we might have the {@linkplain it.unimi.di.big.mg4j.index.IndexIterator#nextPosition() positions} in which the term occurs. Some indices store also a user-defined {@linkplain it.unimi.di.big.mg4j.index.IndexIterator#payload() payload}.
Traditional indices are based on gap encoding techniques: sequence of increasing integers, such as document pointers, are stored by writing the gaps between successive pointers using suitable instantaneous codes. MG4J supports this kind of indices (see {@link it.unimi.di.big.mg4j.index.BitStreamIndexWriter} and {@link it.unimi.di.big.mg4j.index.BitStreamHPIndexWriter}), but since version 5.0 the default index is a new kind of {@linkplain it.unimi.di.big.mg4j.index.QuasiSuccinctIndexWriter quasi-succinct index} that has major performance improvements with respect to traditional gap-encoded indices.