public final class SegmentInfos extends Object implements Cloneable, Iterable<SegmentInfo>
Modifier and Type | Class and Description |
---|---|
static class |
SegmentInfos.FindSegmentsFile
Utility class for executing code that needs to do
something with the current segments file.
|
Modifier and Type | Field and Description |
---|---|
int |
counter |
static int |
CURRENT_FORMAT |
static int |
FORMAT
The file format version, a negative number.
|
static int |
FORMAT_3_1
Each segment records the Lucene version that created it.
|
static int |
FORMAT_CHECKSUM
This format adds a checksum at the end of the file to
ensure all bytes were successfully written.
|
static int |
FORMAT_DEL_COUNT
This format adds the deletion count for each segment.
|
static int |
FORMAT_DIAGNOSTICS
This format adds optional per-segment String
diagnostics storage, and switches userData to Map
|
static int |
FORMAT_HAS_PROX
This format adds the boolean hasProx to record if any
fields in the segment store prox information (ie, have
omitTermFreqAndPositions==false)
|
static int |
FORMAT_HAS_VECTORS
Each segment records whether it has term vectors
|
static int |
FORMAT_LOCKLESS
This format adds details used for lockless commits.
|
static int |
FORMAT_MAXIMUM |
static int |
FORMAT_MINIMUM |
static int |
FORMAT_SHARED_DOC_STORE
This format allows multiple segments to share a single
vectors and stored fields file.
|
static int |
FORMAT_SINGLE_NORM_FILE
This format adds a "hasSingleNormFile" flag into each segment info.
|
static int |
FORMAT_USER_DATA
This format adds optional commit userData (String) storage.
|
Constructor and Description |
---|
SegmentInfos() |
Modifier and Type | Method and Description |
---|---|
void |
add(SegmentInfo si) |
void |
addAll(Iterable<SegmentInfo> sis) |
List<SegmentInfo> |
asList()
Returns all contained segments as an unmodifiable
List view. |
Set<SegmentInfo> |
asSet()
Returns all contained segments as an unmodifiable
Set view. |
void |
changed()
Call this before committing if changes have been made to the
segments.
|
void |
clear() |
Object |
clone()
Returns a copy of this instance, also copying each
SegmentInfo.
|
boolean |
contains(SegmentInfo si) |
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.
|
static int |
getDefaultGenLookahedCount() |
int |
getFormat() |
long |
getGeneration() |
static PrintStream |
getInfoStream() |
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() |
String |
getNextSegmentFileName()
Get the next segments_N filename that will be written.
|
String |
getSegmentsFileName()
Get the segments_N filename in use by this segment infos.
|
Map<String,String> |
getUserData() |
long |
getVersion()
version number when this SegmentInfos was generated.
|
int |
indexOf(SegmentInfo si) |
SegmentInfo |
info(int i) |
Iterator<SegmentInfo> |
iterator()
Returns an unmodifiable
Iterator of contained segments in order. |
void |
pruneDeletedSegments()
Prunes any segment whose docs are all deleted.
|
SegmentInfos |
range(int first,
int last)
Deprecated.
use
asList().subList(first, last)
instead. |
void |
read(Directory directory)
This version of read uses the retry logic (for lock-less
commits) to find the right segments file to load.
|
void |
read(Directory directory,
String segmentFileName)
Read a particular segmentFileName.
|
static long |
readCurrentVersion(Directory directory)
Deprecated.
Load the SegmentInfos and then call
getVersion() . |
void |
remove(int index) |
void |
remove(SegmentInfo si) |
static void |
setDefaultGenLookaheadCount(int count)
Advanced: set how many times to try incrementing the
gen when loading the segments file.
|
void |
setFormat(int format) |
static void |
setInfoStream(PrintStream infoStream)
If non-null, information about retries when loading
the segments file will be printed to this.
|
int |
size() |
String |
toString(Directory directory) |
int |
totalDocCount()
Returns sum of all segment's docCounts.
|
public static final int FORMAT
public static final int FORMAT_LOCKLESS
public static final int FORMAT_SINGLE_NORM_FILE
public static final int FORMAT_SHARED_DOC_STORE
public static final int FORMAT_CHECKSUM
public static final int FORMAT_DEL_COUNT
public static final int FORMAT_HAS_PROX
public static final int FORMAT_USER_DATA
public static final int FORMAT_DIAGNOSTICS
public static final int FORMAT_HAS_VECTORS
public static final int FORMAT_3_1
public static final int CURRENT_FORMAT
public static final int FORMAT_MINIMUM
public static final int FORMAT_MAXIMUM
public int counter
public void setFormat(int format)
public int getFormat()
public SegmentInfo info(int i)
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) throws IOException
files
- -- array of file names to checkIOException
public 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 String getNextSegmentFileName()
public final void read(Directory directory, String segmentFileName) throws CorruptIndexException, IOException
directory
- -- directory containing the segments filesegmentFileName
- -- segment file to loadCorruptIndexException
- if the index is corruptIOException
- if there is a low-level IO errorpublic final void read(Directory directory) throws CorruptIndexException, IOException
CorruptIndexException
- if the index is corruptIOException
- if there is a low-level IO errorpublic void pruneDeletedSegments() throws IOException
IOException
public Object clone()
public long getVersion()
public long getGeneration()
public long getLastGeneration()
@Deprecated public static long readCurrentVersion(Directory directory) throws CorruptIndexException, IOException
getVersion()
.CorruptIndexException
- if the index is corruptIOException
- if there is a low-level IO errorpublic static void setInfoStream(PrintStream infoStream)
public static void setDefaultGenLookaheadCount(int count)
public static int getDefaultGenLookahedCount()
setDefaultGenLookaheadCount(int)
public static PrintStream getInfoStream()
setInfoStream(java.io.PrintStream)
@Deprecated public SegmentInfos range(int first, int last)
asList().subList(first, last)
instead.public Collection<String> files(Directory dir, boolean includeSegmentsFile) throws IOException
IOException
public int totalDocCount()
public void changed()
public Iterator<SegmentInfo> iterator()
Iterator
of contained segments in order.iterator
in interface Iterable<SegmentInfo>
public List<SegmentInfo> asList()
List
view.public Set<SegmentInfo> asSet()
Set
view.
The iterator is not sorted, use List
view or iterator()
to get all segments in order.public int size()
public void add(SegmentInfo si)
public void addAll(Iterable<SegmentInfo> sis)
public void clear()
public void remove(SegmentInfo si)
public void remove(int index)
public boolean contains(SegmentInfo si)
public int indexOf(SegmentInfo si)