Package org.apache.lucene.index
Class IndexFileNames
- java.lang.Object
-
- org.apache.lucene.index.IndexFileNames
-
public final class IndexFileNames extends java.lang.ObjectThis class contains useful constants representing filenames and extensions used by lucene, as well as convenience methods for querying whether a file name matches an extension (matchesExtension), as well as generating file names from a segment name, generation and extension (fileNameFromGeneration,segmentFileName).NOTE: extensions used by codecs are not listed here. You must interact with the
Codecdirectly.
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.PatternCODEC_FILE_PATTERNAll files created by codecs much match this pattern (checked in SegmentInfo).static java.lang.StringCOMPOUND_FILE_ENTRIES_EXTENSIONExtension of compound file entriesstatic java.lang.StringCOMPOUND_FILE_EXTENSIONExtension of compound filestatic java.lang.StringGEN_EXTENSIONExtension of gen filestatic java.lang.String[]INDEX_EXTENSIONSThis array contains all filename extensions used by Lucene's index files, with one exception, namely the extension made up from.s+ a number.static java.lang.StringSEGMENTSName of the index segment filestatic java.lang.StringSEGMENTS_GENName of the generation reference file name
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringfileNameFromGeneration(java.lang.String base, java.lang.String ext, long gen)Computes the full file name from base, extension and generation.static booleanmatchesExtension(java.lang.String filename, java.lang.String ext)Returns true if the given filename ends with the given extension.static java.lang.StringparseSegmentName(java.lang.String filename)Parses the segment name out of the given file name.static java.lang.StringsegmentFileName(java.lang.String segmentName, java.lang.String segmentSuffix, java.lang.String ext)Returns a file name that includes the given segment name, your own custom name and extension.static java.lang.StringstripExtension(java.lang.String filename)Removes the extension (anything after the first '.'), otherwise returns the original filename.static java.lang.StringstripSegmentName(java.lang.String filename)Strips the segment name out of the given file name.
-
-
-
Field Detail
-
SEGMENTS
public static final java.lang.String SEGMENTS
Name of the index segment file- See Also:
- Constant Field Values
-
GEN_EXTENSION
public static final java.lang.String GEN_EXTENSION
Extension of gen file- See Also:
- Constant Field Values
-
SEGMENTS_GEN
public static final java.lang.String SEGMENTS_GEN
Name of the generation reference file name- See Also:
- Constant Field Values
-
COMPOUND_FILE_EXTENSION
public static final java.lang.String COMPOUND_FILE_EXTENSION
Extension of compound file- See Also:
- Constant Field Values
-
COMPOUND_FILE_ENTRIES_EXTENSION
public static final java.lang.String COMPOUND_FILE_ENTRIES_EXTENSION
Extension of compound file entries- See Also:
- Constant Field Values
-
INDEX_EXTENSIONS
public static final java.lang.String[] INDEX_EXTENSIONS
This array contains all filename extensions used by Lucene's index files, with one exception, namely the extension made up from.s+ a number. Also note that Lucene'ssegments_Nfiles do not have any filename extension.
-
CODEC_FILE_PATTERN
public static final java.util.regex.Pattern CODEC_FILE_PATTERN
All files created by codecs much match this pattern (checked in SegmentInfo).
-
-
Method Detail
-
fileNameFromGeneration
public static java.lang.String fileNameFromGeneration(java.lang.String base, java.lang.String ext, long gen)Computes the full file name from base, extension and generation. If the generation is -1, the file name is null. If it's 0, the file name is <base>.<ext>. If it's > 0, the file name is <base>_<gen>.<ext>.
NOTE: .<ext> is added to the name only ifextis not an empty string.- Parameters:
base- main part of the file nameext- extension of the filenamegen- generation
-
segmentFileName
public static java.lang.String segmentFileName(java.lang.String segmentName, java.lang.String segmentSuffix, java.lang.String ext)Returns a file name that includes the given segment name, your own custom name and extension. The format of the filename is: <segmentName>(_<name>)(.<ext>).NOTE: .<ext> is added to the result file name only if
extis not empty.NOTE: _<segmentSuffix> is added to the result file name only if it's not the empty string
NOTE: all custom files should be named using this method, or otherwise some structures may fail to handle them properly (such as if they are added to compound files).
-
matchesExtension
public static boolean matchesExtension(java.lang.String filename, java.lang.String ext)Returns true if the given filename ends with the given extension. One should provide a pure extension, without '.'.
-
stripSegmentName
public static java.lang.String stripSegmentName(java.lang.String filename)
Strips the segment name out of the given file name. If you usedsegmentFileName(java.lang.String, java.lang.String, java.lang.String)orfileNameFromGeneration(java.lang.String, java.lang.String, long)to create your files, then this method simply removes whatever comes before the first '.', or the second '_' (excluding both).- Returns:
- the filename with the segment name removed, or the given filename if it does not contain a '.' and '_'.
-
parseSegmentName
public static java.lang.String parseSegmentName(java.lang.String filename)
Parses the segment name out of the given file name.- Returns:
- the segment name only, or filename if it does not contain a '.' and '_'.
-
stripExtension
public static java.lang.String stripExtension(java.lang.String filename)
Removes the extension (anything after the first '.'), otherwise returns the original filename.
-
-