public final class SegmentInfos extends Object implements Cloneable, 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:
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 |
---|---|
int |
counter
Used to name new segments.
|
Map<String,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.
|
Constructor and Description |
---|
SegmentInfos(int indexCreatedVersionMajor)
Sole constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(SegmentCommitInfo si)
Appends the provided
SegmentCommitInfo . |
void |
addAll(Iterable<SegmentCommitInfo> sis)
Appends the provided
SegmentCommitInfo s. |
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
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
|
Collection<String> |
files(boolean includeSegmentsFile)
Returns all file names referenced by SegmentInfo.
|
static long |
generationFromSegmentsFileName(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 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(String[] files)
Get the generation of the most recent commit to the
list of index files (N in the segments_N file).
|
static String |
getLastCommitSegmentsFileName(Directory directory)
Get the filename of the segments_N file for the most
recent commit to the index in this Directory.
|
static String |
getLastCommitSegmentsFileName(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.
|
String |
getSegmentsFileName()
Get the segments_N filename in use by this segment infos.
|
Map<String,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. |
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,
String segmentFileName)
Read a particular segmentFileName.
|
static SegmentInfos |
readLatestCommit(Directory directory)
Find the latest commit (
segments_N file ) and
load all SegmentCommitInfo s. |
void |
remove(SegmentCommitInfo si)
Remove the provided
SegmentCommitInfo . |
static void |
setInfoStream(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(Map<String,String> data,
boolean doIncrementVersion)
Sets the commit data.
|
int |
size()
Returns number of
SegmentCommitInfo s. |
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 |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
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 int counter
public long version
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(String[] files)
files
- -- array of file names to checkpublic static long getLastCommitGeneration(Directory directory) throws IOException
directory
- -- directory to search for the latest segments_N fileIOException
public static String getLastCommitSegmentsFileName(String[] files)
files
- -- array of file names to checkpublic static String getLastCommitSegmentsFileName(Directory directory) throws IOException
directory
- -- directory to search for the latest segments_N fileIOException
public String getSegmentsFileName()
public static long generationFromSegmentsFileName(String fileName)
public byte[] getId()
public static final SegmentInfos readCommit(Directory directory, String segmentFileName) throws IOException
directory
- -- directory containing the segments filesegmentFileName
- -- segment file to loadCorruptIndexException
- if the index is corruptIOException
- if there is a low-level IO errorpublic static final SegmentInfos readCommit(Directory directory, ChecksumIndexInput input, long generation) throws IOException
ChecksumIndexInput
.IOException
public static final SegmentInfos readLatestCommit(Directory directory) throws IOException
segments_N file
) and
load all SegmentCommitInfo
s.IOException
public void write(Directory directory, IndexOutput out) throws IOException
IndexOutput
IOException
public SegmentInfos clone()
public long getVersion()
public long getGeneration()
public long getLastGeneration()
public static void setInfoStream(PrintStream infoStream)
public static PrintStream getInfoStream()
infoStream
.setInfoStream(java.io.PrintStream)
public void updateGeneration(SegmentInfos other)
public void setNextWriteGeneration(long generation)
public Collection<String> files(boolean includeSegmentsFile) throws IOException
IOException
public final void commit(Directory dir) throws IOException
Note: changed()
should be called prior to this
method if changes have been made to this SegmentInfos
instance
IOException
public String toString()
public Map<String,String> getUserData()
userData
saved with this commit.IndexWriter.commit()
public void setUserData(Map<String,String> data, boolean doIncrementVersion)
public int totalMaxDoc()
public void changed()
public Iterator<SegmentCommitInfo> iterator()
Iterator
of contained segments in order.iterator
in interface Iterable<SegmentCommitInfo>
public List<SegmentCommitInfo> asList()
List
view.public int size()
SegmentCommitInfo
s.public void add(SegmentCommitInfo si)
SegmentCommitInfo
.public void addAll(Iterable<SegmentCommitInfo> sis)
SegmentCommitInfo
s.public void clear()
SegmentCommitInfo
s.public void 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-2017 Apache Software Foundation. All Rights Reserved.