public final class SegmentInfos extends java.lang.Object implements java.lang.Cloneable, java.lang.Iterable<SegmentCommitInfo>
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:
IndexHeaderVersion was used for this commit, written as three vInt: major, minor, bugfix
Version of the oldest segment, written as three vInt: major, minor, bugfix; this is only
written only if there's at least one segment
Int32Int64Int8ID_LENGTHStringMap<String,String>Int32,
Set<String>>CodecFooterLiveDocsFormat.name of the Codec that encoded
this segment.IndexWriter.setLiveCommitData(Iterable).FieldInfosFormat
.DocValuesFormat.| Modifier and Type | Class and Description |
|---|---|
static class |
SegmentInfos.FindSegmentsFile<T>
Utility class for executing code that needs to do
something with the current segments file.
|
| Modifier and Type | Field and Description |
|---|---|
long |
counter
Used to name new segments.
|
java.util.Map<java.lang.String,java.lang.String> |
userData
Opaque Map<String, String> that user can specify during IndexWriter.commit
|
long |
version
Counts how often the index has been changed.
|
static int |
VERSION_53
|
static int |
VERSION_70
The version that added information about the Lucene version at the time when the index has been created.
|
static int |
VERSION_72
The version that updated segment name counter to be long instead of int.
|
static int |
VERSION_74
The version that recorded softDelCount
|
| Constructor and Description |
|---|
SegmentInfos(int indexCreatedVersionMajor)
Sole constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(SegmentCommitInfo si)
Appends the provided
SegmentCommitInfo. |
void |
addAll(java.lang.Iterable<SegmentCommitInfo> sis)
Appends the provided
SegmentCommitInfos. |
java.util.List<SegmentCommitInfo> |
asList()
Returns all contained segments as an unmodifiable
List view. |
void |
changed()
Call this before committing if changes have been made to the
segments.
|
void |
clear()
Clear all
SegmentCommitInfos. |
SegmentInfos |
clone()
Returns a copy of this instance, also copying each
SegmentInfo.
|
void |
commit(Directory dir)
Writes and syncs to the Directory dir, taking care to
remove the segments file on exception
|
java.util.Collection<java.lang.String> |
files(boolean includeSegmentsFile)
Returns all file names referenced by SegmentInfo.
|
static long |
generationFromSegmentsFileName(java.lang.String fileName)
Parse the generation off the segments file name and
return it.
|
Version |
getCommitLuceneVersion()
Returns which Lucene
Version wrote this commit, or null if the
version this index was written with did not directly record the version. |
long |
getGeneration()
Returns current generation.
|
byte[] |
getId()
Since Lucene 5.0, every commit (segments_N) writes a unique id.
|
int |
getIndexCreatedVersionMajor()
Return the version major that was used to initially create the index.
|
static java.io.PrintStream |
getInfoStream()
Returns
infoStream. |
static long |
getLastCommitGeneration(Directory directory)
Get the generation of the most recent commit to the
index in this directory (N in the segments_N file).
|
static long |
getLastCommitGeneration(java.lang.String[] files)
Get the generation of the most recent commit to the
list of index files (N in the segments_N file).
|
static java.lang.String |
getLastCommitSegmentsFileName(Directory directory)
Get the filename of the segments_N file for the most
recent commit to the index in this Directory.
|
static java.lang.String |
getLastCommitSegmentsFileName(java.lang.String[] files)
Get the filename of the segments_N file for the most
recent commit in the list of index files.
|
long |
getLastGeneration()
Returns last succesfully read or written generation.
|
Version |
getMinSegmentLuceneVersion()
Returns the version of the oldest segment, or null if there are no segments.
|
java.lang.String |
getSegmentsFileName()
Get the segments_N filename in use by this segment infos.
|
java.util.Map<java.lang.String,java.lang.String> |
getUserData()
Return
userData saved with this commit. |
long |
getVersion()
version number when this SegmentInfos was generated.
|
SegmentCommitInfo |
info(int i)
Returns
SegmentCommitInfo at the provided
index. |
java.util.Iterator<SegmentCommitInfo> |
iterator()
Returns an unmodifiable
Iterator of contained segments in order. |
static SegmentInfos |
readCommit(Directory directory,
ChecksumIndexInput input,
long generation)
Read the commit from the provided
ChecksumIndexInput. |
static SegmentInfos |
readCommit(Directory directory,
java.lang.String segmentFileName)
Read a particular segmentFileName.
|
static SegmentInfos |
readLatestCommit(Directory directory)
Find the latest commit (
segments_N file) and
load all SegmentCommitInfos. |
boolean |
remove(SegmentCommitInfo si)
Remove the provided
SegmentCommitInfo. |
static void |
setInfoStream(java.io.PrintStream infoStream)
If non-null, information about retries when loading
the segments file will be printed to this.
|
void |
setNextWriteGeneration(long generation)
Set the generation to be used for the next commit
|
void |
setUserData(java.util.Map<java.lang.String,java.lang.String> data,
boolean doIncrementVersion)
Sets the commit data.
|
int |
size()
Returns number of
SegmentCommitInfos. |
java.lang.String |
toString()
Returns readable description of this segment.
|
int |
totalMaxDoc()
Returns sum of all segment's maxDocs.
|
void |
updateGeneration(SegmentInfos other)
Carry over generation numbers from another SegmentInfos
|
void |
write(Directory directory,
IndexOutput out)
Write ourselves to the provided
IndexOutput |
public static final int VERSION_53
Version that committed this segments_N file, as well as the Version of the oldest segment, since 5.3+public static final int VERSION_70
public static final int VERSION_72
public static final int VERSION_74
public long counter
public long version
public java.util.Map<java.lang.String,java.lang.String> userData
public SegmentInfos(int indexCreatedVersionMajor)
indexCreatedVersionMajor - the Lucene version major at index creation time, or 6 if the index was created before 7.0public SegmentCommitInfo info(int i)
SegmentCommitInfo at the provided
index.public static long getLastCommitGeneration(java.lang.String[] files)
files - -- array of file names to checkpublic static long getLastCommitGeneration(Directory directory) throws java.io.IOException
directory - -- directory to search for the latest segments_N filejava.io.IOExceptionpublic static java.lang.String getLastCommitSegmentsFileName(java.lang.String[] files)
files - -- array of file names to checkpublic static java.lang.String getLastCommitSegmentsFileName(Directory directory) throws java.io.IOException
directory - -- directory to search for the latest segments_N filejava.io.IOExceptionpublic java.lang.String getSegmentsFileName()
public static long generationFromSegmentsFileName(java.lang.String fileName)
public byte[] getId()
public static final SegmentInfos readCommit(Directory directory, java.lang.String segmentFileName) throws java.io.IOException
directory - -- directory containing the segments filesegmentFileName - -- segment file to loadCorruptIndexException - if the index is corruptjava.io.IOException - if there is a low-level IO errorpublic static final SegmentInfos readCommit(Directory directory, ChecksumIndexInput input, long generation) throws java.io.IOException
ChecksumIndexInput.java.io.IOExceptionpublic static final SegmentInfos readLatestCommit(Directory directory) throws java.io.IOException
segments_N file) and
load all SegmentCommitInfos.java.io.IOExceptionpublic void write(Directory directory, IndexOutput out) throws java.io.IOException
IndexOutputjava.io.IOExceptionpublic SegmentInfos clone()
clone in class java.lang.Objectpublic long getVersion()
public long getGeneration()
public long getLastGeneration()
public static void setInfoStream(java.io.PrintStream infoStream)
public static java.io.PrintStream getInfoStream()
infoStream.setInfoStream(java.io.PrintStream)public void updateGeneration(SegmentInfos other)
public void setNextWriteGeneration(long generation)
public java.util.Collection<java.lang.String> files(boolean includeSegmentsFile)
throws java.io.IOException
java.io.IOExceptionpublic final void commit(Directory dir) throws java.io.IOException
Note: changed() should be called prior to this
method if changes have been made to this SegmentInfos instance
java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Map<java.lang.String,java.lang.String> getUserData()
userData saved with this commit.IndexWriter.commit()public void setUserData(java.util.Map<java.lang.String,java.lang.String> data,
boolean doIncrementVersion)
public int totalMaxDoc()
public void changed()
public java.util.Iterator<SegmentCommitInfo> iterator()
Iterator of contained segments in order.iterator in interface java.lang.Iterable<SegmentCommitInfo>public java.util.List<SegmentCommitInfo> asList()
List view.public int size()
SegmentCommitInfos.public void add(SegmentCommitInfo si)
SegmentCommitInfo.public void addAll(java.lang.Iterable<SegmentCommitInfo> sis)
SegmentCommitInfos.public void clear()
SegmentCommitInfos.public boolean remove(SegmentCommitInfo si)
SegmentCommitInfo.
WARNING: O(N) cost
public Version getCommitLuceneVersion()
Version wrote this commit, or null if the
version this index was written with did not directly record the version.public Version getMinSegmentLuceneVersion()
public int getIndexCreatedVersionMajor()
Copyright © 2000–2025 The Apache Software Foundation. All rights reserved.