Class IndexUtils
- java.lang.Object
-
- org.apache.lucene.luke.models.util.IndexUtils
-
public final class IndexUtils extends Object
Utilities for various raw index operations.This is for internal uses, DO NOT call from UI components or applications.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CheckIndex.Status
checkIndex(Directory dir, PrintStream ps)
Check the index status.static void
close(IndexReader reader)
Close index reader.static void
close(Directory dir)
Close index directory.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 theBinaryDocValues
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 theFieldInfo
referenced by the field.static FieldInfos
getFieldInfos(IndexReader reader)
Returns fieldFieldInfos
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 theBits
representing live documents in the index.static NumericDocValues
getNumericDocValues(IndexReader reader, String field)
Returns theNumericDocValues
for the specified field.static SortedDocValues
getSortedDocValues(IndexReader reader, String field)
Returns theSortedDocValues
for the specified field.static SortedNumericDocValues
getSortedNumericDocValues(IndexReader reader, String field)
Returns theSortedNumericDocValues
for the specified field.static SortedSetDocValues
getSortedSetDocvalues(IndexReader reader, String field)
Returns theSortedSetDocValues
for the specified field.static Terms
getTerms(IndexReader reader, String field)
Returns theTerms
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.
-
-
-
Method Detail
-
openIndex
public static IndexReader openIndex(String indexPath, String dirImpl) throws Exception
Opens index(es) reader for given index path.- Parameters:
indexPath
- - path to the index directorydirImpl
- - class name for the specific directory implementation- Returns:
- index reader
- Throws:
Exception
- - if there is a low level IO error.
-
openDirectory
public static Directory openDirectory(String dirPath, String dirImpl) throws IOException
Opens an index directory for given index path.This can be used to open/repair corrupted indexes.
- Parameters:
dirPath
- - index directory pathdirImpl
- - class name for the specific directory implementation- Returns:
- directory
- Throws:
IOException
- - if there is a low level IO error.
-
close
public static void close(Directory dir)
Close index directory.- Parameters:
dir
- - index directory to be closed
-
close
public static void close(IndexReader reader)
Close index reader.- Parameters:
reader
- - index reader to be closed
-
createWriter
public static IndexWriter createWriter(Directory dir, Analyzer analyzer, boolean useCompound, boolean keepAllCommits) throws IOException
Create an index writer.- Parameters:
dir
- - index directoryanalyzer
- - analyzer used by the index writeruseCompound
- - if true, compound index files are usedkeepAllCommits
- - if true, all commit generations are kept- Returns:
- new index writer
- Throws:
IOException
- - if there is a low level IO error.
-
createWriter
public static IndexWriter createWriter(Directory dir, Analyzer analyzer, boolean useCompound, boolean keepAllCommits, PrintStream ps) throws IOException
Create an index writer.- Parameters:
dir
- - index directoryanalyzer
- - analyser used by the index writeruseCompound
- - if true, compound index files are usedkeepAllCommits
- - if true, all commit generations are keptps
- - information stream- Returns:
- new index writer
- Throws:
IOException
- - if there is a low level IO error.
-
optimizeIndex
public static void optimizeIndex(IndexWriter writer, boolean expunge, int maxNumSegments) throws IOException
Execute force merge with the index writer.- Parameters:
writer
- - index writerexpunge
- - if true, only segments having deleted documents are mergedmaxNumSegments
- - max number of segments- Throws:
IOException
- - if there is a low level IO error.
-
checkIndex
public static CheckIndex.Status checkIndex(Directory dir, PrintStream ps) throws IOException
Check the index status.- Parameters:
dir
- - index directory for checkingps
- - information stream- Returns:
- - index status
- Throws:
IOException
- - if there is a low level IO error.
-
tryRepairIndex
public static void tryRepairIndex(Directory dir, CheckIndex.Status st, PrintStream ps) throws IOException
Try to repair the corrupted index using previously returned index status.- Parameters:
dir
- - index directory for repairingst
- - index statusps
- - information stream- Throws:
IOException
- - if there is a low level IO error.
-
getIndexFormat
public static String getIndexFormat(Directory dir) throws IOException
Returns the string representation for Lucene codec version when the index was written.- Parameters:
dir
- - index directory- Throws:
IOException
- - if there is a low level IO error.
-
getCommitUserData
public static String getCommitUserData(IndexCommit ic) throws IOException
Returns user data written with the specified commit.- Parameters:
ic
- - index commit- Throws:
IOException
- - if there is a low level IO error.
-
countTerms
public static Map<String,Long> countTerms(IndexReader reader, Collection<String> fields) throws IOException
Collect all terms and their counts in the specified fields.- Parameters:
reader
- - index readerfields
- - field names- Returns:
- a map contains terms and their occurrence frequencies
- Throws:
IOException
- - if there is a low level IO error.
-
getLiveDocs
public static Bits getLiveDocs(IndexReader reader)
Returns theBits
representing live documents in the index.- Parameters:
reader
- - index reader
-
getFieldInfos
public static FieldInfos getFieldInfos(IndexReader reader)
Returns fieldFieldInfos
in the index.- Parameters:
reader
- - index reader
-
getFieldInfo
public static FieldInfo getFieldInfo(IndexReader reader, String fieldName)
Returns theFieldInfo
referenced by the field.- Parameters:
reader
- - index readerfieldName
- - field name
-
getFieldNames
public static Collection<String> getFieldNames(IndexReader reader)
Returns all field names in the index.- Parameters:
reader
- - index reader
-
getTerms
public static Terms getTerms(IndexReader reader, String field) throws IOException
Returns theTerms
for the specified field.- Parameters:
reader
- - index readerfield
- - field name- Throws:
IOException
- - if there is a low level IO error.
-
getBinaryDocValues
public static BinaryDocValues getBinaryDocValues(IndexReader reader, String field) throws IOException
Returns theBinaryDocValues
for the specified field.- Parameters:
reader
- - index readerfield
- - field name- Throws:
IOException
- - if there is a low level IO error.
-
getNumericDocValues
public static NumericDocValues getNumericDocValues(IndexReader reader, String field) throws IOException
Returns theNumericDocValues
for the specified field.- Parameters:
reader
- - index readerfield
- - field name- Throws:
IOException
- - if there is a low level IO error.
-
getSortedNumericDocValues
public static SortedNumericDocValues getSortedNumericDocValues(IndexReader reader, String field) throws IOException
Returns theSortedNumericDocValues
for the specified field.- Parameters:
reader
- - index readerfield
- - field name- Throws:
IOException
- - if there is a low level IO error.
-
getSortedDocValues
public static SortedDocValues getSortedDocValues(IndexReader reader, String field) throws IOException
Returns theSortedDocValues
for the specified field.- Parameters:
reader
- - index readerfield
- - field name- Throws:
IOException
- - if there is a low level IO error.
-
getSortedSetDocvalues
public static SortedSetDocValues getSortedSetDocvalues(IndexReader reader, String field) throws IOException
Returns theSortedSetDocValues
for the specified field.- Parameters:
reader
- - index readerfield
- - field name- Throws:
IOException
- - if there is a low level IO error.
-
-