public final class

SegmentInfos

extends Object
implements Cloneable Iterable<T>
java.lang.Object
   ↳ org.apache.lucene.index.SegmentInfos

Class Overview

A collection of segmentInfo objects with methods for operating on those segments in relation to the file system.

Summary

Nested Classes
class SegmentInfos.FindSegmentsFile Utility class for executing code that needs to do something with the current segments file. 
Constants
int CURRENT_FORMAT
int FORMAT The file format version, a negative number.
int FORMAT_3_1 Each segment records the Lucene version that created it.
int FORMAT_CHECKSUM This format adds a checksum at the end of the file to ensure all bytes were successfully written.
int FORMAT_DEL_COUNT This format adds the deletion count for each segment.
int FORMAT_DIAGNOSTICS This format adds optional per-segment String diagnostics storage, and switches userData to Map
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)
int FORMAT_HAS_VECTORS Each segment records whether it has term vectors
int FORMAT_LOCKLESS This format adds details used for lockless commits.
int FORMAT_SHARED_DOC_STORE This format allows multiple segments to share a single vectors and stored fields file.
int FORMAT_SINGLE_NORM_FILE This format adds a "hasSingleNormFile" flag into each segment info.
int FORMAT_USER_DATA This format adds optional commit userData (String) storage.
Fields
public int counter
Public Constructors
SegmentInfos()
Public Methods
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 String getCurrentSegmentFileName(Directory directory)
Get the filename of the current segments_N file in the directory.
static String getCurrentSegmentFileName(String[] files)
Get the filename of the current segments_N file from a list of files.
String getCurrentSegmentFileName()
Get the segments_N filename in use by this segment infos.
static long getCurrentSegmentGeneration(Directory directory)
Get the generation (N) of the current segments_N file in the directory.
static long getCurrentSegmentGeneration(String[] files)
Get the generation (N) of the current segments_N file from a list of files.
static int getDefaultGenFileRetryCount()
static int getDefaultGenFileRetryPauseMsec()
static int getDefaultGenLookahedCount()
int getFormat()
long getGeneration()
static PrintStream getInfoStream()
long getLastGeneration()
String getNextSegmentFileName()
Get the next segments_N filename that will be written.
Map<StringString> 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.
@Deprecated SegmentInfos range(int first, int last)
This method is deprecated. use asList().subList(first, last) instead.
final void read(Directory directory, String segmentFileName)
Read a particular segmentFileName.
final void read(Directory directory)
This version of read uses the retry logic (for lock-less commits) to find the right segments file to load.
static Map<StringString> readCurrentUserData(Directory directory)
Returns userData from latest segments file
static long readCurrentVersion(Directory directory)
Current version number from segments file.
void remove(SegmentInfo si)
void remove(int index)
static void setDefaultGenFileRetryCount(int count)
Advanced: set how many times to try loading the segments.gen file contents to determine current segment generation.
static void setDefaultGenFileRetryPauseMsec(int msec)
Advanced: set how many milliseconds to pause in between attempts to load the segments.gen file.
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.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Iterable

Constants

public static final int CURRENT_FORMAT

Constant Value: -11 (0xfffffff5)

public static final int FORMAT

The file format version, a negative number.

Constant Value: -1 (0xffffffff)

public static final int FORMAT_3_1

Each segment records the Lucene version that created it.

Constant Value: -11 (0xfffffff5)

public static final int FORMAT_CHECKSUM

This format adds a checksum at the end of the file to ensure all bytes were successfully written.

Constant Value: -5 (0xfffffffb)

public static final int FORMAT_DEL_COUNT

This format adds the deletion count for each segment. This way IndexWriter can efficiently report numDocs().

Constant Value: -6 (0xfffffffa)

public static final int FORMAT_DIAGNOSTICS

This format adds optional per-segment String diagnostics storage, and switches userData to Map

Constant Value: -9 (0xfffffff7)

public static final 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)

Constant Value: -7 (0xfffffff9)

public static final int FORMAT_HAS_VECTORS

Each segment records whether it has term vectors

Constant Value: -10 (0xfffffff6)

public static final int FORMAT_LOCKLESS

This format adds details used for lockless commits. It differs slightly from the previous format in that file names are never re-used (write once). Instead, each file is written to the next generation. For example, segments_1, segments_2, etc. This allows us to not use a commit lock. See file formats for details.

Constant Value: -2 (0xfffffffe)

public static final int FORMAT_SHARED_DOC_STORE

This format allows multiple segments to share a single vectors and stored fields file.

Constant Value: -4 (0xfffffffc)

public static final int FORMAT_SINGLE_NORM_FILE

This format adds a "hasSingleNormFile" flag into each segment info. See LUCENE-756 for details.

Constant Value: -3 (0xfffffffd)

public static final int FORMAT_USER_DATA

This format adds optional commit userData (String) storage.

Constant Value: -8 (0xfffffff8)

Fields

public int counter

Public Constructors

public SegmentInfos ()

Public Methods

public void add (SegmentInfo si)

public void addAll (Iterable<SegmentInfo> sis)

public List<SegmentInfo> asList ()

Returns all contained segments as an unmodifiable List view.

public Set<SegmentInfo> asSet ()

Returns all contained segments as an unmodifiable Set view. The iterator is not sorted, use List view or iterator() to get all segments in order.

public void changed ()

Call this before committing if changes have been made to the segments.

public void clear ()

public Object clone ()

Returns a copy of this instance, also copying each SegmentInfo.

public boolean contains (SegmentInfo si)

public 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). The returned collection is recomputed on each invocation.

Throws
IOException

public static long generationFromSegmentsFileName (String fileName)

Parse the generation off the segments file name and return it.

public static String getCurrentSegmentFileName (Directory directory)

Get the filename of the current segments_N file in the directory.

Parameters
directory -- directory to search for the latest segments_N file
Throws
IOException

public static String getCurrentSegmentFileName (String[] files)

Get the filename of the current segments_N file from a list of files.

Parameters
files -- array of file names to check
Throws
IOException

public String getCurrentSegmentFileName ()

Get the segments_N filename in use by this segment infos.

public static long getCurrentSegmentGeneration (Directory directory)

Get the generation (N) of the current segments_N file in the directory.

Parameters
directory -- directory to search for the latest segments_N file
Throws
IOException

public static long getCurrentSegmentGeneration (String[] files)

Get the generation (N) of the current segments_N file from a list of files.

Parameters
files -- array of file names to check

public static int getDefaultGenFileRetryCount ()

public static int getDefaultGenFileRetryPauseMsec ()

public static int getDefaultGenLookahedCount ()

public int getFormat ()

public long getGeneration ()

public static PrintStream getInfoStream ()

public long getLastGeneration ()

public String getNextSegmentFileName ()

Get the next segments_N filename that will be written.

public Map<StringString> getUserData ()

public long getVersion ()

version number when this SegmentInfos was generated.

public int indexOf (SegmentInfo si)

public SegmentInfo info (int i)

public Iterator<SegmentInfo> iterator ()

Returns an unmodifiable Iterator of contained segments in order.

public void pruneDeletedSegments ()

Prunes any segment whose docs are all deleted.

Throws
IOException

@Deprecated public SegmentInfos range (int first, int last)

This method is deprecated.
use asList().subList(first, last) instead.

Returns a new SegmentInfos containing the SegmentInfo instances in the specified range first (inclusive) to last (exclusive), so total number of segments returned is last-first.

public final void read (Directory directory, String segmentFileName)

Read a particular segmentFileName. Note that this may throw an IOException if a commit is in process.

Parameters
directory -- directory containing the segments file
segmentFileName -- segment file to load
Throws
CorruptIndexException if the index is corrupt
IOException if there is a low-level IO error

public final void read (Directory directory)

This version of read uses the retry logic (for lock-less commits) to find the right segments file to load.

Throws
CorruptIndexException if the index is corrupt
IOException if there is a low-level IO error

public static Map<StringString> readCurrentUserData (Directory directory)

Returns userData from latest segments file

Throws
CorruptIndexException if the index is corrupt
IOException if there is a low-level IO error

public static long readCurrentVersion (Directory directory)

Current version number from segments file.

Throws
CorruptIndexException if the index is corrupt
IOException if there is a low-level IO error

public void remove (SegmentInfo si)

public void remove (int index)

public static void setDefaultGenFileRetryCount (int count)

Advanced: set how many times to try loading the segments.gen file contents to determine current segment generation. This file is only referenced when the primary method (listing the directory) fails.

public static void setDefaultGenFileRetryPauseMsec (int msec)

Advanced: set how many milliseconds to pause in between attempts to load the segments.gen file.

public static void setDefaultGenLookaheadCount (int count)

Advanced: set how many times to try incrementing the gen when loading the segments file. This only runs if the primary (listing directory) and secondary (opening segments.gen file) methods fail to find the segments file.

public void setFormat (int format)

public static void setInfoStream (PrintStream infoStream)

If non-null, information about retries when loading the segments file will be printed to this.

public int size ()

public String toString (Directory directory)

public int totalDocCount ()

Returns sum of all segment's docCounts. Note that this does not include deletions