Package org.terrier.structures
Class IndexUtil
- java.lang.Object
-
- org.terrier.structures.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 IndexConfigurablestatic 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 indexstatic 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 cachestatic 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 namestatic 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 indexstatic 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 indexstatic void
printMetaIndex(Index index, java.lang.String structureName)
Print the contents of the meta indexstatic 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 anotherstatic 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
-
-
-
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
-
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 onstructureName
- which structure name to usestructure
- 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 onstructureName
- 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 examinestructureName
- 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.
-
-