Class BitStreamIndexWriter
- java.lang.Object
-
- it.unimi.di.big.mg4j.index.AbstractBitStreamIndexWriter
-
- it.unimi.di.big.mg4j.index.BitStreamIndexWriter
-
- All Implemented Interfaces:
IndexWriter
- Direct Known Subclasses:
SkipBitStreamIndexWriter
public class BitStreamIndexWriter extends AbstractBitStreamIndexWriter
Writes a bitstream-based interleaved index.Indices written by this class are somewhat classical. Each inverted list contains the frequency, followed by gap-encoded pointers optionally interleaved with counts and gap-encoded positions. The compression technique used for each component can be chosen using a compression flag.
Interleaved indices of this kind are essentially unusable, as all information in each posting list must be entirely read (no skipping is possible). One possible exception is disjunctive queries which use all the information in the index (e.g., with proximity scoring). Another possible usage is to test the compression power of different codes, as essentially all classical compression techniques are available. But, most importantly, the
Scantool generates interleaved indices as batches (albeit not using this class).These are the files that form an interleaved index:
- basename.properties
- A Java property file containing information about the index.
- basename.terms
- For each indexed term, the corresponding literal string in UTF-8 encoding. More precisely, the i-th line of the file (starting from 0) contains the literal string corresponding to term index i.
- basename.frequencies
- For each term, the number of documents in which the term appears in γ coding. More precisely, i-th integer of the file (starting from 0) is the number of documents in which the term of index i appears. This information appears also at the start of each posting list in the index, but it is also stored in this file for convenience.
- basename.sizes (not generated for payload-based indices)
- For each indexed document, the corresponding size (=number of words) in γ coding. More precisely, i-th integer of the file (starting from 0) is the size in words of the document of index i.
- basename.index
- The inverted index.
- basename.offsets
- For each term, the bit offset in basename.index at which the inverted lists start. More precisely, the first integer is the offset for term 0 in γ coding, and then the i-th integer is the difference between the i-th and the i−1-th offset in γ coding. If T terms were indexed, this file will contain T+1 integers, the last being the difference (in bits) between the length of the entire inverted index and the offset of the last inverted list. Thus, in practice, the file is formed by the number zero (the offset of the first list) followed by the length in bits of each inverted list.
- basename.occurrencies
- For each term, its occurrency, that is, the number of its occurrences throughout the whole document collection, in γ coding. More precisely, the i-th integer of the file (starting from 0) is the occurrency of the term of index i.
- basename.posnumbits
- For each term, the number of bits spent to store positions in γ code (used just for quantum-optimisation purposes).
- basename.sumsmaxpos
- For each term, the sum of the maximum positions in which the term appears (necessary to build a
QuasiSuccinctIndex) in δ code. - basename.stats
- Miscellaneous detailed statistics about the index.
- Since:
- 0.6
- Author:
- Paolo Boldi, Sebastiano Vigna
-
-
Field Summary
Fields Modifier and Type Field Description protected intbThe parameterbfor Golomb coding of pointers.protected static intBEFORE_COUNTThis value ofstatecan be assumed only in indices that contain counts; it means that we are positioned just before the count for the current document record.protected static intBEFORE_DOCUMENT_RECORDThis value ofstatemeans that we are ready to callnewDocumentRecord().protected static intBEFORE_FREQUENCYThis value ofstatemeans that we are positioned at the start of an inverted list, and we should callwriteFrequency(long).protected static intBEFORE_INVERTED_LISTThis value ofstatemeans that we should callnewInvertedList().protected static intBEFORE_PAYLOADThis value ofstatecan be assumed only in indices that contain payloads; it means that we are positioned just before the payload for the current document record.protected static intBEFORE_POINTERThis value ofstatemeans that we just started a new document record, and we should callwriteDocumentPointer(OutputBitStream, long).protected static intBEFORE_POSITIONSThis value ofstatecan be assumed only in indices that contain document positions; it means that we are positioned just before the position list of the current document record.protected longcurrentDocumentThe current document pointer.protected static intFIRST_UNUSED_STATEThis is the first unused state.protected longfrequencyThe number of document records that the current inverted list will contain.protected longlastDocumentThe last document pointer in the current list.protected longlastInvertedListPosThe position (in bytes) where the last inverted list started.protected intlog2bThe parameterlog2bfor Golomb coding of pointers; it is the most significant bit ofb.intmaxCountThe maximum number of positions in a document record so far.protected OutputBitStreamobsThe underlyingOutputBitStream.protected intstateThe current state of the writer.protected longwrittenDocumentsThe number of document records already written for the current inverted list.-
Fields inherited from class it.unimi.di.big.mg4j.index.AbstractBitStreamIndexWriter
bitsForCounts, bitsForFrequencies, bitsForPayloads, bitsForPointers, bitsForPositions, countCoding, currentTerm, flags, frequencyCoding, hasCounts, hasPayloads, hasPositions, numberOfDocuments, numberOfOccurrences, numberOfPostings, pointerCoding, positionCoding
-
-
Constructor Summary
Constructors Constructor Description BitStreamIndexWriter(IOFactory ioFactory, CharSequence basename, long numberOfDocuments, boolean writeOffsets, Map<CompressionFlags.Component,CompressionFlags.Coding> flags)Creates a new index writer with the specified basename.
-
Method Summary
Modifier and Type Method Description voidclose()Closes this index writer, completing the index creation process and releasing all resources.OutputBitStreamnewDocumentRecord()Starts a new document record.longnewInvertedList()Starts a new inverted list.Propertiesproperties()Returns properties of the index generated by this index writer.voidwriteDocumentPointer(OutputBitStream out, long pointer)Writes a document pointer.voidwriteDocumentPositions(OutputBitStream out, int[] position, int offset, int count, int docSize)Writes the positions of the occurrences of the current term in the current document to the givenOutputBitStream.voidwriteFrequency(long frequency)Writes the frequency.voidwritePayload(OutputBitStream out, Payload payload)Writes the payload for the current document.voidwritePositionCount(OutputBitStream out, int count)Writes the count of the occurrences of the current term in the current document to the givenOutputBitStream.longwrittenBits()Returns the overall number of bits written onto the underlying stream(s).-
Methods inherited from class it.unimi.di.big.mg4j.index.AbstractBitStreamIndexWriter
printStats
-
-
-
-
Field Detail
-
BEFORE_INVERTED_LIST
protected static final int BEFORE_INVERTED_LIST
This value ofstatemeans that we should callnewInvertedList().- See Also:
- Constant Field Values
-
BEFORE_FREQUENCY
protected static final int BEFORE_FREQUENCY
This value ofstatemeans that we are positioned at the start of an inverted list, and we should callwriteFrequency(long).- See Also:
- Constant Field Values
-
BEFORE_DOCUMENT_RECORD
protected static final int BEFORE_DOCUMENT_RECORD
This value ofstatemeans that we are ready to callnewDocumentRecord().- See Also:
- Constant Field Values
-
BEFORE_POINTER
protected static final int BEFORE_POINTER
This value ofstatemeans that we just started a new document record, and we should callwriteDocumentPointer(OutputBitStream, long).- See Also:
- Constant Field Values
-
BEFORE_PAYLOAD
protected static final int BEFORE_PAYLOAD
This value ofstatecan be assumed only in indices that contain payloads; it means that we are positioned just before the payload for the current document record.- See Also:
- Constant Field Values
-
BEFORE_COUNT
protected static final int BEFORE_COUNT
This value ofstatecan be assumed only in indices that contain counts; it means that we are positioned just before the count for the current document record.- See Also:
- Constant Field Values
-
BEFORE_POSITIONS
protected static final int BEFORE_POSITIONS
This value ofstatecan be assumed only in indices that contain document positions; it means that we are positioned just before the position list of the current document record.- See Also:
- Constant Field Values
-
FIRST_UNUSED_STATE
protected static final int FIRST_UNUSED_STATE
This is the first unused state. Subclasses may start from this value to define new states.- See Also:
- Constant Field Values
-
obs
protected OutputBitStream obs
The underlyingOutputBitStream.
-
state
protected int state
The current state of the writer.
-
frequency
protected long frequency
The number of document records that the current inverted list will contain.
-
writtenDocuments
protected long writtenDocuments
The number of document records already written for the current inverted list.
-
currentDocument
protected long currentDocument
The current document pointer.
-
lastDocument
protected long lastDocument
The last document pointer in the current list.
-
lastInvertedListPos
protected long lastInvertedListPos
The position (in bytes) where the last inverted list started.
-
maxCount
public int maxCount
The maximum number of positions in a document record so far.
-
b
protected int b
The parameterbfor Golomb coding of pointers.
-
log2b
protected int log2b
The parameterlog2bfor Golomb coding of pointers; it is the most significant bit ofb.
-
-
Constructor Detail
-
BitStreamIndexWriter
public BitStreamIndexWriter(IOFactory ioFactory, CharSequence basename, long numberOfDocuments, boolean writeOffsets, Map<CompressionFlags.Component,CompressionFlags.Coding> flags) throws IOException
Creates a new index writer with the specified basename. The index will be written on a file (stemmed with .index). IfwriteOffsets, also an offset file will be produced (stemmed with .offsets). Whenclose()will be called, the property file will also be produced (stemmed with .properties), or enriched if it already exists.- Parameters:
ioFactory- the factory that will be used to perform I/O.basename- the basename.numberOfDocuments- the number of documents in the collection to be indexed.writeOffsets- iftrue, the offset file will also be produced.flags- a flag map setting the coding techniques to be used (seeCompressionFlags).- Throws:
IOException
-
-
Method Detail
-
newInvertedList
public long newInvertedList() throws IOExceptionDescription copied from interface:IndexWriterStarts a new inverted list. The previous inverted list, if any, is actually written to the underlying bit stream.- Returns:
- the position (in bits) of the underlying bit stream where the new inverted list starts.
- Throws:
IOException
-
writeFrequency
public void writeFrequency(long frequency) throws IOExceptionDescription copied from interface:IndexWriterWrites the frequency.- Parameters:
frequency- the (positive) number of document records that this inverted list will contain.- Throws:
IOException
-
newDocumentRecord
public OutputBitStream newDocumentRecord() throws IOException
Description copied from interface:IndexWriterStarts a new document record.This method must be called exactly exactly f times, where f is the frequency specified with
IndexWriter.writeFrequency(long).- Returns:
- the output bit stream where the next document record data should be written, if necessary, or
null, ifIndexWriter.writeDocumentPointer(OutputBitStream, long)ignores its first argument. - Throws:
IOException
-
writeDocumentPointer
public void writeDocumentPointer(OutputBitStream out, long pointer) throws IOException
Description copied from interface:IndexWriterWrites a document pointer.This method must be called immediately after
IndexWriter.newDocumentRecord().- Parameters:
out- the output bit stream where the pointer will be written.pointer- the document pointer.- Throws:
IOException
-
writePayload
public void writePayload(OutputBitStream out, Payload payload) throws IOException
Description copied from interface:IndexWriterWrites the payload for the current document.This method must be called immediately after
IndexWriter.writeDocumentPointer(OutputBitStream, long).- Parameters:
out- the output bit stream where the payload will be written.payload- the payload.- Throws:
IOException
-
close
public void close() throws IOExceptionDescription copied from interface:IndexWriterCloses this index writer, completing the index creation process and releasing all resources.- Throws:
IOException
-
writePositionCount
public void writePositionCount(OutputBitStream out, int count) throws IOException
Description copied from interface:IndexWriterWrites the count of the occurrences of the current term in the current document to the givenOutputBitStream.- Parameters:
out- the output stream where the occurrences should be written.count- the count.- Throws:
IOException
-
writeDocumentPositions
public void writeDocumentPositions(OutputBitStream out, int[] position, int offset, int count, int docSize) throws IOException
Description copied from interface:IndexWriterWrites the positions of the occurrences of the current term in the current document to the givenOutputBitStream.- Parameters:
out- the output stream where the occurrences should be written.position- the position vector (a sequence of strictly increasing natural numbers).offset- the first valid entry inposition.count- the number of valid entries inpositionstarting fromoffset.docSize- the size of the current document (only for Golomb and interpolative coding; you can safely pass -1 otherwise).- Throws:
IOException
-
writtenBits
public long writtenBits()
Description copied from interface:IndexWriterReturns the overall number of bits written onto the underlying stream(s).- Returns:
- the number of bits written, according to the variables keeping statistical records.
-
properties
public Properties properties()
Description copied from interface:IndexWriterReturns properties of the index generated by this index writer.This method should only be called after
IndexWriter.close(). It returns a new property object containing values for (whenever appropriate)Index.PropertyKeys.DOCUMENTS,Index.PropertyKeys.TERMS,Index.PropertyKeys.POSTINGS,Index.PropertyKeys.MAXCOUNT,Index.PropertyKeys.INDEXCLASS,Index.PropertyKeys.CODING,Index.PropertyKeys.PAYLOADCLASS,BitStreamIndex.PropertyKeys.SKIPQUANTUM, andBitStreamIndex.PropertyKeys.SKIPHEIGHT.- Returns:
- properties a new set of properties for the just created index.
-
-