public final class SegmentInfos extends implements , <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:
IndexHeader
Version
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
Int32
Int64
Int8ID_LENGTH
String
Map<String,String>
Int32
,
Set<String>
>CodecFooter
LiveDocsFormat
.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.
|
<,> |
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_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
|
static int |
VERSION_86
The version that recorded SegmentCommitInfo IDs
|
Constructor and Description |
---|
SegmentInfos(int indexCreatedVersionMajor)
Sole constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(SegmentCommitInfo si)
Appends the provided
SegmentCommitInfo . |
void |
<SegmentCommitInfo> sis)
Appends the provided
SegmentCommitInfo s. |
<SegmentCommitInfo> |
asList()
Returns all contained segments as an unmodifiable view.
|
void |
changed()
Call this before committing if changes have been made to the
segments.
|
void |
clear()
Clear all
SegmentCommitInfo s. |
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
|
<> |
files(boolean includeSegmentsFile)
Returns all file names referenced by SegmentInfo.
|
static long |
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 |
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 |
[] files)
Get the generation of the most recent commit to the
list of index files (N in the segments_N file).
|
static |
getLastCommitSegmentsFileName(Directory directory)
Get the filename of the segments_N file for the most
recent commit to the index in this Directory.
|
static |
[] 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.
|
|
getSegmentsFileName()
Get the segments_N filename in use by this segment infos.
|
<,> |
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. |
<SegmentCommitInfo> |
iterator()
Returns an unmodifiable 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,
segmentFileName)
Read a particular segmentFileName.
|
static SegmentInfos |
readLatestCommit(Directory directory)
Find the latest commit (
segments_N file ) and
load all SegmentCommitInfo s. |
boolean |
remove(SegmentCommitInfo si)
Remove the provided
SegmentCommitInfo . |
static void |
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 |
<,> data,
boolean doIncrementVersion)
Sets the commit data.
|
int |
size()
Returns number of
SegmentCommitInfo s. |
|
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(IndexOutput out)
Write ourselves to the provided
IndexOutput |
public static final int VERSION_70
public static final int VERSION_72
public static final int VERSION_74
public static final int VERSION_86
public long counter
public long version
public <,> 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([] files)
files
- -- array of file names to checkpublic static long getLastCommitGeneration(Directory directory) throws
directory
- -- directory to search for the latest segments_N file
public static getLastCommitSegmentsFileName([] files)
files
- -- array of file names to checkpublic static getLastCommitSegmentsFileName(Directory directory) throws
directory
- -- directory to search for the latest segments_N file
public getSegmentsFileName()
public static long generationFromSegmentsFileName( fileName)
public byte[] getId()
public static final SegmentInfos readCommit(Directory directory, segmentFileName) throws
directory
- -- directory containing the segments filesegmentFileName
- -- segment file to loadCorruptIndexException
- if the index is corrupt
- if there is a low-level IO errorpublic static final SegmentInfos readCommit(Directory directory, ChecksumIndexInput input, long generation) throws
ChecksumIndexInput
.
public static final SegmentInfos readLatestCommit(Directory directory) throws
segments_N file
) and
load all SegmentCommitInfo
s.
public void write(IndexOutput out) throws
IndexOutput
public SegmentInfos clone()
in class
public long getVersion()
public long getGeneration()
public long getLastGeneration()
public static void setInfoStream( infoStream)
public static getInfoStream()
infoStream
.setInfoStream(java.io.PrintStream)
public void updateGeneration(SegmentInfos other)
public void setNextWriteGeneration(long generation)
public <> files(boolean includeSegmentsFile) throws
public final void commit(Directory dir) throws
Note: changed()
should be called prior to this
method if changes have been made to this SegmentInfos
instance
public toString()
in class
public <,> getUserData()
userData
saved with this commit.IndexWriter.commit()
public void setUserData(<,> data, boolean doIncrementVersion)
public int totalMaxDoc()
public void changed()
public <SegmentCommitInfo> iterator()
in interface <SegmentCommitInfo>
public <SegmentCommitInfo> asList()
public int size()
SegmentCommitInfo
s.public void add(SegmentCommitInfo si)
SegmentCommitInfo
.public void addAll(<SegmentCommitInfo> sis)
SegmentCommitInfo
s.public void clear()
SegmentCommitInfo
s.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-2021 Apache Software Foundation. All Rights Reserved.