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.StatuscheckIndex(Directory dir, PrintStream ps)Check the index status.static voidclose(IndexReader reader)Close index reader.static voidclose(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 IndexWritercreateWriter(Directory dir, Analyzer analyzer, boolean useCompound, boolean keepAllCommits)Create an index writer.static IndexWritercreateWriter(Directory dir, Analyzer analyzer, boolean useCompound, boolean keepAllCommits, PrintStream ps)Create an index writer.static BinaryDocValuesgetBinaryDocValues(IndexReader reader, String field)Returns theBinaryDocValuesfor the specified field.static StringgetCommitUserData(IndexCommit ic)Returns user data written with the specified commit.static FieldInfogetFieldInfo(IndexReader reader, String fieldName)Returns theFieldInforeferenced by the field.static FieldInfosgetFieldInfos(IndexReader reader)Returns fieldFieldInfosin the index.static Collection<String>getFieldNames(IndexReader reader)Returns all field names in the index.static StringgetIndexFormat(Directory dir)Returns the string representation for Lucene codec version when the index was written.static BitsgetLiveDocs(IndexReader reader)Returns theBitsrepresenting live documents in the index.static NumericDocValuesgetNumericDocValues(IndexReader reader, String field)Returns theNumericDocValuesfor the specified field.static SortedDocValuesgetSortedDocValues(IndexReader reader, String field)Returns theSortedDocValuesfor the specified field.static SortedNumericDocValuesgetSortedNumericDocValues(IndexReader reader, String field)Returns theSortedNumericDocValuesfor the specified field.static SortedSetDocValuesgetSortedSetDocvalues(IndexReader reader, String field)Returns theSortedSetDocValuesfor the specified field.static TermsgetTerms(IndexReader reader, String field)Returns theTermsfor the specified field.static DirectoryopenDirectory(String dirPath, String dirImpl)Opens an index directory for given index path.static IndexReaderopenIndex(String indexPath, String dirImpl)Opens index(es) reader for given index path.static voidoptimizeIndex(IndexWriter writer, boolean expunge, int maxNumSegments)Execute force merge with the index writer.static voidtryRepairIndex(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 theBitsrepresenting live documents in the index.- Parameters:
reader- - index reader
-
getFieldInfos
public static FieldInfos getFieldInfos(IndexReader reader)
Returns fieldFieldInfosin the index.- Parameters:
reader- - index reader
-
getFieldInfo
public static FieldInfo getFieldInfo(IndexReader reader, String fieldName)
Returns theFieldInforeferenced 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 theTermsfor 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 theBinaryDocValuesfor 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 theNumericDocValuesfor 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 theSortedNumericDocValuesfor 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 theSortedDocValuesfor 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 theSortedSetDocValuesfor the specified field.- Parameters:
reader- - index readerfield- - field name- Throws:
IOException- - if there is a low level IO error.
-
-