Class SegmentInfos
A collection of segmentInfo objects with methods for operating on those segments in relation to the file system.
The active segments in the index are stored in the segment info file,
segments_N
. There may be one or more segments_N
files in the
index; however, the one with the largest generation is the active one (when
older segments_N files are present it's because they temporarily cannot be
deleted, or, a writer is in the process of committing, or a custom
IndexDeletionPolicy
is in use). This file lists each segment by name and has details about the
codec and generation of deletes.
There is also a file segments.gen
. this file contains
the current generation (the _N
in segments_N
) of the index.
This is used only as a fallback in case the current generation cannot be
accurately determined by directory listing alone (as is the case for some NFS
clients with time-based directory cache expiration). This file simply contains
an WriteInt32(Int32) version header
(FORMAT_SEGMENTS_GEN_CURRENT), followed by the
generation recorded as WriteInt64(Int64), written twice.
Files:
segments.gen
: GenHeader, Generation, Generation, Footersegments_N
: Header, Version, NameCounter, SegCount, <SegName, SegCodec, DelGen, DeletionCount, FieldInfosGen, UpdatesFiles>SegCount, CommitUserData, Footer
- Header --> WriteHeader(DataOutput, String, Int32)
- GenHeader, NameCounter, SegCount, DeletionCount --> WriteInt32(Int32)
- Generation, Version, DelGen, Checksum, FieldInfosGen --> WriteInt64(Int64)
- SegName, SegCodec --> WriteString(String)
- CommitUserData --> WriteStringStringMap(IDictionary<String, String>)
- UpdatesFiles --> WriteStringSet(ISet<String>)
- Footer --> WriteFooter(IndexOutput)
- Version counts how often the index has been changed by adding or deleting documents.
- NameCounter is used to generate names for new segment files.
- SegName is the name of the segment, and is used as the file name prefix for all of the files that compose the segment's index.
- DelGen is the generation count of the deletes file. If this is -1, there are no deletes. Anything above zero means there are deletes stored by LiveDocsFormat.
- DeletionCount records the number of deleted documents in this segment.
- SegCodec is the Name of the Codec that encoded this segment.
- CommitUserData stores an optional user-supplied opaque
that was passed to SetCommitData(IDictionary<String, String>). - FieldInfosGen is the generation count of the fieldInfos file. If this is -1, there are no updates to the fieldInfos in that segment. Anything above zero means there are updates to fieldInfos stored by FieldInfosFormat.
- UpdatesFiles stores the list of files that were updated in that segment.
@lucene.experimental
Inheritance
Assembly: DistributedLucene.Net.dll
Syntax
public sealed class SegmentInfos : IEnumerable<SegmentCommitInfo>
Constructors
Name | Description |
---|---|
SegmentInfos() | Sole constructor. Typically you call this and then use Read(Directory) or Read(Directory, String) to populate each SegmentCommitInfo. Alternatively, you can add/remove your own SegmentCommitInfos. |
Fields
Name | Description |
---|---|
FORMAT_SEGMENTS_GEN_CURRENT | Current format of segments.gen |
VERSION_40 | The file format version for the segments_N codec header, up to 4.5. |
VERSION_46 | The file format version for the segments_N codec header, since 4.6+. |
VERSION_48 | The file format version for the segments_N codec header, since 4.8+ |
Properties
Name | Description |
---|---|
Count | Returns number of SegmentCommitInfos. NOTE: This was size() in Lucene. |
Counter | Used to name new segments. |
DefaultGenLookaheadCount | Gets or Sets the Lucene.Net.Index.SegmentInfos.defaultGenLookaheadCount. Advanced: set how many times to try incrementing the gen when loading the segments file. this only runs if the primary (listing directory) and secondary (opening segments.gen file) methods fail to find the segments file. @lucene.experimental |
Generation | Returns current generation. |
InfoStream | If non-null, information about retries when loading the segments file will be printed to this. |
LastGeneration | Returns last succesfully read or written generation. |
Segments | |
TotalDocCount | Returns sum of all segment's docCounts. Note that this does not include deletions |
UserData | Gets Lucene.Net.Index.SegmentInfos.userData saved with this commit. |
Version | Version number when this SegmentInfos was generated. |
Methods
Name | Description |
---|---|
Add(SegmentCommitInfo) | Appends the provided SegmentCommitInfo. |
AddAll(IEnumerable<SegmentCommitInfo>) | Appends the provided SegmentCommitInfos. |
AsList() | Returns all contained segments as an unmodifiable IList{SegmentCommitInfo} view. |
Changed() | Call this before committing if changes have been made to the segments. |
Clear() | Clear all SegmentCommitInfos. |
Clone() | Returns a copy of this instance, also copying each SegmentInfo. |
GenerationFromSegmentsFileName(String) | Parse the generation off the segments file name and return it. |
GetEnumerator() | Returns an unmodifiable IEnumerator{SegmentCommitInfo} of contained segments in order. |
GetFiles(Directory, Boolean) | Returns all file names referenced by SegmentInfo instances matching the provided Directory (ie files associated with any "external" segments are skipped). The returned collection is recomputed on each invocation. |
GetLastCommitGeneration(Directory) | Get the generation of the most recent commit to the index in this directory (N in the segments_N file). |
GetLastCommitGeneration(String[]) | Get the generation of the most recent commit to the list of index files (N in the segments_N file). |
GetLastCommitSegmentsFileName(Directory) | Get the filename of the segments_N file for the most recent commit to the index in this Directory. |
GetLastCommitSegmentsFileName(String[]) | Get the filename of the segments_N file for the most recent commit in the list of index files. |
GetNextSegmentFileName() | Get the next segments_N filename that will be written. |
GetSegmentsFileName() | Get the segments_N filename in use by this segment infos. |
Info(Int32) | Returns SegmentCommitInfo at the provided index. |
Read(Directory) | Find the latest commit ( |
Read(Directory, String) | Read a particular |
Remove(SegmentCommitInfo) | Remove the provided SegmentCommitInfo. WARNING: O(N) cost |
ToString(Directory) | Returns readable description of this segment. |
Write3xInfo(Directory, SegmentInfo, IOContext) | |
WriteSegmentsGen(Directory, Int64) | A utility for writing the SEGMENTS_GEN file to a Directory. NOTE: this is an internal utility which is kept public so that it's accessible by code from other packages. You should avoid calling this method unless you're absolutely sure what you're doing! @lucene.internal |