Class LuceneConnection
- java.lang.Object
-
- com.atlassian.confluence.internal.search.v2.lucene.LuceneConnection
-
- All Implemented Interfaces:
ILuceneConnection,LuceneAccessor
public class LuceneConnection extends Object implements ILuceneConnection, LuceneAccessor
The implementation ofILuceneConnectionthat allows concurrent searching/reading and writing/deleting. Concurrent writes and deletes block each other. This class optimizes use of Lucene reader instances by holding a common IndexReader that is shared by idempotent operations on an unmodified index. Any mutative operations cause the current IndexReader to be cleared, and subsequent reads will see the results of the previous index change.- Since:
- 8.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.atlassian.confluence.internal.search.v2.lucene.ILuceneConnection
ILuceneConnection.BatchUpdateAction, ILuceneConnection.Configuration, ILuceneConnection.ReaderAction, ILuceneConnection.SearcherAction, ILuceneConnection.SearcherWithTokenAction<T>, ILuceneConnection.WriterAction
-
-
Field Summary
-
Fields inherited from interface com.atlassian.confluence.internal.search.v2.lucene.ILuceneConnection
DEFAULT_CONFIGURATION
-
-
Constructor Summary
Constructors Constructor Description LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer)LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration)LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation)LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation, LuceneIndexMetrics metrics)LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer)LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration)LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation)LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation, LuceneIndexMetrics metrics)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the reader and the writer.voidcloseWriter()Closes the writervoidexecute(Consumer<org.apache.lucene.index.IndexWriter> writerAction)org.apache.lucene.analysis.AnalyzergetAnalyzer()intgetNumDocs()Returns the number ofdocumentsin the index.PathgetPath()ScheduledExecutorServicegetScheduledExecutorService()org.apache.lucene.search.SearcherLifetimeManagergetSearcherLifetimeManager()org.apache.lucene.search.SearcherManagergetSearcherManager()voidoptimize()Blocks and waits until all write operations to the index complete.voidreset(Runnable resetAction)Closes the reader and the writer and create new ones.voidsnapshot(org.apache.lucene.store.Directory destDir)Allows taking a snapshot of the index.voidtruncateIndex()Removes all documents from the index.voidwithBatchUpdate(ILuceneConnection.BatchUpdateAction action)Blocks and waits until all write operations to the index complete.ObjectwithReader(ILuceneConnection.ReaderAction action)Idempotent operation.voidwithSearch(ILuceneConnection.SearcherAction action)This implementation does not respect the boolean return of the of theILuceneConnection.SearcherAction.perform(IndexSearcher)method<T> TwithSearcher(long searchToken, ILuceneConnection.SearcherWithTokenAction<T> action)Perform a search with the specified search token.<T> TwithSearcher(ILuceneConnection.SearcherWithTokenAction<T> action)Perform a search that can be later continued via the search token passed toILuceneConnection.SearcherWithTokenAction.perform(IndexSearcher, long).voidwithWriter(ILuceneConnection.WriterAction action)Blocks and waits until all write operations to the index complete.
-
-
-
Constructor Detail
-
LuceneConnection
public LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation, LuceneIndexMetrics metrics)
-
LuceneConnection
public LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation)
-
LuceneConnection
public LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration)
-
LuceneConnection
public LuceneConnection(org.apache.lucene.store.Directory directory, org.apache.lucene.analysis.Analyzer analyzer)
-
LuceneConnection
public LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation, LuceneIndexMetrics metrics)
-
LuceneConnection
public LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration, SearcherInitialisation searcherInitialisation)
-
LuceneConnection
public LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer, ILuceneConnection.Configuration configuration)
-
LuceneConnection
public LuceneConnection(File path, org.apache.lucene.analysis.Analyzer analyzer)
-
-
Method Detail
-
getNumDocs
public int getNumDocs()
Description copied from interface:ILuceneConnectionReturns the number ofdocumentsin the index.- Specified by:
getNumDocsin interfaceILuceneConnection
-
optimize
public void optimize() throws LuceneExceptionBlocks and waits until all write operations to the index complete. Optimizes the index while holding the write lock to ensure no concurrent modifications. Optimize is done using interactive mode configuration.- Specified by:
optimizein interfaceILuceneConnection- Throws:
LuceneException
-
close
public void close() throws LuceneExceptionDescription copied from interface:ILuceneConnectionCloses the reader and the writer. Calling any method on the API after closing the connection will throwLuceneConnectionClosedException.- Specified by:
closein interfaceILuceneConnection- Specified by:
closein interfaceLuceneAccessor- Throws:
LuceneException
-
closeWriter
public void closeWriter() throws LuceneExceptionDescription copied from interface:ILuceneConnectionCloses the writer- Specified by:
closeWriterin interfaceILuceneConnection- Throws:
LuceneException
-
withSearch
public void withSearch(ILuceneConnection.SearcherAction action) throws LuceneException
This implementation does not respect the boolean return of the of theILuceneConnection.SearcherAction.perform(IndexSearcher)method- Specified by:
withSearchin interfaceILuceneConnection- Throws:
LuceneException
-
withSearcher
public <T> T withSearcher(ILuceneConnection.SearcherWithTokenAction<T> action) throws LuceneException
Description copied from interface:ILuceneConnectionPerform a search that can be later continued via the search token passed to
ILuceneConnection.SearcherWithTokenAction.perform(IndexSearcher, long).You may want to continue the search by requesting the next page of results, or refining the search with additional parameters. The token guarantees that the search will be conducted on a particular version of the index.
- Specified by:
withSearcherin interfaceILuceneConnection- Type Parameters:
T- the return type of the searcher action callback- Parameters:
action- the search action to perform- Returns:
- result of the search
- Throws:
LuceneException
-
withSearcher
public <T> T withSearcher(long searchToken, ILuceneConnection.SearcherWithTokenAction<T> action) throws SearchTokenExpiredExceptionDescription copied from interface:ILuceneConnectionPerform a search with the specified search token.- Specified by:
withSearcherin interfaceILuceneConnection- Type Parameters:
T- the return type of the searcher action callback- Parameters:
searchToken- a search token that identifies a version of the index to search.action- the search action to perform- Returns:
- result of the search
- Throws:
SearchTokenExpiredException- if the specified search token has expired. Clients should report the error to the user and / or retry the search with a new token.
-
withReader
public Object withReader(ILuceneConnection.ReaderAction action) throws LuceneException
Description copied from interface:ILuceneConnectionIdempotent operation. Just for querying, do not delete documents with this action. UseILuceneConnection.withWriter(WriterAction)to perform index deletes.- Specified by:
withReaderin interfaceILuceneConnection- Throws:
LuceneException
-
withWriter
public void withWriter(ILuceneConnection.WriterAction action) throws LuceneException
Blocks and waits until all write operations to the index complete. Executes the WriterAction while holding the write lock to ensure no concurrent modifications.- Specified by:
withWriterin interfaceILuceneConnection- Throws:
LuceneException
-
withBatchUpdate
public void withBatchUpdate(ILuceneConnection.BatchUpdateAction action)
Blocks and waits until all write operations to the index complete. Executes the BatchUpdateAction while holding the write lock to ensure no concurrent modifications. Note: This method holds the writeLock for the whole operation, so is used to ensure a set of deletes and writes are effectively executed atomically. Refreshes the searcher only once, at the end of the batch update action.- Specified by:
withBatchUpdatein interfaceILuceneConnection
-
truncateIndex
public void truncateIndex() throws LuceneExceptionDescription copied from interface:ILuceneConnectionRemoves all documents from the index.- Specified by:
truncateIndexin interfaceILuceneConnection- Throws:
LuceneException- if there was a problem removing the index
-
snapshot
public void snapshot(org.apache.lucene.store.Directory destDir) throws IOExceptionDescription copied from interface:ILuceneConnectionAllows taking a snapshot of the index.- Specified by:
snapshotin interfaceILuceneConnection- Specified by:
snapshotin interfaceLuceneAccessor- Parameters:
destDir- directory in which the snapshot should be saved- Throws:
IOException
-
reset
public void reset(Runnable resetAction) throws LuceneException
Description copied from interface:ILuceneConnectionCloses the reader and the writer and create new ones.- Specified by:
resetin interfaceILuceneConnection- Specified by:
resetin interfaceLuceneAccessor- Parameters:
resetAction- action that should be executed before the reset- Throws:
LuceneException
-
getScheduledExecutorService
public ScheduledExecutorService getScheduledExecutorService()
-
getAnalyzer
public org.apache.lucene.analysis.Analyzer getAnalyzer()
- Specified by:
getAnalyzerin interfaceLuceneAccessor
-
execute
public void execute(Consumer<org.apache.lucene.index.IndexWriter> writerAction)
- Specified by:
executein interfaceLuceneAccessor
-
getSearcherManager
public org.apache.lucene.search.SearcherManager getSearcherManager()
- Specified by:
getSearcherManagerin interfaceLuceneAccessor
-
getSearcherLifetimeManager
public org.apache.lucene.search.SearcherLifetimeManager getSearcherLifetimeManager()
- Specified by:
getSearcherLifetimeManagerin interfaceLuceneAccessor
-
getPath
public Path getPath()
- Specified by:
getPathin interfaceLuceneAccessor
-
-