Namespace Lucene.Net.Codecs.Lucene46
Lucene 4.6 file format.
Apache Lucene - Index File Formats
Introduction
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. 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 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
File Naming
Summary of File Extensions
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 | .doc | Contains the list of docs which contain each term along with frequency |
Positions | .pos | Stores position information about where a term occurs in the index |
Payloads | .pay | Stores additional per-position metadata information such as character offsets and user payloads |
Norms | .nvd, .nvm | Encodes length and boost factors for docs and fields |
Per-Document Values | .dvd, .dvm | 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 Map<String,String> CommitUserData may be passed to IndexWriter's commit methods (and later retrieved), which is recorded in the segments_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 ({@code 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.
In version 4.1, the format of the postings list changed to use either of FOR compression or variable-byte encoding, depending upon the frequency of the term. Terms appearing only once were changed to inline directly into the term dictionary. Stored fields are compressed by default.
In version 4.2, term vectors are compressed by default. DocValues has a new multi-valued type (SortedSet), that can be used for faceting/grouping/joining on multi-valued fields.
In version 4.5, DocValues were extended to explicitly represent missing values.
In version 4.6, FieldInfos were extended to support per-field DocValues generation, to allow updating NumericDocValues fields.
In version 4.8, checksum footers were added to the end of each index file for improved data integrity. Specifically, the last 8 bytes of every index file contain the zlib-crc32 checksum of the file.
Limitations
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
Lucene46Codec
Implements the Lucene 4.6 index format, with configurable per-field postings and docvalues formats.
If you want to reuse functionality of this codec in another codec, extend FilterCodec.
See Lucene.Net.Codecs.Lucene46 package documentation for file format details.
Lucene46FieldInfosFormat
Lucene 4.6 Field Infos format.
Field names are stored in the field info file, with suffix .fnm
.
FieldInfos (.fnm) --> Header,FieldsCount, <FieldName,FieldNumber, FieldBits,DocValuesBits,DocValuesGen,Attributes> FieldsCount,Footer
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>))
- DocValuesGen --> Int64 (WriteInt64(Int64))
- Footer --> CodecFooter (WriteFooter(IndexOutput))
- 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 System.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 System.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: NumericDocValues. (NUMERIC)
- 2: BinaryDocValues. (BINARY)
- 3: SortedDocValues. (SORTED)
- DocValuesGen is the generation count of the field's DocValues. If this is -1, there are no DocValues updates to that field. Anything above zero means there are updates stored by DocValuesFormat.
- Attributes: a key-value map of codec-private attributes.
Lucene46SegmentInfoFormat
Lucene 4.6 Segment info format.
Files:
.si
: Header, SegVersion, SegSize, IsCompoundFile, Diagnostics, Files, Footer
- Header --> CodecHeader (WriteHeader(DataOutput, String, Int32))
- SegSize --> Int32 (WriteInt32(Int32))
- SegVersion --> String (WriteString(String))
- Files --> ISet<String> (WriteStringSet(ISet<String>))
- Diagnostics --> IDictionary<String,String> (WriteStringStringMap(IDictionary<String, String>))
- IsCompoundFile --> Int8 (WriteByte(Byte))
- Footer --> CodecFooter (WriteFooter(IndexOutput))
- 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.
- 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.
- Files is a list of files referred to by this segment.
Lucene46SegmentInfoReader
Lucene 4.6 implementation of SegmentInfoReader.
Lucene46SegmentInfoWriter
Lucene 4.0 implementation of SegmentInfoWriter.