Package org.terrier.structures
Class PropertiesIndex
- java.lang.Object
-
- org.terrier.structures.Index
-
- org.terrier.structures.PropertiesIndex
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Direct Known Subclasses:
IndexOnDisk
public abstract class PropertiesIndex extends Index implements java.io.Closeable, java.io.Flushable
This class encapsulates all the Indexes at retrieval time. It is loaded by giving a path and prefix. This looks for an index properties file at path/prefix.properties. Essentially, the properties file then specifies which index structures the index supports. The index then loads these so they can be used in retrieval.Arbitrary properties can be defined in the index properties files, and in particular, properties are used to record index statistics and the contructor type and values of various index objects.
The Index will apply methods on specially marked interfaces. Currently, the only interface supported is IndexConfigurable. Moreover, structures implementing java.io.Closeable will have their close method called when the Index is closed.
- Author:
- Craig Macdonald & Vassilis Plachouras
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classPropertiesIndex.UpdatingCollectionStatisticsThis collection statistics parses the associated index properties for each call.-
Nested classes/interfaces inherited from class org.terrier.structures.Index
Index.DirectIndexRef
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandirtyPropertiesHave the properties of this index changed, suggesting a flush() is necessary when closingprotected static java.lang.Class<?>[]EMPTY_CLASS_ARRAYempty class arrayprotected static java.lang.StringlastLoadErrorprotected static org.slf4j.LoggerloggerThe logger usedprotected static intMINIMUM_INDEX_TERRIER_VERSIONprotected java.util.Propertiespropertiesproperties of this indexprotected static java.lang.StringPROPERTIES_SUFFIXprotected static booleanRETRIEVAL_LOADING_PROFILE
-
Constructor Summary
Constructors Modifier Constructor Description PropertiesIndex()Empty Index constructor - this should never be used! Use Index.createIndex() insteadprotectedPropertiesIndex(long a, long b, long c)A constructor for child classes that doesnt open the file
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddIndexStructure(java.lang.String structureName, java.lang.Class<?> className, java.lang.Class<?>[] paramTypes, java.lang.String[] paramValues)tell the index about a new index structure it provides.voidaddIndexStructure(java.lang.String structureName, java.lang.String className)add an index structure to this index.voidaddIndexStructure(java.lang.String structureName, java.lang.String className, java.lang.String[] paramTypes, java.lang.String[] paramValues)add an index structure to this index.voidaddIndexStructure(java.lang.String structureName, java.lang.String className, java.lang.String paramTypes, java.lang.String paramValues)add an index structure to this index.voidaddIndexStructureInputStream(java.lang.String structureName, java.lang.Class<?> className, java.lang.Class<?>[] paramTypes, java.lang.String[] paramValues)tell the index about a new input stream index structure it provides.voidaddIndexStructureInputStream(java.lang.String structureName, java.lang.String className)tell the index about a new input stream index structure it provides.voidaddIndexStructureInputStream(java.lang.String structureName, java.lang.String className, java.lang.String[] paramTypes, java.lang.String[] paramValues)tell the index about a new input stream index structure it provides.voidaddIndexStructureInputStream(java.lang.String structureName, java.lang.String className, java.lang.String paramTypes, java.lang.String paramValues)tell the index about a new input stream index structure it provides.static booleanallExists(java.lang.String... files)returns true if all named files existabstract voidclose()Closes the data structures of the index.static IndexOnDiskcreateIndex()Constructs a new Index object.static IndexOnDiskcreateIndex(java.lang.String path, java.lang.String prefix)Factory method for load an index.static IndexOnDiskcreateNewIndex(java.lang.String path, java.lang.String prefix)Factory method create a new index.static booleanexistsIndex(java.lang.String path, java.lang.String prefix)Returns true if it is likely that an index exists at the specified locationabstract voidflush()Write any dirty data structures down to diskabstract CollectionStatisticsgetCollectionStatistics()Get the collection statisticsabstract PostingIndex<?>getDirectIndex()Return the DirectIndex associated with this indexabstract DocumentIndexgetDocumentIndex()Return the DocumentIndex associated with this indexintgetEnd()Returns the last docid in this indexstatic booleangetIndexLoadingProfileAsRetrieval()Get RETRIEVAL_LOADING_PROFILEjava.lang.StringgetIndexProperty(java.lang.String key, java.lang.String defaultValue)get an arbitrary property in the indexIndexRefgetIndexRef()Returns a direct IndexRef to this indexabstract java.lang.ObjectgetIndexStructure(java.lang.String structureName)Obtains the named index structure, using an already loaded one if possible.abstract java.lang.ObjectgetIndexStructureInputStream(java.lang.String structureName)Return the input stream associated with the specified structure of this indexintgetIntIndexProperty(java.lang.String key, int defaultValue)get an arbitrary int property from the indexabstract PostingIndex<?>getInvertedIndex()Returns the InvertedIndex to use for this indexstatic java.lang.StringgetLastIndexLoadError()Returns the last warning given by an index being loaded.abstract Lexicon<java.lang.String>getLexicon()Return the Lexicon associated with this indexabstract MetaIndexgetMetaIndex()Get the Meta Index structurejava.util.PropertiesgetProperties()Get the index propertiesintgetStart()Returns the first docid in this indexbooleanhasIndexStructure(java.lang.String structureName)Does this index have an index structure with the specified name?booleanhasIndexStructureInputStream(java.lang.String structureName)Does this index have an index structure input stream with the specified name?protected static java.lang.Stringjoin(java.lang.String[] input, java.lang.String joinString)joins a series of strings together with a delimiterstatic voidsetIndexLoadingProfileAsRetrieval(boolean yes)Set RETRIEVAL_LOADING_PROFILEvoidsetIndexProperty(java.lang.String key, java.lang.String value)set an arbitrary property in the indexabstract java.lang.StringtoString()Returns a String representation of this index-
Methods inherited from class org.terrier.structures.Index
makeDirectIndexRef
-
-
-
-
Field Detail
-
MINIMUM_INDEX_TERRIER_VERSION
protected static final int MINIMUM_INDEX_TERRIER_VERSION
- See Also:
- Constant Field Values
-
PROPERTIES_SUFFIX
protected static final java.lang.String PROPERTIES_SUFFIX
- See Also:
- Constant Field Values
-
RETRIEVAL_LOADING_PROFILE
protected static boolean RETRIEVAL_LOADING_PROFILE
-
logger
protected static final org.slf4j.Logger logger
The logger used
-
lastLoadError
protected static java.lang.String lastLoadError
-
EMPTY_CLASS_ARRAY
protected static final java.lang.Class<?>[] EMPTY_CLASS_ARRAY
empty class array
-
properties
protected final java.util.Properties properties
properties of this index
-
dirtyProperties
protected boolean dirtyProperties
Have the properties of this index changed, suggesting a flush() is necessary when closing
-
-
Method Detail
-
allExists
public static boolean allExists(java.lang.String... files)
returns true if all named files exist
-
createIndex
public static IndexOnDisk createIndex()
Constructs a new Index object. Don't call this method, call the createIndex(String, String) factory method to construct an Index object.
-
createIndex
public static IndexOnDisk createIndex(java.lang.String path, java.lang.String prefix)
Factory method for load an index. This method should be used in order to load an existing index in the applications.- Parameters:
path- String the path in which the data structures will be created.prefix- String the prefix of the files to be created.
-
createNewIndex
public static IndexOnDisk createNewIndex(java.lang.String path, java.lang.String prefix)
Factory method create a new index. This method should be used in order to load a new index in the applications.- Parameters:
path- String the path in which the data structures will be created.prefix- String the prefix of the files to be created.
-
existsIndex
public static boolean existsIndex(java.lang.String path, java.lang.String prefix)Returns true if it is likely that an index exists at the specified location- Parameters:
path-prefix-- Returns:
- true if a .properties or a .log files exists
-
getIndexLoadingProfileAsRetrieval
public static boolean getIndexLoadingProfileAsRetrieval()
Get RETRIEVAL_LOADING_PROFILE- Returns:
- retrieval loading profile
-
getLastIndexLoadError
public static java.lang.String getLastIndexLoadError()
Returns the last warning given by an index being loaded.
-
join
protected static java.lang.String join(java.lang.String[] input, java.lang.String joinString)joins a series of strings together with a delimiter
-
setIndexLoadingProfileAsRetrieval
public static void setIndexLoadingProfileAsRetrieval(boolean yes)
Set RETRIEVAL_LOADING_PROFILE- Parameters:
yes-
-
addIndexStructure
public void addIndexStructure(java.lang.String structureName, java.lang.Class<?> className, java.lang.Class<?>[] paramTypes, java.lang.String[] paramValues)tell the index about a new index structure it provides. Class and parameter types specified as Class objects instead of Strings.
-
addIndexStructure
public void addIndexStructure(java.lang.String structureName, java.lang.String className)add an index structure to this index. Structure will be called structureName, and instantiated by a class called className. Instantiation parameters are "String,String", which are "path,prefix".- Parameters:
structureName-className-
-
addIndexStructure
public void addIndexStructure(java.lang.String structureName, java.lang.String className, java.lang.String paramTypes, java.lang.String paramValues)add an index structure to this index. Structure will be called structureName, and instantiated by a class called className. Instantiation type parameters or values are non-default.
-
addIndexStructure
public void addIndexStructure(java.lang.String structureName, java.lang.String className, java.lang.String[] paramTypes, java.lang.String[] paramValues)add an index structure to this index. Structure will be called structureName, and instantiated by a class called className. Instantiation type parameters or values are non-default.
-
addIndexStructureInputStream
public void addIndexStructureInputStream(java.lang.String structureName, java.lang.Class<?> className, java.lang.Class<?>[] paramTypes, java.lang.String[] paramValues)tell the index about a new input stream index structure it provides.
-
addIndexStructureInputStream
public void addIndexStructureInputStream(java.lang.String structureName, java.lang.String className)tell the index about a new input stream index structure it provides.
-
addIndexStructureInputStream
public void addIndexStructureInputStream(java.lang.String structureName, java.lang.String className, java.lang.String paramTypes, java.lang.String paramValues)tell the index about a new input stream index structure it provides.
-
addIndexStructureInputStream
public void addIndexStructureInputStream(java.lang.String structureName, java.lang.String className, java.lang.String[] paramTypes, java.lang.String[] paramValues)tell the index about a new input stream index structure it provides.
-
close
public abstract void close() throws java.io.IOExceptionCloses the data structures of the index.
-
flush
public abstract void flush() throws java.io.IOExceptionWrite any dirty data structures down to disk- Specified by:
flushin interfacejava.io.Flushable- Throws:
java.io.IOException
-
getCollectionStatistics
public abstract CollectionStatistics getCollectionStatistics()
Get the collection statistics- Specified by:
getCollectionStatisticsin classIndex
-
getDirectIndex
public abstract PostingIndex<?> getDirectIndex()
Return the DirectIndex associated with this index- Specified by:
getDirectIndexin classIndex
-
getDocumentIndex
public abstract DocumentIndex getDocumentIndex()
Return the DocumentIndex associated with this index- Specified by:
getDocumentIndexin classIndex
-
getIndexProperty
public java.lang.String getIndexProperty(java.lang.String key, java.lang.String defaultValue)get an arbitrary property in the index- Parameters:
key- Key of the property to getdefaultValue- value of the property to use if property is not set- Returns:
- Value of the property
-
getIndexRef
public IndexRef getIndexRef()
Description copied from class:IndexReturns a direct IndexRef to this index- Specified by:
getIndexRefin classIndex
-
getIndexStructure
public abstract java.lang.Object getIndexStructure(java.lang.String structureName)
Obtains the named index structure, using an already loaded one if possible.- Overrides:
getIndexStructurein classIndex- Parameters:
structureName- name of the required structure- Returns:
- desired object or null if not found
-
getIndexStructureInputStream
public abstract java.lang.Object getIndexStructureInputStream(java.lang.String structureName)
Return the input stream associated with the specified structure of this index- Overrides:
getIndexStructureInputStreamin classIndex- Parameters:
structureName- The name of the structure of which you want the inputstream. Eg "lexicon"- Returns:
- Required structure, or null if not found
-
getIntIndexProperty
public int getIntIndexProperty(java.lang.String key, int defaultValue)get an arbitrary int property from the index
-
getInvertedIndex
public abstract PostingIndex<?> getInvertedIndex()
Returns the InvertedIndex to use for this index- Specified by:
getInvertedIndexin classIndex
-
getLexicon
public abstract Lexicon<java.lang.String> getLexicon()
Return the Lexicon associated with this index- Specified by:
getLexiconin classIndex
-
getMetaIndex
public abstract MetaIndex getMetaIndex()
Get the Meta Index structure- Specified by:
getMetaIndexin classIndex
-
getProperties
public java.util.Properties getProperties()
Get the index properties
-
hasIndexStructure
public boolean hasIndexStructure(java.lang.String structureName)
Does this index have an index structure with the specified name?- Overrides:
hasIndexStructurein classIndex- Parameters:
structureName- name of the required structure- Returns:
- true if the index has an appropriately named structure
-
hasIndexStructureInputStream
public boolean hasIndexStructureInputStream(java.lang.String structureName)
Does this index have an index structure input stream with the specified name?- Overrides:
hasIndexStructureInputStreamin classIndex- Parameters:
structureName- name of the required structure- Returns:
- true if the index has an appropriately named structure
-
setIndexProperty
public void setIndexProperty(java.lang.String key, java.lang.String value)set an arbitrary property in the index- Parameters:
key- Key to of the property to setvalue- Value of the property to set
-
toString
public abstract java.lang.String toString()
Returns a String representation of this index- Overrides:
toStringin classjava.lang.Object
-
getStart
public int getStart()
Returns the first docid in this index
-
-