Class 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
    • Constructor Detail

      • 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:
        getIndexStructure in class Index
      • getIndexStructureInputStream

        public java.lang.Object getIndexStructureInputStream​(java.lang.String structureName)
        Description copied from class: Index
        Return a particular index data structure input stream
        Overrides:
        getIndexStructureInputStream in class Index
      • getLexicon

        public Lexicon<java.lang.String> getLexicon()
        Return the Lexicon associated with this index
        Specified by:
        getLexicon in class Index
      • getIndexRef

        public IndexRef getIndexRef()
        Description copied from class: Index
        Returns a direct IndexRef to this index
        Specified by:
        getIndexRef in class Index
      • indexDocument

        public void indexDocument​(Document doc)
                           throws java.lang.Exception
        Index a new document.
        Specified by:
        indexDocument in interface UpdatableIndex
        Throws:
        java.lang.Exception
      • hasIndexStructure

        public boolean hasIndexStructure​(java.lang.String structureName)
        Description copied from class: Index
        Returns true iff the structure exists
        Overrides:
        hasIndexStructure in class Index
      • indexDocument

        public void indexDocument​(java.util.Map<java.lang.String,​java.lang.String> docProperties,
                                  DocumentPostingList docContents)
                           throws java.lang.Exception
        Index a new document.
        Specified by:
        indexDocument in interface UpdatableIndex
        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.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
      • addToDocument

        public boolean addToDocument​(int docid,
                                     Document doc)
                              throws java.lang.Exception
        Adds specified content contents to the named document id.

        NB: This implementation uses addToDocument(int, DocumentPostingList) internally.

        Specified by:
        addToDocument in interface UpdatableIndex
        Returns:
        true if supported & successful.
        Throws:
        java.lang.Exception
      • addToDocument

        public boolean addToDocument​(int docid,
                                     DocumentPostingList docContents)
                              throws java.lang.Exception
        Adds relevant terms to the named document id. Updates DocumentIndex and CollectionStatistics appropriately.
        Specified by:
        addToDocument in interface UpdatableIndex
        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:
        write in interface WritableIndex
        Throws:
        java.io.IOException
      • makeDiskIndexWriter

        protected DiskIndexWriter makeDiskIndexWriter​(java.lang.String path,
                                                      java.lang.String prefix)
      • toString

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

        public void close()
                   throws java.io.IOException
        Not implemented.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class Index
        Throws:
        java.io.IOException
      • flush

        public void flush()
                   throws java.io.IOException
        Not 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: UpdatableIndex
        Removes a document from the index. Returns true if successful. No known operable implementations at this time.
        Specified by:
        removeDocument in interface UpdatableIndex