Class AbstractLuceneBase

  • Direct Known Subclasses:
    AbstractLuceneIndexerImpl

    public abstract class AbstractLuceneBase
    extends java.lang.Object
    Common support for abstracting the lucene indexer from its configuration and management requirements.

    This class defines where the indexes are stored. This should be via a configurable Bean property in Spring.

    The default file structure is

    1. "base"/"protocol"/"name"/ for the main index
    2. "base"/"protocol"/"name"/deltas/"id" for transactional updates
    3. "base"/"protocol"/"name"/undo/"id" undo information

    The IndexWriter and IndexReader for a given index are toggled (one should be used for delete and the other for write). These are reused/closed/initialised as required.

    The index deltas are buffered to memory and persisted in the file system as required.

    Author:
    Andy Hind
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String deltaId
      The identifier for the delta
      protected org.alfresco.service.cmr.repository.StoreRef store
      The identifier for the store
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void closeDeltaReader()
      Close the on file reader for the delta if it is open
      protected void closeDeltaWriter()
      Close the on disk delta writer
      void deleteIndex()  
      <R> R doReadOnly​(IndexInfo.LockWork<R> lockWork)
      Execute actions against a read only index (all write ops will block)
      java.lang.String getDeltaId()
      Get the ID for the delat we are working with.
      protected org.apache.lucene.index.IndexReader getDeltaReader()
      Get a reader for the on file portion of the delta
      protected org.apache.lucene.index.IndexWriter getDeltaWriter()
      Get the on file writer for the delta
      org.alfresco.service.cmr.dictionary.DictionaryService getDictionaryService()
      Get the dictionary service.
      LuceneConfig getLuceneConfig()
      Get the lucene configuration options.
      protected org.apache.lucene.index.IndexReader getReader()  
      protected org.apache.lucene.search.IndexSearcher getSearcher()
      Get a searcher for the main index TODO: Split out support for the main index.
      protected ClosingIndexSearcher getSearcher​(LuceneIndexer luceneIndexer)  
      protected TransactionStatus getStatus()  
      protected void initialise​(org.alfresco.service.cmr.repository.StoreRef store, java.lang.String deltaId)
      Initialise the configuration elements of the lucene store indexers and searchers.
      protected void saveDelta()
      Save the in memory delta to the disk, make sure there is nothing held in memory
      void setDictionaryService​(org.alfresco.service.cmr.dictionary.DictionaryService dictionaryService)
      Set the dictionary service
      protected void setInfo​(long docs, java.util.Set<java.lang.String> deletions, java.util.Set<java.lang.String> containerDeletions, boolean deleteNodesOnly)  
      void setLuceneConfig​(LuceneConfig config)
      Set the lucene configuration options
      protected void setStatus​(TransactionStatus status)  
      • Methods inherited from class java.lang.Object

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

      • store

        protected org.alfresco.service.cmr.repository.StoreRef store
        The identifier for the store
      • deltaId

        protected java.lang.String deltaId
        The identifier for the delta
    • Constructor Detail

      • AbstractLuceneBase

        public AbstractLuceneBase()
    • Method Detail

      • initialise

        protected void initialise​(org.alfresco.service.cmr.repository.StoreRef store,
                                  java.lang.String deltaId)
                           throws LuceneIndexException
        Initialise the configuration elements of the lucene store indexers and searchers.
        Parameters:
        store - StoreRef
        deltaId - String
        Throws:
        LuceneIndexException
      • getSearcher

        protected org.apache.lucene.search.IndexSearcher getSearcher()
                                                              throws LuceneIndexException
        Get a searcher for the main index TODO: Split out support for the main index. We really only need this if we want to search over the changing index before it is committed
        Returns:
        - the searcher
        Throws:
        LuceneIndexException
      • getDeltaReader

        protected org.apache.lucene.index.IndexReader getDeltaReader()
                                                              throws LuceneIndexException,
                                                                     java.io.IOException
        Get a reader for the on file portion of the delta
        Returns:
        - the index reader
        Throws:
        java.io.IOException
        java.io.IOException
        LuceneIndexException
      • closeDeltaReader

        protected void closeDeltaReader()
                                 throws LuceneIndexException,
                                        java.io.IOException
        Close the on file reader for the delta if it is open
        Throws:
        java.io.IOException
        java.io.IOException
        LuceneIndexException
      • getDeltaWriter

        protected org.apache.lucene.index.IndexWriter getDeltaWriter()
                                                              throws LuceneIndexException,
                                                                     java.io.IOException
        Get the on file writer for the delta
        Returns:
        - the writer for the delta
        Throws:
        java.io.IOException
        java.io.IOException
        LuceneIndexException
      • closeDeltaWriter

        protected void closeDeltaWriter()
                                 throws LuceneIndexException,
                                        java.io.IOException
        Close the on disk delta writer
        Throws:
        java.io.IOException
        java.io.IOException
        LuceneIndexException
      • saveDelta

        protected void saveDelta()
                          throws LuceneIndexException,
                                 java.io.IOException
        Save the in memory delta to the disk, make sure there is nothing held in memory
        Throws:
        java.io.IOException
        java.io.IOException
        LuceneIndexException
      • setInfo

        protected void setInfo​(long docs,
                               java.util.Set<java.lang.String> deletions,
                               java.util.Set<java.lang.String> containerDeletions,
                               boolean deleteNodesOnly)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • setStatus

        protected void setStatus​(TransactionStatus status)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • setDictionaryService

        public void setDictionaryService​(org.alfresco.service.cmr.dictionary.DictionaryService dictionaryService)
        Set the dictionary service
        Parameters:
        dictionaryService - DictionaryService
      • getDictionaryService

        public org.alfresco.service.cmr.dictionary.DictionaryService getDictionaryService()
        Get the dictionary service.
        Returns:
        - the service
      • setLuceneConfig

        public void setLuceneConfig​(LuceneConfig config)
        Set the lucene configuration options
        Parameters:
        config - LuceneConfig
      • getLuceneConfig

        public LuceneConfig getLuceneConfig()
        Get the lucene configuration options.
        Returns:
        - the config options object.
      • getDeltaId

        public java.lang.String getDeltaId()
        Get the ID for the delat we are working with.
        Returns:
        - the id
      • doReadOnly

        public <R> R doReadOnly​(IndexInfo.LockWork<R> lockWork)
        Execute actions against a read only index (all write ops will block)
        Returns:
        - the result returned by the action.
      • deleteIndex

        public void deleteIndex()