Class LuceneFormSearchFactory

java.lang.Object
fr.paris.lutece.plugins.forms.service.search.LuceneFormSearchFactory

@ApplicationScoped public class LuceneFormSearchFactory extends Object
Shared factory for Lucene resources used by the forms index. Thread-safety: all state transitions on the writer, the long-lived search Directory and the SearcherManager go through _lock. This guarantees that: - getIndexWriter(Boolean, boolean) never hands out an IndexWriter that is being closed or recreated concurrently; - swapIndex() closes every open resource before moving files on disk so no reader/writer is observing a half-moved directory; - the SearcherManager is rebuilt atomically after each swap. In a multi-instance deployment with a shared index volume, the single-writer invariant across JVMs is enforced by the LuceneLockManagerDB distributed lock held by LuceneFormSearchIndexer; this class only guarantees intra-JVM serialisation.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.lucene.search.IndexSearcher
    Acquire a pooled IndexSearcher on the main index.
    org.apache.lucene.analysis.Analyzer
     
    org.apache.lucene.store.Directory
    Open a fresh FSDirectory on the main path.
    org.apache.lucene.store.Directory
     
    org.apache.lucene.index.IndexWriter
    getIndexWriter(Boolean bCreateIndex, boolean mainDirectory)
    Create (or return the cached) IndexWriter on either the main or the temporary directory.
    getPathDirectory(boolean tempDirectory)
    Resolve the configured index path (main or temporary).
    void
    Signal that the main index has just been updated so subsequent acquireSearcher() calls observe the new view.
    void
    releaseSearcher(org.apache.lucene.search.IndexSearcher searcher)
     
    void
    Release every held resource.
    void
    Swap the freshly built temporary directory onto the main location.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • LuceneFormSearchFactory

      public LuceneFormSearchFactory()
  • Method Details

    • getAnalyzer

      public org.apache.lucene.analysis.Analyzer getAnalyzer()
    • getIndexWriter

      public org.apache.lucene.index.IndexWriter getIndexWriter(Boolean bCreateIndex, boolean mainDirectory)
      Create (or return the cached) IndexWriter on either the main or the temporary directory. Concurrent callers serialise through the factory lock; existing temporary writers are closed before switching target.
    • getPathDirectory

      public String getPathDirectory(boolean tempDirectory)
      Resolve the configured index path (main or temporary). Package-visible so the plugin initialisation can surface a warning if the path is JVM-local.
      Parameters:
      tempDirectory - true to append the temporary suffix
      Returns:
      the absolute or webapp-relative path string
    • getDirectory

      public org.apache.lucene.store.Directory getDirectory() throws IOException
      Open a fresh FSDirectory on the main path. The caller owns the returned handle and is responsible for closing it. Used by callers that need a one-off Directory for DirectoryReader.indexExists(Directory) or for writer construction.
      Throws:
      IOException
    • getDirectoryTemp

      public org.apache.lucene.store.Directory getDirectoryTemp() throws IOException
      Throws:
      IOException
    • acquireSearcher

      public org.apache.lucene.search.IndexSearcher acquireSearcher() throws IOException
      Acquire a pooled IndexSearcher on the main index. Must be paired with releaseSearcher(IndexSearcher). Returns null if the index does not yet exist on disk.
      Throws:
      IOException
    • releaseSearcher

      public void releaseSearcher(org.apache.lucene.search.IndexSearcher searcher) throws IOException
      Throws:
      IOException
    • refreshSearcher

      public void refreshSearcher()
      Signal that the main index has just been updated so subsequent acquireSearcher() calls observe the new view. Safe to call when no reader has been opened yet (no-op in that case).
    • swapIndex

      public void swapIndex()
      Swap the freshly built temporary directory onto the main location. Holds the factory lock for the whole operation so neither writers nor the SearcherManager observe a partially-moved directory; both are closed before the move and lazily reopened by the next caller.
    • shutdown

      @PreDestroy public void shutdown()
      Release every held resource. Invoked at application shutdown.