Class BaseLuceneStorage

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    LuceneKdStorage, LuceneKvStorage

    public class BaseLuceneStorage
    extends java.lang.Object
    implements java.io.Closeable
    Abstract Lucene implementation of NoSQL storage.

    Design: 3 special fields

    Since:
    0.10.0
    Author:
    Thanh Nguyen
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.String FIELD_ID  
      protected static java.lang.String FIELD_KEY  
      protected static java.lang.String FIELD_SPACE_ID  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.lucene.index.Term buildIdTerm​(java.lang.String spaceId, java.lang.String key)
      Build the "id" term (id="spaceId:key"
      protected org.apache.lucene.search.Query buildQuery​(java.lang.String spaceId, java.lang.String key)
      Build query to match entry's space-id and key.
      void close()
      protected org.apache.lucene.document.Document createDocument​(java.lang.String spaceId, java.lang.String key)
      Create a Document, pre-filled with space-id and key fields.
      void destroy()  
      protected long doCount​(java.lang.String spaceId)
      Count number of documents within a space.
      protected void doDelete​(java.lang.String spaceId, java.lang.String key, IDeleteCallback callback)
      Delete a document, identified by spaceId:key, from index.
      protected org.apache.lucene.document.Document doGet​(java.lang.String spaceId, java.lang.String key)
      Fetch a document, identified by spaceId:key, from index.
      long getAutoCommitPeriodMs()
      When set to a positive value, data is automatically committed periodically in a background thread.
      protected org.apache.lucene.store.Directory getDirectory()
      Getter for directory.
      protected com.github.ddth.lucext.directory.IndexManager getIndexManager()
      Getter for indexManager.
      protected org.apache.lucene.search.IndexSearcher getIndexSearcher()  
      protected org.apache.lucene.index.IndexWriter getIndexWriter()  
      protected org.apache.lucene.index.IndexWriterConfig getIndexWriterConfig()
      Getter for indexWriterConfig.
      BaseLuceneStorage init()  
      boolean isAsyncWrite()
      In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default value false)?
      BaseLuceneStorage setAsyncWrite​(boolean asyncWrite)
      In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default value false)?
      BaseLuceneStorage setAutoCommitPeriodMs​(long autoCommitPeriodMs)
      When set to a positive value, data is automatically committed periodically in a background thread.
      BaseLuceneStorage setDirectory​(org.apache.lucene.store.Directory directory)
      Setter for directory.
      BaseLuceneStorage setIndexManager​(com.github.ddth.lucext.directory.IndexManager indexManager)
      Setter for indexManager.
      BaseLuceneStorage setIndexWriterConfig​(org.apache.lucene.index.IndexWriterConfig indexWriterConfig)
      Setter for indexWriterConfig.
      • Methods inherited from class java.lang.Object

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

      • BaseLuceneStorage

        public BaseLuceneStorage()
    • Method Detail

      • getDirectory

        protected org.apache.lucene.store.Directory getDirectory()
        Getter for directory.
        Returns:
      • setDirectory

        public BaseLuceneStorage setDirectory​(org.apache.lucene.store.Directory directory)
        Setter for directory.
        Parameters:
        directory -
        Returns:
      • getIndexWriterConfig

        protected org.apache.lucene.index.IndexWriterConfig getIndexWriterConfig()
        Getter for indexWriterConfig.
        Returns:
      • setIndexWriterConfig

        public BaseLuceneStorage setIndexWriterConfig​(org.apache.lucene.index.IndexWriterConfig indexWriterConfig)
        Setter for indexWriterConfig.
        Parameters:
        indexWriterConfig -
        Returns:
      • getIndexManager

        protected com.github.ddth.lucext.directory.IndexManager getIndexManager()
        Getter for indexManager.
        Returns:
      • setIndexManager

        public BaseLuceneStorage setIndexManager​(com.github.ddth.lucext.directory.IndexManager indexManager)
        Setter for indexManager.
        Parameters:
        indexManager -
        Returns:
      • isAsyncWrite

        public boolean isAsyncWrite()
        In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default value false)?

        Note: autoCommitPeriodMs must be set to a positive value to enable async-write.

        Returns:
        See Also:
        getAutoCommitPeriodMs()
      • setAsyncWrite

        public BaseLuceneStorage setAsyncWrite​(boolean asyncWrite)
        In async-write mode, update operations (delete/put) are performed but not committed, which yields higher update performance but data may be lost in case of JVM crash (default value false)?

        Note: autoCommitPeriodMs must be set to a positive value to enable async-write.

        Parameters:
        asyncWrite -
        Returns:
        See Also:
        getAutoCommitPeriodMs()
      • getAutoCommitPeriodMs

        public long getAutoCommitPeriodMs()
        When set to a positive value, data is automatically committed periodically in a background thread.
        Returns:
      • setAutoCommitPeriodMs

        public BaseLuceneStorage setAutoCommitPeriodMs​(long autoCommitPeriodMs)
        When set to a positive value, data is automatically committed periodically in a background thread.
        Parameters:
        autoCommitPeriodMs -
        Returns:
      • init

        public BaseLuceneStorage init()
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • destroy

        public void destroy()
      • getIndexWriter

        protected org.apache.lucene.index.IndexWriter getIndexWriter()
      • getIndexSearcher

        protected org.apache.lucene.search.IndexSearcher getIndexSearcher()
                                                                   throws java.io.IOException
        Throws:
        java.io.IOException
      • buildQuery

        protected org.apache.lucene.search.Query buildQuery​(java.lang.String spaceId,
                                                            java.lang.String key)
        Build query to match entry's space-id and key.
        Parameters:
        spaceId -
        key -
        Returns:
      • buildIdTerm

        protected org.apache.lucene.index.Term buildIdTerm​(java.lang.String spaceId,
                                                           java.lang.String key)
        Build the "id" term (id="spaceId:key"
        Parameters:
        spaceId -
        key -
        Returns:
      • createDocument

        protected org.apache.lucene.document.Document createDocument​(java.lang.String spaceId,
                                                                     java.lang.String key)
        Create a Document, pre-filled with space-id and key fields.
        Parameters:
        spaceId -
        key -
        Returns:
      • doDelete

        protected void doDelete​(java.lang.String spaceId,
                                java.lang.String key,
                                IDeleteCallback callback)
        Delete a document, identified by spaceId:key, from index.
        Parameters:
        spaceId -
        key -
        callback -
        Since:
        1.0.0
      • doGet

        protected org.apache.lucene.document.Document doGet​(java.lang.String spaceId,
                                                            java.lang.String key)
                                                     throws java.io.IOException
        Fetch a document, identified by spaceId:key, from index.
        Parameters:
        spaceId -
        key -
        Returns:
        Throws:
        java.io.IOException
      • doCount

        protected long doCount​(java.lang.String spaceId)
                        throws java.io.IOException
        Count number of documents within a space.
        Parameters:
        spaceId -
        Returns:
        Throws:
        java.io.IOException