Package org.apache.lucene.index
Class SegmentInfos
- java.lang.Object
-
- org.apache.lucene.index.SegmentInfos
-
- All Implemented Interfaces:
Cloneable,Iterable<SegmentInfo>
public final class SegmentInfos extends Object implements Cloneable, Iterable<SegmentInfo>
A collection of segmentInfo objects with methods for operating on those segments in relation to the file system.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSegmentInfos.FindSegmentsFileUtility class for executing code that needs to do something with the current segments file.
-
Field Summary
Fields Modifier and Type Field Description intcounterstatic intCURRENT_FORMATstatic intFORMATThe file format version, a negative number.static intFORMAT_3_1Each segment records the Lucene version that created it.static intFORMAT_CHECKSUMThis format adds a checksum at the end of the file to ensure all bytes were successfully written.static intFORMAT_DEL_COUNTThis format adds the deletion count for each segment.static intFORMAT_DIAGNOSTICSThis format adds optional per-segment String diagnostics storage, and switches userData to Mapstatic intFORMAT_HAS_PROXThis format adds the boolean hasProx to record if any fields in the segment store prox information (ie, have omitTermFreqAndPositions==false)static intFORMAT_HAS_VECTORSEach segment records whether it has term vectorsstatic intFORMAT_LOCKLESSThis format adds details used for lockless commits.static intFORMAT_MAXIMUMstatic intFORMAT_MINIMUMstatic intFORMAT_SHARED_DOC_STOREThis format allows multiple segments to share a single vectors and stored fields file.static intFORMAT_SINGLE_NORM_FILEThis format adds a "hasSingleNormFile" flag into each segment info.static intFORMAT_USER_DATAThis format adds optional commit userData (String) storage.
-
Constructor Summary
Constructors Constructor Description SegmentInfos()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(SegmentInfo si)voidaddAll(Iterable<SegmentInfo> sis)List<SegmentInfo>asList()Returns all contained segments as an unmodifiableListview.Set<SegmentInfo>asSet()Returns all contained segments as an unmodifiableSetview.voidchanged()Call this before committing if changes have been made to the segments.voidclear()Objectclone()Returns a copy of this instance, also copying each SegmentInfo.booleancontains(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 longgenerationFromSegmentsFileName(String fileName)Parse the generation off the segments file name and return it.static intgetDefaultGenLookahedCount()intgetFormat()longgetGeneration()static PrintStreamgetInfoStream()static longgetLastCommitGeneration(String[] files)Get the generation of the most recent commit to the list of index files (N in the segments_N file).static longgetLastCommitGeneration(Directory directory)Get the generation of the most recent commit to the index in this directory (N in the segments_N file).static StringgetLastCommitSegmentsFileName(String[] files)Get the filename of the segments_N file for the most recent commit in the list of index files.static StringgetLastCommitSegmentsFileName(Directory directory)Get the filename of the segments_N file for the most recent commit to the index in this Directory.longgetLastGeneration()StringgetNextSegmentFileName()Get the next segments_N filename that will be written.StringgetSegmentsFileName()Get the segments_N filename in use by this segment infos.Map<String,String>getUserData()longgetVersion()version number when this SegmentInfos was generated.intindexOf(SegmentInfo si)SegmentInfoinfo(int i)Iterator<SegmentInfo>iterator()Returns an unmodifiableIteratorof contained segments in order.voidpruneDeletedSegments()Prunes any segment whose docs are all deleted.SegmentInfosrange(int first, int last)Deprecated.useasList().subList(first, last)instead.voidread(Directory directory)This version of read uses the retry logic (for lock-less commits) to find the right segments file to load.voidread(Directory directory, String segmentFileName)Read a particular segmentFileName.static longreadCurrentVersion(Directory directory)Deprecated.Load the SegmentInfos and then callgetVersion().voidremove(int index)voidremove(SegmentInfo si)static voidsetDefaultGenLookaheadCount(int count)Advanced: set how many times to try incrementing the gen when loading the segments file.voidsetFormat(int format)static voidsetInfoStream(PrintStream infoStream)If non-null, information about retries when loading the segments file will be printed to this.intsize()StringtoString(Directory directory)inttotalDocCount()Returns sum of all segment's docCounts.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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
-
FORMAT_HAS_VECTORS
public static final int FORMAT_HAS_VECTORS
Each segment records whether it has term vectors- See Also:
- Constant Field Values
-
FORMAT_3_1
public static final int FORMAT_3_1
Each segment records the Lucene version that created it.- See Also:
- Constant Field Values
-
CURRENT_FORMAT
public static final int CURRENT_FORMAT
- See Also:
- Constant Field Values
-
FORMAT_MINIMUM
public static final int FORMAT_MINIMUM
- See Also:
- Constant Field Values
-
FORMAT_MAXIMUM
public static final int FORMAT_MAXIMUM
- See Also:
- Constant Field Values
-
counter
public int counter
-
-
Method Detail
-
setFormat
public void setFormat(int format)
-
getFormat
public int getFormat()
-
info
public SegmentInfo info(int i)
-
getLastCommitGeneration
public 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).- Parameters:
files- -- array of file names to check
-
getLastCommitGeneration
public static long getLastCommitGeneration(Directory directory) throws IOException
Get the generation of the most recent commit to the index in this directory (N in the segments_N file).- Parameters:
directory- -- directory to search for the latest segments_N file- Throws:
IOException
-
getLastCommitSegmentsFileName
public static String getLastCommitSegmentsFileName(String[] files) throws IOException
Get the filename of the segments_N file for the most recent commit in the list of index files.- Parameters:
files- -- array of file names to check- Throws:
IOException
-
getLastCommitSegmentsFileName
public static String getLastCommitSegmentsFileName(Directory directory) throws IOException
Get the filename of the segments_N file for the most recent commit to the index in this Directory.- Parameters:
directory- -- directory to search for the latest segments_N file- Throws:
IOException
-
getSegmentsFileName
public String getSegmentsFileName()
Get the segments_N filename in use by this segment infos.
-
generationFromSegmentsFileName
public static long generationFromSegmentsFileName(String fileName)
Parse the generation off the segments file name and return it.
-
getNextSegmentFileName
public String getNextSegmentFileName()
Get the next segments_N filename that will be written.
-
read
public final void read(Directory directory, String segmentFileName) throws CorruptIndexException, IOException
Read a particular segmentFileName. Note that this may throw an IOException if a commit is in process.- Parameters:
directory- -- directory containing the segments filesegmentFileName- -- segment file to load- Throws:
CorruptIndexException- if the index is corruptIOException- if there is a low-level IO error
-
read
public final void read(Directory directory) throws CorruptIndexException, 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 corruptIOException- if there is a low-level IO error
-
pruneDeletedSegments
public void pruneDeletedSegments() throws IOExceptionPrunes any segment whose docs are all deleted.- Throws:
IOException
-
clone
public Object clone()
Returns a copy of this instance, also copying each SegmentInfo.
-
getVersion
public long getVersion()
version number when this SegmentInfos was generated.
-
getGeneration
public long getGeneration()
-
getLastGeneration
public long getLastGeneration()
-
readCurrentVersion
@Deprecated public static long readCurrentVersion(Directory directory) throws CorruptIndexException, IOException
Deprecated.Load the SegmentInfos and then callgetVersion().Current version number from segments file.- Throws:
CorruptIndexException- if the index is corruptIOException- if there is a low-level IO error
-
setInfoStream
public static void setInfoStream(PrintStream infoStream)
If non-null, information about retries when loading the segments file will be printed to this.
-
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.- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
getDefaultGenLookahedCount
public static int getDefaultGenLookahedCount()
- See Also:
setDefaultGenLookaheadCount(int)- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
getInfoStream
public static PrintStream getInfoStream()
- See Also:
setInfoStream(java.io.PrintStream)
-
range
@Deprecated public SegmentInfos range(int first, int last)
Deprecated.useasList().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.
-
files
public Collection<String> files(Directory dir, boolean includeSegmentsFile) throws 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:
IOException
-
totalDocCount
public int totalDocCount()
Returns sum of all segment's docCounts. Note that this does not include deletions
-
changed
public void changed()
Call this before committing if changes have been made to the segments.
-
iterator
public Iterator<SegmentInfo> iterator()
Returns an unmodifiableIteratorof contained segments in order.- Specified by:
iteratorin interfaceIterable<SegmentInfo>
-
asList
public List<SegmentInfo> asList()
Returns all contained segments as an unmodifiableListview.
-
asSet
public Set<SegmentInfo> asSet()
Returns all contained segments as an unmodifiableSetview. The iterator is not sorted, useListview oriterator()to get all segments in order.
-
size
public int size()
-
add
public void add(SegmentInfo si)
-
addAll
public void addAll(Iterable<SegmentInfo> sis)
-
clear
public void clear()
-
remove
public void remove(SegmentInfo si)
-
remove
public void remove(int index)
-
contains
public boolean contains(SegmentInfo si)
-
indexOf
public int indexOf(SegmentInfo si)
-
-