Class IndexUtil


  • public class IndexUtil
    extends java.lang.Object
    Class with handy utilities for use on an Index.
    Since:
    3.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  IndexUtil.Command  
    • Constructor Summary

      Constructors 
      Constructor Description
      IndexUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void close​(java.lang.Object o)
      Check to see if an object is closeable, and if so, close it.
      static void configure​(Index index, java.lang.Object o)
      Configures an object with the index, if the object implements IndexConfigurable
      static boolean copyStructure​(IndexOnDisk sourceIndex, IndexOnDisk destIndex, java.lang.String sourceStructureName, java.lang.String destinationStructureName)
      Copies an index structure from one index to another.
      static void deleteIndex​(java.lang.String path, java.lang.String prefix)
      Delete an existing index
      static boolean deleteStructure​(IndexOnDisk index, java.lang.String structureName)
      Delete the named structure from the specified index.
      static void forceReloadStructure​(Index index, java.lang.String structureName)
      Forces a structure to be reloaded, by removing it from the index's structure cache
      static void forceStructure​(Index index, java.lang.String structureName, java.lang.Object structure)
      Force the specified object into the structure cache of the specified object, as the given structure name
      static int getFieldId​(Index index, java.lang.String structureName, java.lang.String fieldName)  
      static java.lang.String[] getStructures​(PropertiesIndex index)
      Returns a list of the structures in the given index
      static boolean isStructureOpen​(IndexOnDisk index, java.lang.String structureName)
      Checks the underlying structurecache of the specificed index to see if the named index structure is there.
      static void main​(java.lang.String[] args)
      Has some handy utilities for printing various index structures to System.out, such as: --printbitfile - print the bit file with the specified name --printbitentry - print one entry in a bit posting index. --printlex - print the entire lexicon --printdocument - print the document index --printlist - print the named list (e.g.
      static void printDocumentIndex​(Index index, java.lang.String structureName)
      Print the contents of the document index
      static void printMetaIndex​(Index index, java.lang.String structureName)
      Print the contents of the meta index
      static void printMetaIndexJson​(Index index, java.lang.String structureName)  
      static void renameIndex​(java.lang.String srcPath, java.lang.String srcPrefix, java.lang.String dstPath, java.lang.String dstPrefix)
      Move an index from one location to another
      static boolean renameIndexStructure​(Index _index, java.lang.String sourceStructureName, java.lang.String destinationStructureName)
      Rename a structure within a given index.
      static IndexOnDisk reOpenIndex​(Index index)  
      static IndexOnDisk reOpenIndex​(IndexOnDisk index)
      Reopen an existing index
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IndexUtil

        public IndexUtil()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
        Has some handy utilities for printing various index structures to System.out, such as:
        • --printbitfile - print the bit file with the specified name
        • --printbitentry - print one entry in a bit posting index.
        • --printlex - print the entire lexicon
        • --printdocument - print the document index
        • --printlist - print the named list (e.g. document index)
        • --printmeta - print the meta index
        See bin/terrier help indexutils for more
      • forceStructure

        public static void forceStructure​(Index index,
                                          java.lang.String structureName,
                                          java.lang.Object structure)
        Force the specified object into the structure cache of the specified object, as the given structure name
        Parameters:
        index - Index to operate on
        structureName - which structure name to use
        structure - which object to put into the structure cache
      • forceReloadStructure

        public static void forceReloadStructure​(Index index,
                                                java.lang.String structureName)
        Forces a structure to be reloaded, by removing it from the index's structure cache
      • reOpenIndex

        public static IndexOnDisk reOpenIndex​(Index index)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • reOpenIndex

        public static IndexOnDisk reOpenIndex​(IndexOnDisk index)
                                       throws java.io.IOException
        Reopen an existing index
        Throws:
        java.io.IOException
      • getStructures

        public static java.lang.String[] getStructures​(PropertiesIndex index)
        Returns a list of the structures in the given index
      • renameIndex

        public static void renameIndex​(java.lang.String srcPath,
                                       java.lang.String srcPrefix,
                                       java.lang.String dstPath,
                                       java.lang.String dstPrefix)
                                throws java.io.IOException
        Move an index from one location to another
        Throws:
        java.io.IOException
      • deleteIndex

        public static void deleteIndex​(java.lang.String path,
                                       java.lang.String prefix)
                                throws java.io.IOException
        Delete an existing index
        Throws:
        java.io.IOException
      • printDocumentIndex

        public static void printDocumentIndex​(Index index,
                                              java.lang.String structureName)
                                       throws java.io.IOException
        Print the contents of the document index
        Throws:
        java.io.IOException
      • deleteStructure

        public static boolean deleteStructure​(IndexOnDisk index,
                                              java.lang.String structureName)
                                       throws java.io.IOException
        Delete the named structure from the specified index. Deletes files as well.
        Parameters:
        index - - index to operate on
        structureName - name of structure to delete
        Returns:
        true if structure was found and deleted, false otherwise
        Throws:
        java.io.IOException
      • isStructureOpen

        public static boolean isStructureOpen​(IndexOnDisk index,
                                              java.lang.String structureName)
        Checks the underlying structurecache of the specificed index to see if the named index structure is there.
        Parameters:
        index - index to examine
        structureName - what structure
        Returns:
        true if the structure cache contains the item
      • copyStructure

        public static boolean copyStructure​(IndexOnDisk sourceIndex,
                                            IndexOnDisk destIndex,
                                            java.lang.String sourceStructureName,
                                            java.lang.String destinationStructureName)
                                     throws java.io.IOException
        Copies an index structure from one index to another.
        Parameters:
        sourceIndex -
        destIndex -
        sourceStructureName -
        destinationStructureName -
        Throws:
        java.io.IOException - if an IO problem occurs
      • printMetaIndex

        public static void printMetaIndex​(Index index,
                                          java.lang.String structureName)
                                   throws java.io.IOException
        Print the contents of the meta index
        Throws:
        java.io.IOException
      • printMetaIndexJson

        public static void printMetaIndexJson​(Index index,
                                              java.lang.String structureName)
                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • getFieldId

        public static int getFieldId​(Index index,
                                     java.lang.String structureName,
                                     java.lang.String fieldName)
      • renameIndexStructure

        public static boolean renameIndexStructure​(Index _index,
                                                   java.lang.String sourceStructureName,
                                                   java.lang.String destinationStructureName)
                                            throws java.io.IOException
        Rename a structure within a given index.
        Returns:
        Returns true iff a structure was successfully renamed.
        Throws:
        java.io.IOException
      • configure

        public static void configure​(Index index,
                                     java.lang.Object o)
        Configures an object with the index, if the object implements IndexConfigurable
      • close

        public static void close​(java.lang.Object o)
                          throws java.io.IOException
        Check to see if an object is closeable, and if so, close it. Propagate any exception thrown.
        Parameters:
        o - object to check for being closeable.
        Throws:
        java.io.IOException - if exception thrown while closing.