org.apache.lucene.index

## Class SegmentInfo

- java.lang.Object
- - org.apache.lucene.index.SegmentInfo

-     public final class SegmentInfo
      extends Object

  Information about a segment such as it's name, directory, and files related to the segment.
  WARNING: This API is experimental and might change in incompatible ways in the next release.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `Directory` | `dir` Where this segment resides.
    `String` | `name` Unique segment name in the directory.
    `static int` | `NO` Used by some member fields to mean not present (e.g., norms, deletions).
    `static int` | `YES` Used by some member fields to mean present (e.g., norms, deletions).

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SegmentInfo(Directory dir, String version, String name, int docCount, boolean isCompoundFile, Codec codec, Map<String,String> diagnostics, Map<String,String> attributes)` Construct a new complete SegmentInfo instance from input.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addFile(String file)` Add this file to the set of files written for this segment.
    `void` | `addFiles(Collection<String> files)` Add these files to the set of files written for this segment.
    `Map<String,String>` | `attributes()` Returns the internal codec attributes map.
    `boolean` | `equals(Object obj)` We consider another SegmentInfo instance equal if it has the same dir and same name.
    `Set<String>` | `files()` Return all files referenced by this SegmentInfo.
    `String` | `getAttribute(String key)` Get a codec attribute value, or null if it does not exist
    `Codec` | `getCodec()` Return `Codec` that wrote this segment.
    `Map<String,String>` | `getDiagnostics()` Returns diagnostics saved into the segment when it was written.
    `int` | `getDocCount()` Returns number of documents in this segment (deletions are not taken into account).
    `boolean` | `getUseCompoundFile()` Returns true if this segment is stored as a compound file; else, false.
    `String` | `getVersion()` Returns the version of the code which wrote the segment.
    `int` | `hashCode()`
    `String` | `putAttribute(String key, String value)` Puts a codec attribute value.
    `void` | `setCodec(Codec codec)` Can only be called once.
    `void` | `setFiles(Set<String> files)` Sets the files written for this segment.
    `void` | `setVersion(String version)` Used by DefaultSegmentInfosReader to upgrade a 3.0 segment to record its version is "3.0".
    `String` | `toString()`
    `String` | `toString(Directory dir, int delCount)` Used for debugging.

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

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### NO

          public static final int NO

      Used by some member fields to mean not present (e.g., norms, deletions).
      See Also:
        Constant Field Values

    - #### YES

          public static final int YES

      Used by some member fields to mean present (e.g., norms, deletions).
      See Also:
        Constant Field Values

    - #### name

          public final String name

      Unique segment name in the directory.

    - #### dir

          public final Directory dir

      Where this segment resides.

  - ### Constructor Detail

    - #### SegmentInfo

          public SegmentInfo(Directory dir,
                     String version,
                     String name,
                     int docCount,
                     boolean isCompoundFile,
                     Codec codec,
                     Map<String,String> diagnostics,
                     Map<String,String> attributes)

      Construct a new complete SegmentInfo instance from input.

      Note: this is public only to allow access from the codecs package.

  - ### Method Detail

    - #### getDiagnostics

          public Map<String,String> getDiagnostics()

      Returns diagnostics saved into the segment when it was written.

    - #### getUseCompoundFile

          public boolean getUseCompoundFile()

      Returns true if this segment is stored as a compound file; else, false.

    - #### setCodec

          public void setCodec(Codec codec)

      Can only be called once.

    - #### getCodec

          public Codec getCodec()

      Return `Codec` that wrote this segment.

    - #### getDocCount

          public int getDocCount()

      Returns number of documents in this segment (deletions are not taken into account).

    - #### files

          public Set<String> files()

      Return all files referenced by this SegmentInfo.

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### toString

          public String toString(Directory dir,
                        int delCount)

      Used for debugging. Format may suddenly change.

      Current format looks like `_a(3.1):c45/4`, which means the segment's name is `_a`; it was created with Lucene 3.1 (or '?' if it's unknown); it's using compound file format (would be `C` if not compound); it has 45 documents; it has 4 deletions (this part is left off when there are no deletions).

    - #### equals

          public boolean equals(Object obj)

      We consider another SegmentInfo instance equal if it has the same dir and same name.
      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### setVersion

          public void setVersion(String version)

      Used by DefaultSegmentInfosReader to upgrade a 3.0 segment to record its version is "3.0". This method can be removed when we're not required to support 3x indexes anymore, e.g. in 5.0.

      NOTE: this method is used for internal purposes only - you should not modify the version of a SegmentInfo, or it may result in unexpected exceptions thrown when you attempt to open the index.

      NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

    - #### getVersion

          public String getVersion()

      Returns the version of the code which wrote the segment.

    - #### setFiles

          public void setFiles(Set<String> files)

      Sets the files written for this segment.

    - #### addFiles

          public void addFiles(Collection<String> files)

      Add these files to the set of files written for this segment.

    - #### addFile

          public void addFile(String file)

      Add this file to the set of files written for this segment.

    - #### getAttribute

          public String getAttribute(String key)

      Get a codec attribute value, or null if it does not exist

    - #### putAttribute

          public String putAttribute(String key,
                            String value)

      Puts a codec attribute value.

      This is a key-value mapping for the field that the codec can use to store additional metadata, and will be available to the codec when reading the segment via `getAttribute(String)`

      If a value already exists for the field, it will be replaced with the new value.

    - #### attributes

          public Map<String,String> attributes()

      Returns the internal codec attributes map.
      Returns:
        internal codec attributes map. May be null if no mappings exist.

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