|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.lucene.index.SegmentInfos
public final class SegmentInfos
A collection of segmentInfo objects with methods for operating on those segments in relation to the file system.
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 writer is in the process of committing, or a custom
IndexDeletionPolicy
is in use). This file lists each segment by name and has details about the
codec and generation of deletes.
There is also a file segments.gen. This file contains
the current generation (the _N in segments_N) of the index.
This is used only as a fallback in case the current generation cannot be
accurately determined by directory listing alone (as is the case for some NFS
clients with time-based directory cache expiration). This file simply contains
an Int32 version header
(FORMAT_SEGMENTS_GEN_CURRENT), followed by the
generation recorded as Int64, written twice.
Files:
CodecHeaderInt32Int64StringMap<String,String>
LiveDocsFormat.name of the Codec that encoded
this segment.IndexWriter.commit(java.util.Map)
or IndexWriter.prepareCommit(java.util.Map).
| 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
Used to name new segments. |
static int |
FORMAT_SEGMENTS_GEN_CURRENT
Used for the segments.gen file only! Whenever you add a new format, make it 1 smaller (negative version logic)! |
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 |
| Constructor Summary | |
|---|---|
SegmentInfos()
Sole constructor. |
|
| Method Summary | |
|---|---|
void |
add(SegmentInfoPerCommit si)
Appends the provided SegmentInfoPerCommit. |
void |
addAll(Iterable<SegmentInfoPerCommit> sis)
Appends the provided SegmentInfoPerCommits. |
List<SegmentInfoPerCommit> |
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 SegmentInfoPerCommits. |
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. |
static int |
getDefaultGenLookahedCount()
Returns the defaultGenLookaheadCount. |
long |
getGeneration()
Returns current generation. |
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 |
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()
Return userData saved with this commit. |
long |
getVersion()
version number when this SegmentInfos was generated. |
SegmentInfoPerCommit |
info(int i)
Returns SegmentInfoPerCommit at the provided
index. |
Iterator<SegmentInfoPerCommit> |
iterator()
Returns an unmodifiable Iterator of contained segments in order. |
void |
read(Directory directory)
Find the latest commit ( segments_N file) and
load all SegmentInfoPerCommits. |
void |
read(Directory directory,
String segmentFileName)
Read a particular segmentFileName. |
void |
remove(SegmentInfoPerCommit si)
Remove the provided SegmentInfoPerCommit. |
static void |
setDefaultGenLookaheadCount(int count)
Advanced: set how many times to try incrementing the gen when loading the segments file. |
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 SegmentInfoPerCommits. |
String |
toString(Directory directory)
Returns readable description of this segment. |
int |
totalDocCount()
Returns sum of all segment's docCounts. |
static String |
write3xInfo(Directory dir,
SegmentInfo si,
IOContext context)
Deprecated. |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int VERSION_40
public static final int FORMAT_SEGMENTS_GEN_CURRENT
public int counter
public long version
public Map<String,String> userData
| Constructor Detail |
|---|
public SegmentInfos()
or
#read(Directory,String) to populate each SegmentInfoPerCommit. Alternatively, you can add/remove your
own SegmentInfoPerCommits.
| Method Detail |
|---|
public SegmentInfoPerCommit info(int i)
SegmentInfoPerCommit at the provided
index.
public static long getLastCommitGeneration(String[] files)
files - -- array of file names to check
public static long getLastCommitGeneration(Directory directory)
throws IOException
directory - -- directory to search for the latest segments_N file
IOExceptionpublic static String getLastCommitSegmentsFileName(String[] files)
files - -- array of file names to check
public static String getLastCommitSegmentsFileName(Directory directory)
throws IOException
directory - -- directory to search for the latest segments_N file
IOExceptionpublic String getSegmentsFileName()
public static long generationFromSegmentsFileName(String fileName)
public String getNextSegmentFileName()
public final void read(Directory directory,
String segmentFileName)
throws IOException
directory - -- directory containing the segments filesegmentFileName - -- segment file to load
CorruptIndexException - if the index is corrupt
IOException - if there is a low-level IO error
public final void read(Directory directory)
throws IOException
segments_N file) and
load all SegmentInfoPerCommits.
IOException
@Deprecated
public static String write3xInfo(Directory dir,
SegmentInfo si,
IOContext context)
throws IOException
IOExceptionpublic SegmentInfos clone()
clone in class Objectpublic long getVersion()
public long getGeneration()
public long getLastGeneration()
public static void setInfoStream(PrintStream infoStream)
public static void setDefaultGenLookaheadCount(int count)
public static int getDefaultGenLookahedCount()
defaultGenLookaheadCount.
setDefaultGenLookaheadCount(int)public static PrintStream getInfoStream()
infoStream.
setInfoStream(java.io.PrintStream)
public Collection<String> files(Directory dir,
boolean includeSegmentsFile)
throws IOException
IOExceptionpublic String toString(Directory directory)
public Map<String,String> getUserData()
userData saved with this commit.
IndexWriter.commit(Map)public int totalDocCount()
public void changed()
public Iterator<SegmentInfoPerCommit> iterator()
Iterator of contained segments in order.
iterator in interface Iterable<SegmentInfoPerCommit>public List<SegmentInfoPerCommit> asList()
List view.
public int size()
SegmentInfoPerCommits.
public void add(SegmentInfoPerCommit si)
SegmentInfoPerCommit.
public void addAll(Iterable<SegmentInfoPerCommit> sis)
SegmentInfoPerCommits.
public void clear()
SegmentInfoPerCommits.
public void remove(SegmentInfoPerCommit si)
SegmentInfoPerCommit.
WARNING: O(N) cost
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||