SegmentInfos

class SegmentInfos(indexCreatedVersionMajor: Int) : Cloneable<SegmentInfos> , Iterable<SegmentCommitInfo>

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 custom IndexDeletionPolicy is in use). This file lists each segment by name and has details about the codec and generation of deletes.

Files:

  • segments_N: Header, LuceneVersion, Version, NameCounter, SegCount, MinSegmentLuceneVersion, SegCount, CommitUserData, Footer

Data types:

  • Header -->IndexHeader

  • LuceneVersion --> Which Lucene code Version was used for this commit, written as three DataOutput.writeVInt: major, minor, bugfix

  • MinSegmentLuceneVersion --> Lucene code Version of the oldest segment, written as three DataOutput.writeVInt: major, minor, bugfix; this is only written only if there's at least one segment

  • NameCounter, SegCount, DeletionCount -->DataOutput.writeInt

  • Generation, Version, DelGen, Checksum, FieldInfosGen, DocValuesGen -->DataOutput.writeLong

  • SegID -->DataOutput.writeByte

  • SegName, SegCodec -->DataOutput.writeString

  • CommitUserData -->DataOutput.writeMapOfStrings

  • UpdatesFiles --> Map

  • Footer -->CodecFooter

Field Descriptions:

  • 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 Codec.getName of the Codec that encoded this segment.

  • SegID is the identifier of the Codec that encoded this segment.

  • CommitUserData stores an optional user-supplied opaque Map that was passed to IndexWriter.setLiveCommitData.

  • 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 .

  • DocValuesGen is the generation count of the updatable DocValues. If this is -1, there are no updates to DocValues in that segment. Anything above zero means there are updates to DocValues stored by DocValuesFormat.

  • UpdatesFiles stores the set of files that were updated in that segment per field.

Constructors

Link copied to clipboard
constructor(indexCreatedVersionMajor: Int)

Types

Link copied to clipboard
object Companion
Link copied to clipboard
abstract class FindSegmentsFile<T>

Utility class for executing code that needs to do something with the current segments file. This is necessary with lock-less commits because from the time you locate the current segments file name, until you actually open it, read its contents, or check modified time, etc., it could have been deleted due to a writer commit finishing.

Properties

Link copied to clipboard
Link copied to clipboard

Used to name new segments.

Link copied to clipboard

Returns current generation.

Link copied to clipboard

The Lucene version major that was used to create the index.

Link copied to clipboard

Returns last succesfully read or written generation.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Opaque Map that user can specify during IndexWriter.commit Return userData saved with this commit.

Link copied to clipboard

Functions

Link copied to clipboard

Appends the provided SegmentCommitInfo.

Link copied to clipboard

Appends the provided SegmentCommitInfos.

Link copied to clipboard

applies all changes caused by committing a merge to this SegmentInfos

Link copied to clipboard

Returns all contained segments as an unmodifiable List view.

Link copied to clipboard
fun changed()

Call this before committing if changes have been made to the segments.

Link copied to clipboard
fun clear()

Clear all SegmentCommitInfos.

Link copied to clipboard
open override fun clone(): SegmentInfos

Returns a copy of this instance, also copying each SegmentInfo.

Link copied to clipboard
fun commit(dir: Directory)

Writes and syncs to the Directory dir, taking care to remove the segments file on exception

Link copied to clipboard

Return true if the provided SegmentCommitInfo is contained.

Link copied to clipboard
fun files(includeSegmentsFile: Boolean): MutableCollection<String>

Returns all file names referenced by SegmentInfo. The returned collection is recomputed on each invocation.

Link copied to clipboard

Returns the committed segments_N filename.

Link copied to clipboard

Since Lucene 5.0, every commit (segments_N) writes a unique id. This will return that id

Link copied to clipboard

Returns the version of the oldest segment, or null if there are no segments.

Link copied to clipboard

Returns index of the provided SegmentCommitInfo.

Link copied to clipboard

Returns SegmentCommitInfo at the provided index.

Link copied to clipboard
open operator override fun iterator(): MutableIterator<SegmentCommitInfo>

Returns an unmodifiable Iterator of contained segments in order.

Link copied to clipboard

Call this to start a commit. This writes the new segments file, but writes an invalid checksum at the end, so that it is not visible to readers. Once this is called you must call .finishCommit to complete the commit or .rollbackCommit to abort it.

Link copied to clipboard
fun remove(index: Int)

Remove the SegmentCommitInfo at the provided index.

Remove the provided SegmentCommitInfo.

Link copied to clipboard
fun replace(other: SegmentInfos)

Replaces all segments in this instance, but keeps generation, version, counter so that future commits remain write once.

Link copied to clipboard
Link copied to clipboard
fun setNextWriteGeneration(generation: Long)

Set the generation to be used for the next commit

Link copied to clipboard
fun setUserData(data: MutableMap<String, String>, doIncrementVersion: Boolean)

Sets the commit data.

Link copied to clipboard
fun size(): Int

Returns number of SegmentCommitInfos.

Link copied to clipboard
open override fun toString(): String

Returns readable description of this segment.

Link copied to clipboard

Returns sum of all segment's maxDocs. Note that this does not include deletions

Link copied to clipboard

Carry over generation numbers from another SegmentInfos

Link copied to clipboard
fun write(out: IndexOutput)

Write ourselves to the provided IndexOutput