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:
IndexHeaderInt32Int64Int8Int8ID_LENGTHStringMap<String,String>Int32,
Set<String>>CodecFooter
LiveDocsFormat.name of the Codec that encoded
this segment.null and no SegID is written. Null only happens for Lucene
4.x segments referenced in commits.IndexWriter.setCommitData(java.util.Map).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_40
The file format version for the segments_N codec header, up to 4.5.
|
static int |
VERSION_46
The file format version for the segments_N codec header, since 4.6+.
|
static int |
VERSION_48
The file format version for the segments_N codec header, since 4.8+
|
static int |
VERSION_49
The file format version for the segments_N codec header, since 4.9+
|
static int |
VERSION_50
The file format version for the segments_N codec header, since 5.0+
|
| Constructor and Description |
|---|
SegmentInfos()
Sole constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(SegmentCommitInfo si)
Appends the provided
SegmentCommitInfo. |
void |
addAll(Iterable<SegmentCommitInfo> sis)
Appends the provided
SegmentCommitInfos. |
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.
|
Collection<String> |
files(Directory dir,
boolean includeSegmentsFile)
Returns all file names referenced by SegmentInfo
instances matching the provided Directory (ie files
associated with any "external" segments are skipped).
|
static long |
generationFromSegmentsFileName(String fileName)
Parse the generation off the segments file name and
return it.
|
long |
getGeneration()
Returns current generation.
|
byte[] |
getId()
Since Lucene 5.0, every commit (segments_N) writes a unique id.
|
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.
|
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,
String segmentFileName)
Read a particular segmentFileName.
|
static SegmentInfos |
readLatestCommit(Directory directory)
Find the latest commit (
segments_N file) and
load all SegmentCommitInfos. |
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.
|
int |
size()
Returns number of
SegmentCommitInfos. |
String |
toString(Directory directory)
Returns readable description of this segment.
|
int |
totalDocCount()
Returns sum of all segment's docCounts.
|
public static final int VERSION_40
public static final int VERSION_46
public static final int VERSION_48
public static final int VERSION_49
public static final int VERSION_50
public int counter
public long version
public SegmentInfos()
or
#readCommit(Directory,String) to populate each SegmentCommitInfo. Alternatively, you can add/remove your
own SegmentCommitInfos.public 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 fileIOExceptionpublic 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 fileIOExceptionpublic 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 readLatestCommit(Directory directory) throws IOException
segments_N file) and
load all SegmentCommitInfos.IOExceptionpublic 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 Collection<String> files(Directory dir, boolean includeSegmentsFile) throws IOException
IOExceptionpublic Map<String,String> getUserData()
userData saved with this commit.IndexWriter.commit()public int totalDocCount()
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()
SegmentCommitInfos.public void add(SegmentCommitInfo si)
SegmentCommitInfo.public void addAll(Iterable<SegmentCommitInfo> sis)
SegmentCommitInfos.public void clear()
SegmentCommitInfos.public void remove(SegmentCommitInfo si)
SegmentCommitInfo.
WARNING: O(N) cost
Copyright © 2000-2015 Apache Software Foundation. All Rights Reserved.