## org.apache.lucene.index
Class SegmentInfos

    java.lang.Object
      java.util.AbstractCollection<E>
          java.util.AbstractList<E>
              java.util.Vector
                  org.apache.lucene.index.SegmentInfos

All Implemented Interfaces:
  java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

    public final class SegmentInfos

extends java.util.Vector

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

NOTE: This API is new and still experimental (subject to change suddenly in the next release)

See Also:
  Serialized Form

Nested Class Summary
`static class` `SegmentInfos.FindSegmentsFile` Utility class for executing code that needs to do something with the current segments file.

Field Summary
`int` `counter`
`static int` `FORMAT` The file format version, a negative number.
`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_LOCKLESS` This format adds details used for lockless commits.
`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.

Fields inherited from class java.util.Vector
`capacityIncrement, elementCount, elementData`

Fields inherited from class java.util.AbstractList
`modCount`

Constructor Summary
`SegmentInfos()`

Method Summary
`java.lang.Object` `clone()` Returns a copy of this instance, also copying each SegmentInfo.
`java.util.Collection` `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(java.lang.String fileName)` Parse the generation off the segments file name and return it.
`java.lang.String` `getCurrentSegmentFileName()` Get the segments_N filename in use by this segment infos.
`static java.lang.String` `getCurrentSegmentFileName(Directory directory)` Get the filename of the current segments_N file in the directory.
`static java.lang.String` `getCurrentSegmentFileName(java.lang.String[] files)` Get the filename of the current segments_N file from a list of files.
`static long` `getCurrentSegmentGeneration(Directory directory)` Get the generation (N) of the current segments_N file in the directory.
`static long` `getCurrentSegmentGeneration(java.lang.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()`
`long` `getGeneration()`
`static java.io.PrintStream` `getInfoStream()`
`long` `getLastGeneration()`
`java.lang.String` `getNextSegmentFileName()` Get the next segments_N filename that will be written.
`java.util.Map` `getUserData()`
`long` `getVersion()` version number when this SegmentInfos was generated.
`boolean` `hasExternalSegments(Directory dir)`
`SegmentInfo` `info(int i)`
`SegmentInfos` `range(int first, int last)` 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.
`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, java.lang.String segmentFileName)` Read a particular segmentFileName.
`static java.util.Map` `readCurrentUserData(Directory directory)` Returns userData from latest segments file
`static long` `readCurrentVersion(Directory directory)` Current version number from segments file.
`java.lang.String` `segString(Directory directory)`
`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.
`static void` `setInfoStream(java.io.PrintStream infoStream)` If non-null, information about retries when loading the segments file will be printed to this.

Methods inherited from class java.util.Vector

`add, add, addAll, addAll, addElement, capacity, clear, contains, containsAll, copyInto, elementAt, elements, ensureCapacity, equals, firstElement, get, hashCode, indexOf, indexOf, insertElementAt, isEmpty, iterator, lastElement, lastIndexOf, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeAllElements, removeElement, removeElementAt, removeRange, retainAll, set, setElementAt, setSize, size, subList, toArray, toArray, toString, trimToSize`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### FORMAT

    public static final int FORMAT

  The file format version, a negative number.

  See Also:
    Constant Field Values

### FORMAT_LOCKLESS

    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.

  See Also:
    Constant Field Values

### FORMAT_SINGLE_NORM_FILE

    public static final int FORMAT_SINGLE_NORM_FILE

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

  See Also:
    Constant Field Values

### FORMAT_SHARED_DOC_STORE

    public static final int FORMAT_SHARED_DOC_STORE

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

  See Also:
    Constant Field Values

### FORMAT_CHECKSUM

    public static final int FORMAT_CHECKSUM

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

  See Also:
    Constant Field Values

### FORMAT_DEL_COUNT

    public static final int FORMAT_DEL_COUNT

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

  See Also:
    Constant Field Values

### FORMAT_HAS_PROX

    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)

  See Also:
    Constant Field Values

### FORMAT_USER_DATA

    public static final int FORMAT_USER_DATA

  This format adds optional commit userData (String) storage.

  See Also:
    Constant Field Values

### FORMAT_DIAGNOSTICS

    public static final int FORMAT_DIAGNOSTICS

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

  See Also:
    Constant Field Values

### counter

    public int counter

Constructor Detail

### SegmentInfos

    public SegmentInfos()

Method Detail

### info

    public final SegmentInfo info(int i)

### getCurrentSegmentGeneration

    public static long getCurrentSegmentGeneration(java.lang.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

### getCurrentSegmentGeneration

    public static long getCurrentSegmentGeneration(Directory directory)
                                            throws java.io.IOException

  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:
    `java.io.IOException`

### getCurrentSegmentFileName

    public static java.lang.String getCurrentSegmentFileName(java.lang.String[] files)
                                                      throws java.io.IOException

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

  Parameters:
    `files` - -- array of file names to check
  Throws:
    `java.io.IOException`

### getCurrentSegmentFileName

    public static java.lang.String getCurrentSegmentFileName(Directory directory)
                                                      throws java.io.IOException

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

  Parameters:
    `directory` - -- directory to search for the latest segments_N file
  Throws:
    `java.io.IOException`

### getCurrentSegmentFileName

    public java.lang.String getCurrentSegmentFileName()

  Get the segments_N filename in use by this segment infos.

### generationFromSegmentsFileName

    public static long generationFromSegmentsFileName(java.lang.String fileName)

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

### getNextSegmentFileName

    public java.lang.String getNextSegmentFileName()

  Get the next segments_N filename that will be written.

### read

    public final void read(Directory directory,
                           java.lang.String segmentFileName)
                    throws CorruptIndexException,
                           java.io.IOException

  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
    `java.io.IOException` - if there is a low-level IO error

### read

    public final void read(Directory directory)
                    throws CorruptIndexException,
                           java.io.IOException

  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
    `java.io.IOException` - if there is a low-level IO error

### clone

    public java.lang.Object clone()

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

  Overrides:
    `clone` in class `java.util.Vector`

### getVersion

    public long getVersion()

  version number when this SegmentInfos was generated.

### getGeneration

    public long getGeneration()

### getLastGeneration

    public long getLastGeneration()

### readCurrentVersion

    public static long readCurrentVersion(Directory directory)
                                   throws CorruptIndexException,
                                          java.io.IOException

  Current version number from segments file.

  Throws:
    `CorruptIndexException` - if the index is corrupt
    `java.io.IOException` - if there is a low-level IO error

### readCurrentUserData

    public static java.util.Map readCurrentUserData(Directory directory)
                                             throws CorruptIndexException,
                                                    java.io.IOException

  Returns userData from latest segments file

  Throws:
    `CorruptIndexException` - if the index is corrupt
    `java.io.IOException` - if there is a low-level IO error

### setInfoStream

    public static void setInfoStream(java.io.PrintStream infoStream)

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

### setDefaultGenFileRetryCount

    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.

### getDefaultGenFileRetryCount

    public static int getDefaultGenFileRetryCount()

  See Also:
    `setDefaultGenFileRetryCount(int)`

### setDefaultGenFileRetryPauseMsec

    public static void setDefaultGenFileRetryPauseMsec(int msec)

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

### getDefaultGenFileRetryPauseMsec

    public static int getDefaultGenFileRetryPauseMsec()

  See Also:
    `setDefaultGenFileRetryPauseMsec(int)`

### setDefaultGenLookaheadCount

    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.

### getDefaultGenLookahedCount

    public static int getDefaultGenLookahedCount()

  See Also:
    `setDefaultGenLookaheadCount(int)`

### getInfoStream

    public static java.io.PrintStream getInfoStream()

  See Also:
    `setInfoStream(java.io.PrintStream)`

### range

    public SegmentInfos range(int first,
                              int last)

  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.

### files

    public java.util.Collection files(Directory dir,
                                      boolean includeSegmentsFile)
                               throws java.io.IOException

  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:
    `java.io.IOException`

### segString

    public java.lang.String segString(Directory directory)

### getUserData

    public java.util.Map getUserData()

### hasExternalSegments

    public boolean hasExternalSegments(Directory dir)

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.