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.
Inheritance
Namespace: Lucene.Net.Index
Assembly: Lucene.Net.dll
Syntax
public sealed class SegmentInfos : IEnumerable<SegmentCommitInfo>
Constructors
| Improve this Doc View SourceSegmentInfos()
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.
Declaration
public SegmentInfos()
Fields
| Improve this Doc View SourceFORMAT_SEGMENTS_GEN_CURRENT
Current format of segments.gen
Declaration
public static readonly int FORMAT_SEGMENTS_GEN_CURRENT
Field Value
Type | Description |
---|---|
System.Int32 |
VERSION_40
The file format version for the segments_N codec header, up to 4.5.
Declaration
public static readonly int VERSION_40
Field Value
Type | Description |
---|---|
System.Int32 |
VERSION_46
The file format version for the segments_N codec header, since 4.6+.
Declaration
public static readonly int VERSION_46
Field Value
Type | Description |
---|---|
System.Int32 |
VERSION_48
The file format version for the segments_N codec header, since 4.8+
Declaration
public static readonly int VERSION_48
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
| Improve this Doc View SourceCount
Returns number of SegmentCommitInfos.
NOTE: This was size() in Lucene.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
Counter
Used to name new segments.
Declaration
public int Counter { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
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.
Declaration
public static int DefaultGenLookaheadCount { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Generation
Returns current generation.
Declaration
public long Generation { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
InfoStream
If non-null, information about retries when loading the segments file will be printed to this.
Declaration
public static TextWriter InfoStream { get; set; }
Property Value
Type | Description |
---|---|
TextWriter |
LastGeneration
Returns last succesfully read or written generation.
Declaration
public long LastGeneration { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
Segments
Declaration
public IList<SegmentCommitInfo> Segments { get; }
Property Value
Type | Description |
---|---|
IList<SegmentCommitInfo> |
TotalDocCount
Returns sum of all segment's docCounts. Note that this does not include deletions
Declaration
public int TotalDocCount { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
UserData
Gets Lucene.Net.Index.SegmentInfos.userData saved with this commit.
Declaration
public IDictionary<string, string> UserData { get; }
Property Value
Type | Description |
---|---|
IDictionary<System.String, System.String> |
See Also
| Improve this Doc View SourceVersion
Version number when this SegmentInfos was generated.
Declaration
public long Version { get; }
Property Value
Type | Description |
---|---|
System.Int64 |
Methods
| Improve this Doc View SourceAdd(SegmentCommitInfo)
Appends the provided SegmentCommitInfo.
Declaration
public void Add(SegmentCommitInfo si)
Parameters
Type | Name | Description |
---|---|---|
SegmentCommitInfo | si |
AddAll(IEnumerable<SegmentCommitInfo>)
Appends the provided SegmentCommitInfos.
Declaration
public void AddAll(IEnumerable<SegmentCommitInfo> sis)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<SegmentCommitInfo> | sis |
AsList()
Returns all contained segments as an unmodifiable IList{SegmentCommitInfo} view.
Declaration
public IList<SegmentCommitInfo> AsList()
Returns
Type | Description |
---|---|
IList<SegmentCommitInfo> |
Changed()
Call this before committing if changes have been made to the segments.
Declaration
public void Changed()
Clear()
Clear all SegmentCommitInfos.
Declaration
public void Clear()
Clone()
Returns a copy of this instance, also copying each SegmentInfo.
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object |
GenerationFromSegmentsFileName(String)
Parse the generation off the segments file name and return it.
Declaration
public static long GenerationFromSegmentsFileName(string fileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName |
Returns
Type | Description |
---|---|
System.Int64 |
GetEnumerator()
Returns an unmodifiable IEnumerator{SegmentCommitInfo} of contained segments in order.
Declaration
public IEnumerator<SegmentCommitInfo> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<SegmentCommitInfo> |
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.
Declaration
public ICollection<string> GetFiles(Directory dir, bool includeSegmentsFile)
Parameters
Type | Name | Description |
---|---|---|
Directory | dir | |
System.Boolean | includeSegmentsFile |
Returns
Type | Description |
---|---|
ICollection<System.String> |
GetLastCommitGeneration(Directory)
Get the generation of the most recent commit to the index in this directory (N in the segments_N file).
Declaration
public static long GetLastCommitGeneration(Directory directory)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory | directory to search for the latest segments_N file |
Returns
Type | Description |
---|---|
System.Int64 |
GetLastCommitGeneration(String[])
Get the generation of the most recent commit to the list of index files (N in the segments_N file).
Declaration
public static long GetLastCommitGeneration(string[] files)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | files | array of file names to check |
Returns
Type | Description |
---|---|
System.Int64 |
GetLastCommitSegmentsFileName(Directory)
Get the filename of the segments_N file for the most recent commit to the index in this Directory.
Declaration
public static string GetLastCommitSegmentsFileName(Directory directory)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory | directory to search for the latest segments_N file |
Returns
Type | Description |
---|---|
System.String |
GetLastCommitSegmentsFileName(String[])
Get the filename of the segments_N file for the most recent commit in the list of index files.
Declaration
public static string GetLastCommitSegmentsFileName(string[] files)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | files | array of file names to check |
Returns
Type | Description |
---|---|
System.String |
GetNextSegmentFileName()
Get the next segments_N filename that will be written.
Declaration
public string GetNextSegmentFileName()
Returns
Type | Description |
---|---|
System.String |
GetSegmentsFileName()
Get the segments_N filename in use by this segment infos.
Declaration
public string GetSegmentsFileName()
Returns
Type | Description |
---|---|
System.String |
Info(Int32)
Returns SegmentCommitInfo at the provided index.
Declaration
public SegmentCommitInfo Info(int i)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i |
Returns
Type | Description |
---|---|
SegmentCommitInfo |
Read(Directory)
Find the latest commit (segments_N file
) and
load all SegmentCommitInfos.
Declaration
public void Read(Directory directory)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory |
Read(Directory, String)
Read a particular segmentFileName
. Note that this may
throw an
Declaration
public void Read(Directory directory, string segmentFileName)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory | directory containing the segments file |
System.String | segmentFileName | segment file to load |
Exceptions
Type | Condition |
---|---|
CorruptIndexException | if the index is corrupt |
Remove(SegmentCommitInfo)
Remove the provided SegmentCommitInfo.
WARNING: O(N) cost
Declaration
public void Remove(SegmentCommitInfo si)
Parameters
Type | Name | Description |
---|---|---|
SegmentCommitInfo | si |
ToString(Directory)
Returns readable description of this segment.
Declaration
public string ToString(Directory directory)
Parameters
Type | Name | Description |
---|---|---|
Directory | directory |
Returns
Type | Description |
---|---|
System.String |
Write3xInfo(Directory, SegmentInfo, IOContext)
Declaration
public static string Write3xInfo(Directory dir, SegmentInfo si, IOContext context)
Parameters
Type | Name | Description |
---|---|---|
Directory | dir | |
SegmentInfo | si | |
IOContext | context |
Returns
Type | Description |
---|---|
System.String |
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!
Declaration
public static void WriteSegmentsGen(Directory dir, long generation)
Parameters
Type | Name | Description |
---|---|---|
Directory | dir | |
System.Int64 | generation |