org.apache.lucene.luke.models.util

## 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 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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 directory
        `dirImpl` - - 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 path
        `dirImpl` - - 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 directory
        `analyzer` - - analyzer used by the index writer
        `useCompound` - - if true, compound index files are used
        `keepAllCommits` - - 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 directory
        `analyzer` - - analyser used by the index writer
        `useCompound` - - if true, compound index files are used
        `keepAllCommits` - - if true, all commit generations are kept
        `ps` - - 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 writer
        `expunge` - - if true, only segments having deleted documents are merged
        `maxNumSegments` - - 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 checking
        `ps` - - 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 repairing
        `st` - - index status
        `ps` - - 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 reader
        `fields` - - 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 the `Bits` representing live documents in the index.
      Parameters:
        `reader` - - index reader

    - #### getFieldInfos

          public static FieldInfos getFieldInfos(IndexReader reader)

      Returns field `FieldInfos` in the index.
      Parameters:
        `reader` - - index reader

    - #### getFieldInfo

          public static FieldInfo getFieldInfo(IndexReader reader,
                                               String fieldName)

      Returns the `FieldInfo` referenced by the field.
      Parameters:
        `reader` - - index reader
        `fieldName` - - 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 the `Terms` for the specified field.
      Parameters:
        `reader` - - index reader
        `field` - - field name
      Throws:
        `IOException` - - if there is a low level IO error.

    - #### getBinaryDocValues

          public static BinaryDocValues getBinaryDocValues(IndexReader reader,
                                                           String field)
                                                    throws IOException

      Returns the `BinaryDocValues` for the specified field.
      Parameters:
        `reader` - - index reader
        `field` - - field name
      Throws:
        `IOException` - - if there is a low level IO error.

    - #### getNumericDocValues

          public static NumericDocValues getNumericDocValues(IndexReader reader,
                                                             String field)
                                                      throws IOException

      Returns the `NumericDocValues` for the specified field.
      Parameters:
        `reader` - - index reader
        `field` - - field name
      Throws:
        `IOException` - - if there is a low level IO error.

    - #### getSortedNumericDocValues

          public static SortedNumericDocValues getSortedNumericDocValues(IndexReader reader,
                                                                         String field)
                                                                  throws IOException

      Returns the `SortedNumericDocValues` for the specified field.
      Parameters:
        `reader` - - index reader
        `field` - - field name
      Throws:
        `IOException` - - if there is a low level IO error.

    - #### getSortedDocValues

          public static SortedDocValues getSortedDocValues(IndexReader reader,
                                                           String field)
                                                    throws IOException

      Returns the `SortedDocValues` for the specified field.
      Parameters:
        `reader` - - index reader
        `field` - - field name
      Throws:
        `IOException` - - if there is a low level IO error.

    - #### getSortedSetDocvalues

          public static SortedSetDocValues getSortedSetDocvalues(IndexReader reader,
                                                                 String field)
                                                          throws IOException

      Returns the `SortedSetDocValues` for the specified field.
      Parameters:
        `reader` - - index reader
        `field` - - field name
      Throws:
        `IOException` - - if there is a low level IO error.

Copyright © 2000-2024 Apache Software Foundation. All Rights Reserved.