Package org.terrier.realtime.memory
Class MemoryIndex
- java.lang.Object
-
- org.terrier.structures.Index
-
- org.terrier.realtime.memory.MemoryIndex
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,UpdatableIndex,WritableIndex
- Direct Known Subclasses:
MemoryFields
public class MemoryIndex extends Index implements UpdatableIndex, WritableIndex
An index held in fully memory. This is an updatable index, i.e. it supports indexDocument() methods which can be called at any time to add new documents. A MemoryIndex is also writable, i.e. it has a write() method that will convert it to an IndexOnDisk and write it out to the location specified by terrier.index.path and with prefix terrier.index.prefix.- Since:
- 4.0
- Author:
- Richard McCreadie, Dyaa Albakour
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMemoryIndex.Loader-
Nested classes/interfaces inherited from class org.terrier.structures.Index
Index.DirectIndexRef
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanblocksprotected CompressionFactory.CompressionConfigurationcompressionDirectConfigprotected CompressionFactory.CompressionConfigurationcompressionInvertedConfigprotected MemoryDirectIndexdirectprotected DocumentPostingListdocPostingsFIXMEprotected MemoryDocumentIndexdocumentgnu.trove.TObjectIntHashMap<java.lang.String>fieldIDsprotected booleanfieldsprotected java.lang.String[]fieldtagsprotected java.lang.ObjectindexingLockA lock that stops multiple indexing operations from happening at onceprotected MemoryInvertedIndexinvertedprotected MemoryLexiconlexiconprotected static org.slf4j.Loggerloggerprotected MemoryMetaIndexmetadataprotected TermPipelinepipeline_firstFIXMEprotected static java.lang.StringPIPELINE_NAMESPACEFIXMEprotected MemoryCollectionStatisticsstats
-
Constructor Summary
Constructors Constructor Description MemoryIndex()Constructor.MemoryIndex(MemoryLexicon tmplex, MemoryDocumentIndexMap document, MemoryInvertedIndex inverted, MemoryMetaIndex metadata, MemoryCollectionStatistics stats)MemoryIndex(IndexOnDisk superIndex)MemoryIndex(IndexOnDisk superIndex, boolean compressedMeta)Create a memory index from an existing on-disk index.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddToDocument(int docid, Document doc)Adds specified content contents to the named document id.booleanaddToDocument(int docid, DocumentPostingList docContents)Adds relevant terms to the named document id.voidclose()Not implemented.voidflush()Not implemented.CollectionStatisticsgetCollectionStatistics()Get the collection statisticsPostingIndex<?>getDirectIndex()Not implemented.DocumentIndexgetDocumentIndex()Return the DocumentIndex associated with this indexprotected TermPipelinegetEndOfPipeline()FIXMEIndexRefgetIndexRef()Returns a direct IndexRef to this indexjava.lang.ObjectgetIndexStructure(java.lang.String structureName)Return a particular index data structurejava.lang.ObjectgetIndexStructureInputStream(java.lang.String structureName)Return a particular index data structure input streamPostingIndex<?>getInvertedIndex()Returns the InvertedIndex to use for this indexLexicon<java.lang.String>getLexicon()Return the Lexicon associated with this indexMetaIndexgetMetaIndex()Get the Meta Index structurebooleanhasIndexStructure(java.lang.String structureName)Returns true iff the structure existsvoidindexDocument(java.util.Map<java.lang.String,java.lang.String> docProperties, DocumentPostingList docContents)Index a new document.voidindexDocument(Document doc)Index a new document.voidindexUnDocument(java.util.Map<java.lang.String,java.lang.String> docProperties, DocumentPostingList docContents)Index an unsearchable document.voidindexUnDocument(Document doc)Index an unsearchable document.protected voidload_pipeline()FIXMEprotected DiskIndexWritermakeDiskIndexWriter(java.lang.String path, java.lang.String prefix)booleanremoveDocument(int docid)Removes a document from the index.java.lang.StringtoString()Indexwrite(java.lang.String path, java.lang.String prefix)Write index structures to disk.-
Methods inherited from class org.terrier.structures.Index
createIndex, createIndex, getEnd, getStart, hasIndexStructureInputStream, makeDirectIndexRef, setIndexLoadingProfileAsRetrieval
-
-
-
-
Field Detail
-
logger
protected static final org.slf4j.Logger logger
-
lexicon
protected MemoryLexicon lexicon
-
inverted
protected MemoryInvertedIndex inverted
-
metadata
protected MemoryMetaIndex metadata
-
document
protected MemoryDocumentIndex document
-
stats
protected MemoryCollectionStatistics stats
-
direct
protected MemoryDirectIndex direct
-
blocks
protected boolean blocks
-
fields
protected boolean fields
-
fieldtags
protected java.lang.String[] fieldtags
-
fieldIDs
public gnu.trove.TObjectIntHashMap<java.lang.String> fieldIDs
-
indexingLock
protected java.lang.Object indexingLock
A lock that stops multiple indexing operations from happening at once
-
compressionInvertedConfig
protected CompressionFactory.CompressionConfiguration compressionInvertedConfig
-
compressionDirectConfig
protected CompressionFactory.CompressionConfiguration compressionDirectConfig
-
docPostings
protected DocumentPostingList docPostings
FIXME
-
pipeline_first
protected TermPipeline pipeline_first
FIXME
-
PIPELINE_NAMESPACE
protected static final java.lang.String PIPELINE_NAMESPACE
FIXME- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MemoryIndex
public MemoryIndex(MemoryLexicon tmplex, MemoryDocumentIndexMap document, MemoryInvertedIndex inverted, MemoryMetaIndex metadata, MemoryCollectionStatistics stats)
-
MemoryIndex
public MemoryIndex()
Constructor.
-
MemoryIndex
public MemoryIndex(IndexOnDisk superIndex)
-
MemoryIndex
public MemoryIndex(IndexOnDisk superIndex, boolean compressedMeta)
Create a memory index from an existing on-disk index. If the restored index used non-incremental docis, the restoration will take that into account. This implementation will- Parameters:
superIndex-compressedMeta-
-
-
Method Detail
-
getIndexStructure
public java.lang.Object getIndexStructure(java.lang.String structureName)
Return a particular index data structure- Overrides:
getIndexStructurein classIndex
-
getIndexStructureInputStream
public java.lang.Object getIndexStructureInputStream(java.lang.String structureName)
Description copied from class:IndexReturn a particular index data structure input stream- Overrides:
getIndexStructureInputStreamin classIndex
-
getLexicon
public Lexicon<java.lang.String> getLexicon()
Return the Lexicon associated with this index- Specified by:
getLexiconin classIndex
-
getInvertedIndex
public PostingIndex<?> getInvertedIndex()
Returns the InvertedIndex to use for this index- Specified by:
getInvertedIndexin classIndex
-
getMetaIndex
public MetaIndex getMetaIndex()
Get the Meta Index structure- Specified by:
getMetaIndexin classIndex
-
getDocumentIndex
public DocumentIndex getDocumentIndex()
Return the DocumentIndex associated with this index- Specified by:
getDocumentIndexin classIndex
-
getCollectionStatistics
public CollectionStatistics getCollectionStatistics()
Get the collection statistics- Specified by:
getCollectionStatisticsin classIndex
-
getDirectIndex
public PostingIndex<?> getDirectIndex()
Not implemented.- Specified by:
getDirectIndexin classIndex
-
getIndexRef
public IndexRef getIndexRef()
Description copied from class:IndexReturns a direct IndexRef to this index- Specified by:
getIndexRefin classIndex
-
indexDocument
public void indexDocument(Document doc) throws java.lang.Exception
Index a new document.- Specified by:
indexDocumentin interfaceUpdatableIndex- Throws:
java.lang.Exception
-
hasIndexStructure
public boolean hasIndexStructure(java.lang.String structureName)
Description copied from class:IndexReturns true iff the structure exists- Overrides:
hasIndexStructurein classIndex
-
indexDocument
public void indexDocument(java.util.Map<java.lang.String,java.lang.String> docProperties, DocumentPostingList docContents) throws java.lang.ExceptionIndex a new document.- Specified by:
indexDocumentin interfaceUpdatableIndex- Throws:
java.lang.Exception
-
indexUnDocument
public void indexUnDocument(Document doc) throws java.lang.Exception
Index an unsearchable document. This performs a partial index document operation. Term statistics and global statistics will be updated. But the inverted index will not be. In effect, this adds a document to the index, but in such a way that it will never be retrieved for any query. This is useful when you want to maintain collection statistics for a collection over time, but do not need search functionality.- Throws:
java.lang.Exception
-
indexUnDocument
public void indexUnDocument(java.util.Map<java.lang.String,java.lang.String> docProperties, DocumentPostingList docContents) throws java.lang.ExceptionIndex an unsearchable document. This performs a partial index document operation. Term statistics and global statistics will be updated. But the inverted index will not be. In effect, this adds a document to the index, but in such a way that it will never be retrieved for any query. This is useful when you want to maintain collection statistics for a collection over time, but do not need search functionality.- Throws:
java.lang.Exception
-
addToDocument
public boolean addToDocument(int docid, Document doc) throws java.lang.ExceptionAdds specified content contents to the named document id.NB: This implementation uses addToDocument(int, DocumentPostingList) internally.
- Specified by:
addToDocumentin interfaceUpdatableIndex- Returns:
- true if supported & successful.
- Throws:
java.lang.Exception
-
addToDocument
public boolean addToDocument(int docid, DocumentPostingList docContents) throws java.lang.ExceptionAdds relevant terms to the named document id. Updates DocumentIndex and CollectionStatistics appropriately.- Specified by:
addToDocumentin interfaceUpdatableIndex- Returns:
- true if supported & successful.
- Throws:
java.lang.Exception
-
write
public Index write(java.lang.String path, java.lang.String prefix) throws java.io.IOException
Write index structures to disk.- Specified by:
writein interfaceWritableIndex- Throws:
java.io.IOException
-
makeDiskIndexWriter
protected DiskIndexWriter makeDiskIndexWriter(java.lang.String path, java.lang.String prefix)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
close
public void close() throws java.io.IOExceptionNot implemented.
-
flush
public void flush() throws java.io.IOExceptionNot implemented.- Throws:
java.io.IOException
-
getEndOfPipeline
protected TermPipeline getEndOfPipeline()
FIXME
-
load_pipeline
protected void load_pipeline()
FIXME
-
removeDocument
public boolean removeDocument(int docid)
Description copied from interface:UpdatableIndexRemoves a document from the index. Returns true if successful. No known operable implementations at this time.- Specified by:
removeDocumentin interfaceUpdatableIndex
-
-