public final class IndexUtils extends Object
This is for internal uses, DO NOT call from UI components or applications.
Modifier and Type | Method and Description |
---|---|
static CheckIndex.Status |
checkIndex(Directory dir,
PrintStream ps)
Check the index status.
|
static void |
close(Directory dir)
Close index directory.
|
static void |
close(IndexReader reader)
Close index reader.
|
static Map<String,Long> |
countTerms(IndexReader reader,
Collection<String> fields)
Collect all terms and their counts in the specified fields.
|
static IndexWriter |
createWriter(Directory dir,
Analyzer analyzer,
boolean useCompound,
boolean keepAllCommits)
Create an index writer.
|
static IndexWriter |
createWriter(Directory dir,
Analyzer analyzer,
boolean useCompound,
boolean keepAllCommits,
PrintStream ps)
Create an index writer.
|
static BinaryDocValues |
getBinaryDocValues(IndexReader reader,
String field)
Returns the
BinaryDocValues for the specified field. |
static String |
getCommitUserData(IndexCommit ic)
Returns user data written with the specified commit.
|
static FieldInfo |
getFieldInfo(IndexReader reader,
String fieldName)
Returns the
FieldInfo referenced by the field. |
static FieldInfos |
getFieldInfos(IndexReader reader)
Returns field
FieldInfos in the index. |
static Collection<String> |
getFieldNames(IndexReader reader)
Returns all field names in the index.
|
static String |
getIndexFormat(Directory dir)
Returns the string representation for Lucene codec version when the index was written.
|
static Bits |
getLiveDocs(IndexReader reader)
Returns the
Bits representing live documents in the index. |
static NumericDocValues |
getNumericDocValues(IndexReader reader,
String field)
Returns the
NumericDocValues for the specified field. |
static SortedDocValues |
getSortedDocValues(IndexReader reader,
String field)
Returns the
SortedDocValues for the specified field. |
static SortedNumericDocValues |
getSortedNumericDocValues(IndexReader reader,
String field)
Returns the
SortedNumericDocValues for the specified field. |
static SortedSetDocValues |
getSortedSetDocvalues(IndexReader reader,
String field)
Returns the
SortedSetDocValues for the specified field. |
static Terms |
getTerms(IndexReader reader,
String field)
Returns the
Terms for the specified field. |
static Directory |
openDirectory(String dirPath,
String dirImpl)
Opens an index directory for given index path.
|
static IndexReader |
openIndex(String indexPath,
String dirImpl)
Opens index(es) reader for given index path.
|
static void |
optimizeIndex(IndexWriter writer,
boolean expunge,
int maxNumSegments)
Execute force merge with the index writer.
|
static void |
tryRepairIndex(Directory dir,
CheckIndex.Status st,
PrintStream ps)
Try to repair the corrupted index using previously returned index status.
|
public static IndexReader openIndex(String indexPath, String dirImpl) throws Exception
indexPath
- - path to the index directorydirImpl
- - class name for the specific directory implementationException
- - if there is a low level IO error.public static Directory openDirectory(String dirPath, String dirImpl) throws IOException
This can be used to open/repair corrupted indexes.
dirPath
- - index directory pathdirImpl
- - class name for the specific directory implementationIOException
- - if there is a low level IO error.public static void close(Directory dir)
dir
- - index directory to be closedpublic static void close(IndexReader reader)
reader
- - index reader to be closedpublic static IndexWriter createWriter(Directory dir, Analyzer analyzer, boolean useCompound, boolean keepAllCommits) throws IOException
dir
- - index directoryanalyzer
- - analyzer used by the index writeruseCompound
- - if true, compound index files are usedkeepAllCommits
- - if true, all commit generations are keptIOException
- - if there is a low level IO error.public static IndexWriter createWriter(Directory dir, Analyzer analyzer, boolean useCompound, boolean keepAllCommits, PrintStream ps) throws IOException
dir
- - index directoryanalyzer
- - analyser used by the index writeruseCompound
- - if true, compound index files are usedkeepAllCommits
- - if true, all commit generations are keptps
- - information streamIOException
- - if there is a low level IO error.public static void optimizeIndex(IndexWriter writer, boolean expunge, int maxNumSegments) throws IOException
writer
- - index writerexpunge
- - if true, only segments having deleted documents are mergedmaxNumSegments
- - max number of segmentsIOException
- - if there is a low level IO error.public static CheckIndex.Status checkIndex(Directory dir, PrintStream ps) throws IOException
dir
- - index directory for checkingps
- - information streamIOException
- - if there is a low level IO error.public static void tryRepairIndex(Directory dir, CheckIndex.Status st, PrintStream ps) throws IOException
dir
- - index directory for repairingst
- - index statusps
- - information streamIOException
- - if there is a low level IO error.public static String getIndexFormat(Directory dir) throws IOException
dir
- - index directoryIOException
- - if there is a low level IO error.public static String getCommitUserData(IndexCommit ic) throws IOException
ic
- - index commitIOException
- - if there is a low level IO error.public static Map<String,Long> countTerms(IndexReader reader, Collection<String> fields) throws IOException
reader
- - index readerfields
- - field namesIOException
- - if there is a low level IO error.public static Bits getLiveDocs(IndexReader reader)
Bits
representing live documents in the index.reader
- - index readerpublic static FieldInfos getFieldInfos(IndexReader reader)
FieldInfos
in the index.reader
- - index readerpublic static FieldInfo getFieldInfo(IndexReader reader, String fieldName)
FieldInfo
referenced by the field.reader
- - index readerfieldName
- - field namepublic static Collection<String> getFieldNames(IndexReader reader)
reader
- - index readerpublic static Terms getTerms(IndexReader reader, String field) throws IOException
Terms
for the specified field.reader
- - index readerfield
- - field nameIOException
- - if there is a low level IO error.public static BinaryDocValues getBinaryDocValues(IndexReader reader, String field) throws IOException
BinaryDocValues
for the specified field.reader
- - index readerfield
- - field nameIOException
- - if there is a low level IO error.public static NumericDocValues getNumericDocValues(IndexReader reader, String field) throws IOException
NumericDocValues
for the specified field.reader
- - index readerfield
- - field nameIOException
- - if there is a low level IO error.public static SortedNumericDocValues getSortedNumericDocValues(IndexReader reader, String field) throws IOException
SortedNumericDocValues
for the specified field.reader
- - index readerfield
- - field nameIOException
- - if there is a low level IO error.public static SortedDocValues getSortedDocValues(IndexReader reader, String field) throws IOException
SortedDocValues
for the specified field.reader
- - index readerfield
- - field nameIOException
- - if there is a low level IO error.public static SortedSetDocValues getSortedSetDocvalues(IndexReader reader, String field) throws IOException
SortedSetDocValues
for the specified field.reader
- - index readerfield
- - field nameIOException
- - if there is a low level IO error.Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.