Namespace Lucene.Net.Codecs.Lucene40
Lucene 4.0 file format.
Apache Lucene - Index File Formats
Introduction
This document defines the index file formats used in this version of Lucene. If you are using a different version of Lucene, please consult the copy of docs/
that was distributed with the version you are using.
Apache Lucene is written in Java, but several efforts are underway to write versions of Lucene in other programming languages including this implementation in .NET. If these versions are to remain compatible with Apache Lucene, then a language-independent definition of the Lucene index format is required. This document thus attempts to provide a complete and independent definition of the Apache Lucene file formats.
As Lucene evolves, this document should evolve. Versions of Lucene in different programming languages should endeavor to agree on file formats, and generate new versions of this document.
Definitions
The fundamental concepts in Lucene are index, document, field and term.
An index contains a sequence of documents.
A document is a sequence of fields.
A field is a named sequence of terms.
A term is a sequence of bytes.
The same sequence of bytes in two different fields is considered a different term. Thus terms are represented as a pair: the string naming the field, and the bytes within the field.
Inverted Indexing
The index stores statistics about terms in order to make term-based search more efficient. Lucene's index falls into the family of indexes known as an inverted index. This is because it can list, for a term, the documents that contain it. This is the inverse of the natural relationship, in which documents list terms.
Types of Fields
In Lucene, fields may be stored, in which case their text is stored in the index literally, in a non-inverted manner. Fields that are inverted are called indexed. A field may be both stored and indexed.
The text of a field may be tokenized into terms to be indexed, or the text of a field may be used literally as a term to be indexed. Most fields are tokenized, but sometimes it is useful for certain identifier fields to be indexed literally.
See the Field docs for more information on Fields.
Segments
Lucene indexes may be composed of multiple sub-indexes, or segments. Each segment is a fully independent index, which could be searched separately. Indexes evolve by:
Creating new segments for newly added documents.
Merging existing segments.
Searches may involve multiple segments and/or multiple indexes, each index potentially composed of a set of segments.
Document Numbers
Internally, Lucene refers to documents by an integer document number. The first document added to an index is numbered zero, and each subsequent document added gets a number one greater than the previous.
Note that a document's number may change, so caution should be taken when storing these numbers outside of Lucene. In particular, numbers may change in the following situations:
The numbers stored in each segment are unique only within the segment, and must be converted before they can be used in a larger context. The standard technique is to allocate each segment a range of values, based on the range of numbers used in that segment. To convert a document number from a segment to an external value, the segment's base document number is added. To convert an external value back to a segment-specific value, the segment is identified by the range that the external value is in, and the segment's base value is subtracted. For example two five document segments might be combined, so that the first segment has a base value of zero, and the second of five. Document three from the second segment would have an external value of eight.
When documents are deleted, gaps are created in the numbering. These are eventually removed as the index evolves through merging. Deleted documents are dropped when segments are merged. A freshly-merged segment thus has no gaps in its numbering.
Index Structure Overview
Each segment index maintains the following:
Segment info. This contains metadata about a segment, such as the number of documents, what files it uses,
Field names. This contains the set of field names used in the index.
Stored Field values. This contains, for each document, a list of attribute-value pairs, where the attributes are field names. These are used to store auxiliary information about the document, such as its title, url, or an identifier to access a database. The set of stored fields are what is returned for each hit when searching. This is keyed by document number.
Term dictionary. A dictionary containing all of the terms used in all of the indexed fields of all of the documents. The dictionary also contains the number of documents which contain the term, and pointers to the term's frequency and proximity data.
Term Frequency data. For each term in the dictionary, the numbers of all the documents that contain that term, and the frequency of the term in that document, unless frequencies are omitted (IndexOptions.DOCS_ONLY)
Term Proximity data. For each term in the dictionary, the positions that the term occurs in each document. Note that this will not exist if all fields in all documents omit position data.
Normalization factors. For each field in each document, a value is stored that is multiplied into the score for hits on that field.
Term Vectors. For each field in each document, the term vector (sometimes called document vector) may be stored. A term vector consists of term text and term frequency. To add Term Vectors to your index see the Field constructors
Per-document values. Like stored values, these are also keyed by document number, but are generally intended to be loaded into main memory for fast access. Whereas stored values are generally intended for summary results from searches, per-document values are useful for things like scoring factors.
Deleted documents. An optional file indicating which documents are deleted.
Details on each of these are provided in their linked pages.
File Naming
All files belonging to a segment have the same name with varying extensions. The extensions correspond to the different file formats described below. When using the Compound File format (default in 1.4 and greater) these files (except for the Segment info file, the Lock file, and Deleted documents file) are collapsed into a single .cfs file (see below for details)
Typically, all segments in an index are stored in a single directory, although this is not required.
As of version 2.1 (lock-less commits), file names are never re-used (there is one exception, "segments.gen", see below). That is, when any file is saved to the Directory it is given a never before used filename. This is achieved using a simple generations approach. For example, the first segments file is segments_1
, then segments_2
, etc. The generation is a sequential long integer represented in alpha-numeric (base 36) form.
Summary of File Extensions
The following table summarizes the names and extensions of the files in Lucene:
Name | Extension | Brief Description |
---|---|---|
Segments File | segments.gen, segments_N | Stores information about a commit point |
Lock File | write.lock | The Write lock prevents multiple IndexWriters from writing to the same file. |
Segment Info | .si | Stores metadata about a segment |
Compound File | .cfs, .cfe | An optional "virtual" file consisting of all the other index files for systems that frequently run out of file handles. |
Fields | .fnm | Stores information about the fields |
Field Index | .fdx | Contains pointers to field data |
Field Data | .fdt | The stored fields for documents |
Term Dictionary | .tim | The term dictionary, stores term info |
Term Index | .tip | The index into the Term Dictionary |
Frequencies | .frq | Contains the list of docs which contain each term along with frequency |
Positions | .prx | Stores position information about where a term occurs in the index |
Norms | .nrm.cfs, .nrm.cfe | Encodes length and boost factors for docs and fields |
Per-Document Values | .dv.cfs, .dv.cfe | Encodes additional scoring factors or other per-document information. |
Term Vector Index | .tvx | Stores offset into the document data file |
Term Vector Documents | .tvd | Contains information about each document that has term vectors |
Term Vector Fields | .tvf | The field level info about term vectors |
Deleted Documents | .del | Info about what files are deleted |
Lock File
The write lock, which is stored in the index directory by default, is named
write.lock
. If the lock directory is different from the index directory then
the write lock will be named XXXX-write.lock
where XXXX is a unique prefix
derived from the full path to the index directory. When this file is present, a
writer is currently modifying the index (adding or removing documents). This
lock file ensures that only one writer is modifying the index at a time.
History
Compatibility notes are provided in this document, describing how file formats have changed from prior versions:
In version 2.1, the file format was changed to allow lock-less commits (ie, no more commit lock). The change is fully backwards compatible: you can open a pre-2.1 index for searching or adding/deleting of docs. When the new segments file is saved (committed), it will be written in the new file format (meaning no specific "upgrade" process is needed). But note that once a commit has occurred, pre-2.1 Lucene will not be able to read the index.
In version 2.3, the file format was changed to allow segments to share a single set of doc store (vectors & stored fields) files. This allows for faster indexing in certain cases. The change is fully backwards compatible (in the same way as the lock-less commits change in 2.1).
In version 2.4, Strings are now written as true UTF-8 byte sequence, not Java's modified UTF-8. See LUCENE-510 for details.
In version 2.9, an optional opaque
IDictionary<string, string>
CommitUserData may be passed to IndexWriter's commit methods (and later retrieved), which is recorded in thesegments_N
file. See LUCENE-1382 for details. Also, diagnostics were added to each segment written recording details about why it was written (due to flush, merge; which OS/JRE was used; etc.). See issue LUCENE-1654 for details.In version 3.0, compressed fields are no longer written to the index (they can still be read, but on merge the new segment will write them, uncompressed). See issue LUCENE-1960 for details.
In version 3.1, segments records the code version that created them. See LUCENE-2720 for details. Additionally segments track explicitly whether or not they have term vectors. See LUCENE-2811 for details.
In version 3.2, numeric fields are written as natively to stored fields file, previously they were stored in text format only.
In version 3.4, fields can omit position data while still indexing term frequencies.
In version 4.0, the format of the inverted index became extensible via the Codec api. Fast per-document storage (
DocValues
) was introduced. Normalization factors need no longer be a single byte, they can be any NumericDocValues. Terms need not be unicode strings, they can be any byte sequence. Term offsets can optionally be indexed into the postings lists. Payloads can be stored in the term vectors.
Limitations
Lucene uses a .NET int
to refer to document numbers, and the index file format uses an Int32
on-disk to store document numbers. This is a limitation of both the index file format and the current implementation. Eventually these should be replaced with either UInt64
values, or better yet, VInt values which have no limit.
Classes
Lucene40Codec
Implements the Lucene 4.0 index format, with configurable per-field postings formats.
If you want to reuse functionality of this codec in another codec, extend FilterCodec.
See Lucene.Net.Codecs.Lucene40 package documentation for file format details.
Lucene40DocValuesFormat
Lucene 4.0 DocValues format.
Files:
.dv.cfs
: compound container (CompoundFileDirectory).dv.cfe
: compound entries (CompoundFileDirectory)
<segment><fieldNumber>.dat
: data values<segment><fieldNumber>.idx
: index into the .dat for DEREF types
There are several many types of DocValues with different encodings.
From the perspective of filenames, all types store their values in .dat
entries within the compound file. In the case of dereferenced/sorted types, the .dat
actually contains only the unique values, and an additional .idx
file contains
pointers to these unique values.
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.VAR_INTS .dat --> Header, PackedType, MinValue, DefaultValue, PackedStream
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_8 .dat --> Header, ValueSize, Byte (WriteByte(Byte)) maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_16 .dat --> Header, ValueSize, Short (WriteInt16(Int16)) maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_32 .dat --> Header, ValueSize, Int32 (WriteInt32(Int32)) maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_64 .dat --> Header, ValueSize, Int64 (WriteInt64(Int64)) maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FLOAT_32 .dat --> Header, ValueSize, Float32maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FLOAT_64 .dat --> Header, ValueSize, Float64maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_STRAIGHT .dat --> Header, ValueSize, (Byte (WriteByte(Byte)) * ValueSize)maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_STRAIGHT .idx --> Header, TotalBytes, Addresses
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_STRAIGHT .dat --> Header, (Byte (WriteByte(Byte)) * variable ValueSize)maxdoc
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_DEREF .idx --> Header, NumValues, Addresses
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_DEREF .dat --> Header, ValueSize, (Byte (WriteByte(Byte)) * ValueSize)NumValues
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_DEREF .idx --> Header, TotalVarBytes, Addresses
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_DEREF .dat --> Header, (LengthPrefix + Byte (WriteByte(Byte)) * variable ValueSize)NumValues
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_SORTED .idx --> Header, NumValues, Ordinals
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_SORTED .dat --> Header, ValueSize, (Byte (WriteByte(Byte)) * ValueSize)NumValues
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_SORTED .idx --> Header, TotalVarBytes, Addresses, Ordinals
- Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_SORTED .dat --> Header, (Byte (WriteByte(Byte)) * variable ValueSize)NumValues
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- PackedType --> Byte (WriteByte(Byte))
- MaxAddress, MinValue, DefaultValue --> Int64 (WriteInt64(Int64))
- PackedStream, Addresses, Ordinals --> PackedInt32s
- ValueSize, NumValues --> Int32 (WriteInt32(Int32))
- Float32 --> 32-bit float encoded with J2N.BitConversion.SingleToRawInt32Bits(System.Single) then written as Int32 (WriteInt32(Int32))
- Float64 --> 64-bit float encoded with J2N.BitConversion.DoubleToRawInt64Bits(System.Double) then written as Int64 (WriteInt64(Int64))
- TotalBytes --> VLong (WriteVInt64(Int64))
- TotalVarBytes --> Int64 (WriteInt64(Int64))
- LengthPrefix --> Length of the data value as VInt (WriteVInt32(Int32)) (maximum of 2 bytes)
- PackedType is a 0 when compressed, 1 when the stream is written as 64-bit integers.
- Addresses stores pointers to the actual byte location (indexed by docid). In the VAR_STRAIGHT case, each entry can have a different length, so to determine the length, docid+1 is retrieved. A sentinel address is written at the end for the VAR_STRAIGHT case, so the Addresses stream contains maxdoc+1 indices. For the deduplicated VAR_DEREF case, each length is encoded as a prefix to the data itself as a VInt (WriteVInt32(Int32)) (maximum of 2 bytes).
- Ordinals stores the term ID in sorted order (indexed by docid). In the FIXED_SORTED case,
the address into the .dat can be computed from the ordinal as
Header+ValueSize+(ordinal*ValueSize)
because the byte length is fixed. In the VAR_SORTED case, there is double indirection (docid -> ordinal -> address), but an additional sentinel ordinal+address is always written (so there are NumValues+1 ordinals). To determine the length, ord+1's address is looked up as well. - Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_STRAIGHT in contrast to other straight
variants uses a
.idx
file to improve lookup perfromance. In contrast to Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_DEREF it doesn't apply deduplication of the document values.
Limitations:
- Binary doc values can be at most MAX_BINARY_FIELD_LENGTH in length.
Lucene40FieldInfosFormat
Lucene 4.0 Field Infos format.
Field names are stored in the field info file, with suffix .fnm.
FieldInfos (.fnm) --> Header,FieldsCount, <FieldName,FieldNumber, FieldBits,DocValuesBits,Attributes> FieldsCount
Data types:
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- FieldsCount --> VInt (WriteVInt32(Int32))
- FieldName --> String (WriteString(String))
- FieldBits, DocValuesBits --> Byte (WriteByte(Byte))
- FieldNumber --> VInt (WriteInt32(Int32))
- Attributes --> IDictionary<String,String> (WriteStringStringMap(IDictionary<String, String>))
- FieldsCount: the number of fields in this file.
- FieldName: name of the field as a UTF-8 String.
- FieldNumber: the field's number. Note that unlike previous versions of Lucene, the fields are not numbered implicitly by their order in the file, instead explicitly.
- FieldBits: a byte containing field options.
- The low-order bit is one for indexed fields, and zero for non-indexed fields.
- The second lowest-order bit is one for fields that have term vectors stored, and zero for fields without term vectors.
- If the third lowest order-bit is set (0x4), offsets are stored into the postings list in addition to positions.
- Fourth bit is unused.
- If the fifth lowest-order bit is set (0x10), norms are omitted for the indexed field.
- If the sixth lowest-order bit is set (0x20), payloads are stored for the indexed field.
- If the seventh lowest-order bit is set (0x40), term frequencies and positions omitted for the indexed field.
- If the eighth lowest-order bit is set (0x80), positions are omitted for the indexed field.
- DocValuesBits: a byte containing per-document value types. The type
recorded as two four-bit integers, with the high-order bits representing
norms
options, and the low-order bits representing DocValues options. Each four-bit integer can be decoded as such:- 0: no DocValues for this field.
- 1: variable-width signed integers. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.VAR_INTS)
- 2: 32-bit floating point values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FLOAT_32)
- 3: 64-bit floating point values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FLOAT_64)
- 4: fixed-length byte array values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_STRAIGHT)
- 5: fixed-length dereferenced byte array values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_DEREF)
- 6: variable-length byte array values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_STRAIGHT)
- 7: variable-length dereferenced byte array values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_DEREF)
- 8: 16-bit signed integers. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_16)
- 9: 32-bit signed integers. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_32)
- 10: 64-bit signed integers. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_64)
- 11: 8-bit signed integers. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.FIXED_INTS_8)
- 12: fixed-length sorted byte array values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_FIXED_SORTED)
- 13: variable-length sorted byte array values. (Lucene.Net.Codecs.Lucene40.LegacyDocValuesType.BYTES_VAR_SORTED)
- Attributes: a key-value map of codec-private attributes.
Note
This API is experimental and might change in incompatible ways in the next release.
Lucene40LiveDocsFormat
Lucene 4.0 Live Documents Format.
The .del file is optional, and only exists when a segment contains deletions.
Although per-segment, this file is maintained exterior to compound segment files.
Deletions (.del) --> Format,Header,ByteCount,BitCount, Bits | DGaps (depending on Format)
- Format,ByteSize,BitCount --> Uint32 (WriteInt32(Int32))
- Bits --> < Byte (WriteByte(Byte)) > ByteCount
- DGaps --> <DGap,NonOnesByte> NonzeroBytesCount
- DGap --> VInt (WriteVInt32(Int32))
- NonOnesByte --> Byte(WriteByte(Byte))
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
Format is 1: indicates cleared DGaps.
ByteCount indicates the number of bytes in Bits. It is typically (SegSize/8)+1.
BitCount indicates the number of bits that are currently set in Bits.
Bits contains one bit for each document indexed. When the bit corresponding to a document number is cleared, that document is marked as deleted. Bit ordering is from least to most significant. Thus, if Bits contains two bytes, 0x00 and 0x02, then document 9 is marked as alive (not deleted).
DGaps represents sparse bit-vectors more efficiently than Bits. It is made of DGaps on indexes of nonOnes bytes in Bits, and the nonOnes bytes themselves. The number of nonOnes bytes in Bits (NonOnesBytesCount) is not stored.
For example, if there are 8000 bits and only bits 10,12,32 are cleared, DGaps would be used:
(VInt) 1 , (byte) 20 , (VInt) 3 , (Byte) 1
Lucene40NormsFormat
Lucene 4.0 Norms Format.
Files:
.nrm.cfs
: compound container (CompoundFileDirectory).nrm.cfe
: compound entries (CompoundFileDirectory)
Note
This API is experimental and might change in incompatible ways in the next release.
Lucene40PostingsBaseFormat
Provides a PostingsReaderBase and PostingsWriterBase.
Lucene40PostingsFormat
Lucene 4.0 Postings format.
Files:
- .tim: Term Dictionary
- .tip: Term Index
- .frq: Frequencies
- .prx: Positions
Term Dictionary
The .tim file contains the list of terms in each field along with per-term statistics (such as docfreq) and pointers to the frequencies, positions and skip data in the .frq and .prx files. See BlockTreeTermsWriter for more details on the format.
NOTE: The term dictionary can plug into different postings implementations: the postings writer/reader are actually responsible for encoding and decoding the Postings Metadata and Term Metadata sections described here:
- Postings Metadata --> Header, SkipInterval, MaxSkipLevels, SkipMinimum
- Term Metadata --> FreqDelta, SkipDelta?, ProxDelta?
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- SkipInterval,MaxSkipLevels,SkipMinimum --> Uint32 (WriteInt32(Int32))
- SkipDelta,FreqDelta,ProxDelta --> VLong (WriteVInt64(Int64))
Notes:
- Header is a CodecHeader (WriteHeader(DataOutput, String, Int32)) storing the version information for the postings.
- SkipInterval is the fraction of TermDocs stored in skip tables. It is used to accelerate Advance(Int32). Larger values result in smaller indexes, greater acceleration, but fewer accelerable cases, while smaller values result in bigger indexes, less acceleration (in case of a small value for MaxSkipLevels) and more accelerable cases.
- MaxSkipLevels is the max. number of skip levels stored for each term in the .frq file. A low value results in smaller indexes but less acceleration, a larger value results in slightly larger indexes but greater acceleration. See format of .frq file for more information about skip levels.
- SkipMinimum is the minimum document frequency a term must have in order to write any skip data at all.
- FreqDelta determines the position of this term's TermFreqs within the .frq file. In particular, it is the difference between the position of this term's data in that file and the position of the previous term's data (or zero, for the first term in the block).
- ProxDelta determines the position of this term's TermPositions within the .prx file. In particular, it is the difference between the position of this term's data in that file and the position of the previous term's data (or zero, for the first term in the block. For fields that omit position data, this will be 0 since prox information is not stored.
- SkipDelta determines the position of this term's SkipData within the .frq file. In particular, it is the number of bytes after TermFreqs that the SkipData starts. In other words, it is the length of the TermFreq data. SkipDelta is only stored if DocFreq is not smaller than SkipMinimum.
Term Index
The .tip file contains an index into the term dictionary, so that it can be accessed randomly. See BlockTreeTermsWriter for more details on the format.
Frequencies
The .frq file contains the lists of documents which contain each term, along with the frequency of the term in that document (except when frequencies are omitted: DOCS_ONLY).
- FreqFile (.frq) --> Header, <TermFreqs, SkipData?> TermCount
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- TermFreqs --> <TermFreq> DocFreq
- TermFreq --> DocDelta[, Freq?]
- SkipData --> <<SkipLevelLength, SkipLevel> NumSkipLevels-1, SkipLevel> <SkipDatum>
- SkipLevel --> <SkipDatum> DocFreq/(SkipInterval^(Level + 1))
- SkipDatum --> DocSkip,PayloadLength?,OffsetLength?,FreqSkip,ProxSkip,SkipChildLevelPointer?
- DocDelta,Freq,DocSkip,PayloadLength,OffsetLength,FreqSkip,ProxSkip --> VInt (WriteVInt32(Int32))
- SkipChildLevelPointer --> VLong (WriteVInt64(Int64))
TermFreqs are ordered by term (the term is implicit, from the term dictionary).
TermFreq entries are ordered by increasing document number.
DocDelta: if frequencies are indexed, this determines both the document number and the frequency. In particular, DocDelta/2 is the difference between this document number and the previous document number (or zero when this is the first document in a TermFreqs). When DocDelta is odd, the frequency is one. When DocDelta is even, the frequency is read as another VInt. If frequencies are omitted, DocDelta contains the gap (not multiplied by 2) between document numbers and no frequency information is stored.
For example, the TermFreqs for a term which occurs once in document seven and three times in document eleven, with frequencies indexed, would be the following sequence of VInts:
15, 8, 3
If frequencies were omitted (DOCS_ONLY) it would be this sequence of VInts instead:
7,4
DocSkip records the document number before every SkipInterval th document in TermFreqs. If payloads and offsets are disabled for the term's field, then DocSkip represents the difference from the previous value in the sequence. If payloads and/or offsets are enabled for the term's field, then DocSkip/2 represents the difference from the previous value in the sequence. In this case when DocSkip is odd, then PayloadLength and/or OffsetLength are stored indicating the length of the last payload/offset before the SkipIntervalth document in TermPositions.
PayloadLength indicates the length of the last payload.
OffsetLength indicates the length of the last offset (endOffset-startOffset).
FreqSkip and ProxSkip record the position of every SkipInterval th entry in FreqFile and ProxFile, respectively. File positions are relative to the start of TermFreqs and Positions, to the previous SkipDatum in the sequence.
For example, if DocFreq=35 and SkipInterval=16, then there are two SkipData entries, containing the 15 th and 31 st document numbers in TermFreqs. The first FreqSkip names the number of bytes after the beginning of TermFreqs that the 16 th SkipDatum starts, and the second the number of bytes after that that the 32 nd starts. The first ProxSkip names the number of bytes after the beginning of Positions that the 16 th SkipDatum starts, and the second the number of bytes after that that the 32 nd starts.
Each term can have multiple skip levels. The amount of skip levels for a term is NumSkipLevels = Min(MaxSkipLevels, floor(log(DocFreq/log(SkipInterval)))). The number of SkipData entries for a skip level is DocFreq/(SkipInterval^(Level + 1)), whereas the lowest skip level is Level=0.
Example: SkipInterval = 4, MaxSkipLevels = 2, DocFreq = 35. Then skip level 0 has 8 SkipData entries, containing the 3rd, 7th, 11th, 15th, 19th, 23rd, 27th, and 31st document numbers in TermFreqs. Skip level 1 has 2 SkipData entries, containing the 15th and 31st document numbers in TermFreqs.
The SkipData entries on all upper levels > 0 contain a SkipChildLevelPointer referencing the corresponding SkipData entry in level-1. In the example has entry 15 on level 1 a pointer to entry 15 on level 0 and entry 31 on level 1 a pointer to entry 31 on level 0.
Positions
The .prx file contains the lists of positions that each term occurs at within documents. Note that fields omitting positional data do not store anything into this file, and if all fields in the index omit positional data then the .prx file will not exist.
- ProxFile (.prx) --> Header, <TermPositions> TermCount
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- TermPositions --> <Positions> DocFreq
- Positions --> <PositionDelta,PayloadLength?,OffsetDelta?,OffsetLength?,PayloadData?> Freq
- PositionDelta,OffsetDelta,OffsetLength,PayloadLength --> VInt (WriteVInt32(Int32))
- PayloadData --> byte (WriteByte(Byte)) PayloadLength
TermPositions are ordered by term (the term is implicit, from the term dictionary).
Positions entries are ordered by increasing document number (the document number is implicit from the .frq file).
PositionDelta is, if payloads are disabled for the term's field, the difference between the position of the current occurrence in the document and the previous occurrence (or zero, if this is the first occurrence in this document). If payloads are enabled for the term's field, then PositionDelta/2 is the difference between the current and the previous position. If payloads are enabled and PositionDelta is odd, then PayloadLength is stored, indicating the length of the payload at the current term position.
For example, the TermPositions for a term which occurs as the fourth term in one document, and as the fifth and ninth term in a subsequent document, would be the following sequence of VInts (payloads disabled):
4, 5, 4
PayloadData is metadata associated with the current term position. If PayloadLength is stored at the current position, then it indicates the length of this payload. If PayloadLength is not stored, then this payload has the same length as the payload at the previous position.
OffsetDelta/2 is the difference between this position's startOffset from the previous occurrence (or zero, if this is the first occurrence in this document). If OffsetDelta is odd, then the length (endOffset-startOffset) differs from the previous occurrence and an OffsetLength follows. Offset data is only written for DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS.
Lucene40PostingsReader
Concrete class that reads the 4.0 frq/prox postings format.
Lucene40SegmentInfoFormat
Lucene 4.0 Segment info format.
Files:
- .si: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Attributes, Files
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- SegSize --> Int32 (WriteInt32(Int32))
- SegVersion --> String (WriteString(String))
- Files --> ISet<String> (WriteStringSet(ISet<String>))
- Diagnostics, Attributes --> IDictionary<String,String> (WriteStringStringMap(IDictionary<String, String>))
- IsCompoundFile --> Int8 (WriteByte(Byte))
- SegVersion is the code version that created the segment.
- SegSize is the number of documents contained in the segment index.
- IsCompoundFile records whether the segment is written as a compound file or not. If this is -1, the segment is not a compound file. If it is 1, the segment is a compound file.
- Checksum contains the CRC32 checksum of all bytes in the segments_N file up until the checksum. This is used to verify integrity of the file on opening the index.
- The Diagnostics Map is privately written by IndexWriter, as a debugging aid, for each segment it creates. It includes metadata like the current Lucene version, OS, .NET/Java version, why the segment was created (merge, flush, addIndexes), etc.
- Attributes: a key-value map of codec-private attributes.
- Files is a list of files referred to by this segment.
Note
This API is experimental and might change in incompatible ways in the next release.
Lucene40SegmentInfoReader
Lucene 4.0 implementation of SegmentInfoReader.
Note
This API is experimental and might change in incompatible ways in the next release.
Lucene40SegmentInfoWriter
Lucene 4.0 implementation of SegmentInfoWriter.
Note
This API is experimental and might change in incompatible ways in the next release.
Lucene40SkipListReader
Implements the skip list reader for the 4.0 posting list format that stores positions and payloads.
Lucene40StoredFieldsFormat
Lucene 4.0 Stored Fields Format.
Stored fields are represented by two files:
-
The field index, or
.fdx
file.This is used to find the location within the field data file of the fields of a particular document. Because it contains fixed-length data, this file may be easily randomly accessed. The position of document n 's field data is the Uint64 (WriteInt64(Int64)) at n*8 in this file.
This contains, for each document, a pointer to its field data, as follows:
- FieldIndex (.fdx) --> <Header>, <FieldValuesPosition> SegSize
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- FieldValuesPosition --> Uint64 (WriteInt64(Int64))
-
This contains the stored fields of each document, as follows:
- FieldData (.fdt) --> <Header>, <DocFieldData> SegSize
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- DocFieldData --> FieldCount, <FieldNum, Bits, Value> FieldCount
- FieldCount --> VInt (WriteVInt32(Int32))
- FieldNum --> VInt (WriteVInt32(Int32))
- Bits --> Byte (WriteByte(Byte))
- low order bit reserved.
- second bit is one for fields containing binary data
- third bit reserved.
- 4th to 6th bit (mask: 0x7<<3) define the type of a numeric field:
- all bits in mask are cleared if no numeric field at all
- 1<<3: Value is Int
- 2<<3: Value is Long
- 3<<3: Value is Int as Float (as of J2N.BitConversion.Int32BitsToSingle(System.Int32)
- 4<<3: Value is Long as Double (as of J2N.BitConversion.Int64BitsToDouble(System.Int64)
- Value --> String | BinaryValue | Int | Long (depending on Bits)
- BinaryValue --> ValueSize, < Byte (WriteByte(Byte)) >^ValueSize
- ValueSize --> VInt (WriteVInt32(Int32))
Note
This API is experimental and might change in incompatible ways in the next release.
Lucene40StoredFieldsReader
Class responsible for access to stored document fields.
It uses <segment>.fdt and <segment>.fdx; files.
Note
This API is for internal purposes only and might change in incompatible ways in the next release.
Lucene40StoredFieldsWriter
Class responsible for writing stored document fields.
It uses <segment>.fdt and <segment>.fdx; files.
Note
This API is experimental and might change in incompatible ways in the next release.
Lucene40TermVectorsFormat
Lucene 4.0 Term Vectors format.
Term Vector support is an optional on a field by field basis. It consists of 3 files.
-
The Document Index or .tvx file.
For each document, this stores the offset into the document data (.tvd) and field data (.tvf) files.
DocumentIndex (.tvx) --> Header,<DocumentPosition,FieldPosition> NumDocs
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- DocumentPosition --> UInt64 (WriteInt64(Int64)) (offset in the .tvd file)
- FieldPosition --> UInt64 (WriteInt64(Int64)) (offset in the .tvf file)
-
The Document or .tvd file.
This contains, for each document, the number of fields, a list of the fields with term vector info and finally a list of pointers to the field information in the .tvf (Term Vector Fields) file.
The .tvd file is used to map out the fields that have term vectors stored and where the field information is in the .tvf file.
Document (.tvd) --> Header,<NumFields, FieldNums, FieldPositions> NumDocs
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- NumFields --> VInt (WriteVInt32(Int32))
- FieldNums --> <FieldNumDelta> NumFields
- FieldNumDelta --> VInt (WriteVInt32(Int32))
- FieldPositions --> <FieldPositionDelta> NumFields-1
- FieldPositionDelta --> VLong (WriteVInt64(Int64))
-
The Field or .tvf file.
This file contains, for each field that has a term vector stored, a list of the terms, their frequencies and, optionally, position, offset, and payload information.
Field (.tvf) --> Header,<NumTerms, Flags, TermFreqs> NumFields
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- NumTerms --> VInt (WriteVInt32(Int32))
- Flags --> Byte (WriteByte(Byte))
- TermFreqs --> <TermText, TermFreq, Positions?, PayloadData?, Offsets?> NumTerms
- TermText --> <PrefixLength, Suffix>
- PrefixLength --> VInt (WriteVInt32(Int32))
- Suffix --> String (WriteString(String))
- TermFreq --> VInt (WriteVInt32(Int32))
- Positions --> <PositionDelta PayloadLength?>TermFreq
- PositionDelta --> VInt (WriteVInt32(Int32))
- PayloadLength --> VInt (WriteVInt32(Int32))
- PayloadData --> Byte (WriteByte(Byte)) NumPayloadBytes
- Offsets --> <VInt (WriteVInt32(Int32)), VInt (WriteVInt32(Int32)) >TermFreq
Notes:
- Flags byte stores whether this term vector has position, offset, payload. information stored.
- Term byte prefixes are shared. The PrefixLength is the number of initial bytes from the previous term which must be pre-pended to a term's suffix in order to form the term's bytes. Thus, if the previous term's text was "bone" and the term is "boy", the PrefixLength is two and the suffix is "y".
- PositionDelta is, if payloads are disabled for the term's field, the difference between the position of the current occurrence in the document and the previous occurrence (or zero, if this is the first occurrence in this document). If payloads are enabled for the term's field, then PositionDelta/2 is the difference between the current and the previous position. If payloads are enabled and PositionDelta is odd, then PayloadLength is stored, indicating the length of the payload at the current term position.
- PayloadData is metadata associated with a term position. If PayloadLength is stored at the current position, then it indicates the length of this payload. If PayloadLength is not stored, then this payload has the same length as the payload at the previous position. PayloadData encodes the concatenated bytes for all of a terms occurrences.
- Offsets are stored as delta encoded VInts. The first VInt is the startOffset, the second is the endOffset.
Lucene40TermVectorsReader
Lucene 4.0 Term Vectors reader.
It reads .tvd, .tvf, and .tvx files.
Lucene40TermVectorsWriter
Lucene 4.0 Term Vectors writer.
It writes .tvd, .tvf, and .tvx files.