Class LuceneFormSearchFactory
java.lang.Object
fr.paris.lutece.plugins.forms.service.search.LuceneFormSearchFactory
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 -
Method Summary
Modifier and TypeMethodDescriptionorg.apache.lucene.search.IndexSearcherAcquire a pooledIndexSearcheron the main index.org.apache.lucene.analysis.Analyzerorg.apache.lucene.store.DirectoryOpen a freshFSDirectoryon the main path.org.apache.lucene.store.Directoryorg.apache.lucene.index.IndexWritergetIndexWriter(Boolean bCreateIndex, boolean mainDirectory) Create (or return the cached)IndexWriteron either the main or the temporary directory.getPathDirectory(boolean tempDirectory) Resolve the configured index path (main or temporary).voidSignal that the main index has just been updated so subsequentacquireSearcher()calls observe the new view.voidreleaseSearcher(org.apache.lucene.search.IndexSearcher searcher) voidshutdown()Release every held resource.voidSwap the freshly built temporary directory onto the main location.
-
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)IndexWriteron either the main or the temporary directory. Concurrent callers serialise through the factory lock; existing temporary writers are closed before switching target. -
getPathDirectory
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-trueto append the temporary suffix- Returns:
- the absolute or webapp-relative path string
-
getDirectory
Open a freshFSDirectoryon the main path. The caller owns the returned handle and is responsible for closing it. Used by callers that need a one-off Directory forDirectoryReader.indexExists(Directory)or for writer construction.- Throws:
IOException
-
getDirectoryTemp
- Throws:
IOException
-
acquireSearcher
Acquire a pooledIndexSearcheron the main index. Must be paired withreleaseSearcher(IndexSearcher). Returnsnullif the index does not yet exist on disk.- Throws:
IOException
-
releaseSearcher
- Throws:
IOException
-
refreshSearcher
public void refreshSearcher()Signal that the main index has just been updated so subsequentacquireSearcher()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 theSearcherManagerobserve 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.
-