Class SegmentInfo


  • public final class SegmentInfo
    extends java.lang.Object
    Information about a segment such as its name, directory, and files related to the segment.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.String> attributes  
      private Codec codec  
      private java.util.Map<java.lang.String,​java.lang.String> diagnostics  
      Directory dir
      Where this segment resides.
      private byte[] id
      Id that uniquely identifies this segment.
      private Sort indexSort  
      private boolean isCompoundFile  
      private int maxDoc  
      (package private) Version minVersion  
      java.lang.String name
      Unique segment name in the directory.
      static int NO
      Used by some member fields to mean not present (e.g., norms, deletions).
      private java.util.Set<java.lang.String> setFiles  
      private Version version  
      static int YES
      Used by some member fields to mean present (e.g., norms, deletions).
    • Constructor Summary

      Constructors 
      Constructor Description
      SegmentInfo​(Directory dir, Version version, Version minVersion, java.lang.String name, int maxDoc, boolean isCompoundFile, Codec codec, java.util.Map<java.lang.String,​java.lang.String> diagnostics, byte[] id, java.util.Map<java.lang.String,​java.lang.String> attributes, Sort indexSort)
      Construct a new complete SegmentInfo instance from input.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFile​(java.lang.String file)
      Add this file to the set of files written for this segment.
      void addFiles​(java.util.Collection<java.lang.String> files)
      Add these files to the set of files written for this segment.
      private void checkFileNames​(java.util.Collection<java.lang.String> files)  
      boolean equals​(java.lang.Object obj)
      We consider another SegmentInfo instance equal if it has the same dir and same name.
      java.util.Set<java.lang.String> files()
      Return all files referenced by this SegmentInfo.
      java.lang.String getAttribute​(java.lang.String key)
      Get a codec attribute value, or null if it does not exist
      java.util.Map<java.lang.String,​java.lang.String> getAttributes()
      Returns the internal codec attributes map.
      Codec getCodec()
      Return Codec that wrote this segment.
      java.util.Map<java.lang.String,​java.lang.String> getDiagnostics()
      Returns diagnostics saved into the segment when it was written.
      byte[] getId()
      Return the id that uniquely identifies this segment.
      Sort getIndexSort()
      Return the sort order of this segment, or null if the index has no sort.
      Version getMinVersion()
      Return the minimum Lucene version that contributed documents to this segment, or null if it is unknown.
      boolean getUseCompoundFile()
      Returns true if this segment is stored as a compound file; else, false.
      Version getVersion()
      Returns the version of the code which wrote the segment.
      int hashCode()  
      int maxDoc()
      Returns number of documents in this segment (deletions are not taken into account).
      (package private) java.lang.String namedForThisSegment​(java.lang.String file)
      strips any segment name from the file, naming it with this segment this is because "segment names" can change, e.g.
      java.lang.String putAttribute​(java.lang.String key, java.lang.String value)
      Puts a codec attribute value.
      void setCodec​(Codec codec)
      Can only be called once.
      (package private) void setDiagnostics​(java.util.Map<java.lang.String,​java.lang.String> diagnostics)  
      void setFiles​(java.util.Collection<java.lang.String> files)
      Sets the files written for this segment.
      (package private) void setMaxDoc​(int maxDoc)  
      (package private) void setUseCompoundFile​(boolean isCompoundFile)
      Mark whether this segment is stored as a compound file.
      java.lang.String toString()  
      java.lang.String toString​(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 java.lang.String name
        Unique segment name in the directory.
      • maxDoc

        private int maxDoc
      • dir

        public final Directory dir
        Where this segment resides.
      • isCompoundFile

        private boolean isCompoundFile
      • id

        private final byte[] id
        Id that uniquely identifies this segment.
      • codec

        private Codec codec
      • diagnostics

        private java.util.Map<java.lang.String,​java.lang.String> diagnostics
      • attributes

        private java.util.Map<java.lang.String,​java.lang.String> attributes
      • indexSort

        private final Sort indexSort
      • version

        private final Version version
      • setFiles

        private java.util.Set<java.lang.String> setFiles
    • Constructor Detail

      • SegmentInfo

        public SegmentInfo​(Directory dir,
                           Version version,
                           Version minVersion,
                           java.lang.String name,
                           int maxDoc,
                           boolean isCompoundFile,
                           Codec codec,
                           java.util.Map<java.lang.String,​java.lang.String> diagnostics,
                           byte[] id,
                           java.util.Map<java.lang.String,​java.lang.String> attributes,
                           Sort indexSort)
        Construct a new complete SegmentInfo instance from input.

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

    • Method Detail

      • setDiagnostics

        void setDiagnostics​(java.util.Map<java.lang.String,​java.lang.String> diagnostics)
      • getDiagnostics

        public java.util.Map<java.lang.String,​java.lang.String> getDiagnostics()
        Returns diagnostics saved into the segment when it was written. The map is immutable.
      • setUseCompoundFile

        void setUseCompoundFile​(boolean isCompoundFile)
        Mark whether this segment is stored as a compound file.
        Parameters:
        isCompoundFile - true if this is a compound file; else, false
      • 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.
      • maxDoc

        public int maxDoc()
        Returns number of documents in this segment (deletions are not taken into account).
      • setMaxDoc

        void setMaxDoc​(int maxDoc)
      • files

        public java.util.Set<java.lang.String> files()
        Return all files referenced by this SegmentInfo.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(int delCount)
        Used for debugging. Format may suddenly change.

        Current format looks like _a(3.1):c45/4:[sorter=<long: "timestamp">!], 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); it is sorted by the timestamp field in descending order (this part is omitted for unsorted segments).

      • equals

        public boolean equals​(java.lang.Object obj)
        We consider another SegmentInfo instance equal if it has the same dir and same name.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getVersion

        public Version getVersion()
        Returns the version of the code which wrote the segment.
      • getMinVersion

        public Version getMinVersion()
        Return the minimum Lucene version that contributed documents to this segment, or null if it is unknown.
      • getId

        public byte[] getId()
        Return the id that uniquely identifies this segment.
      • setFiles

        public void setFiles​(java.util.Collection<java.lang.String> files)
        Sets the files written for this segment.
      • addFiles

        public void addFiles​(java.util.Collection<java.lang.String> files)
        Add these files to the set of files written for this segment.
      • addFile

        public void addFile​(java.lang.String file)
        Add this file to the set of files written for this segment.
      • checkFileNames

        private void checkFileNames​(java.util.Collection<java.lang.String> files)
      • namedForThisSegment

        java.lang.String namedForThisSegment​(java.lang.String file)
        strips any segment name from the file, naming it with this segment this is because "segment names" can change, e.g. by addIndexes(Dir)
      • getAttribute

        public java.lang.String getAttribute​(java.lang.String key)
        Get a codec attribute value, or null if it does not exist
      • putAttribute

        public java.lang.String putAttribute​(java.lang.String key,
                                             java.lang.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. This method make a copy on write for every attribute change.

      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.String> getAttributes()
        Returns the internal codec attributes map.
        Returns:
        internal codec attributes map.
      • getIndexSort

        public Sort getIndexSort()
        Return the sort order of this segment, or null if the index has no sort.