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 ofILuceneConnection
that 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 void
close()
Closes the reader and the writer.void
closeWriter()
Closes the writervoid
execute(Consumer<org.apache.lucene.index.IndexWriter> writerAction)
org.apache.lucene.analysis.Analyzer
getAnalyzer()
int
getNumDocs()
Returns the number ofdocuments
in the index.Path
getPath()
ScheduledExecutorService
getScheduledExecutorService()
org.apache.lucene.search.SearcherLifetimeManager
getSearcherLifetimeManager()
org.apache.lucene.search.SearcherManager
getSearcherManager()
void
optimize()
Blocks and waits until all write operations to the index complete.void
reset(Runnable resetAction)
Closes the reader and the writer and create new ones.void
snapshot(org.apache.lucene.store.Directory destDir)
Allows taking a snapshot of the index.void
truncateIndex()
Removes all documents from the index.void
withBatchUpdate(ILuceneConnection.BatchUpdateAction action)
Blocks and waits until all write operations to the index complete.Object
withReader(ILuceneConnection.ReaderAction action)
Idempotent operation.void
withSearch(ILuceneConnection.SearcherAction action)
This implementation does not respect the boolean return of the of theILuceneConnection.SearcherAction.perform(IndexSearcher)
method<T> T
withSearcher(long searchToken, ILuceneConnection.SearcherWithTokenAction<T> action)
Perform a search with the specified search token.<T> T
withSearcher(ILuceneConnection.SearcherWithTokenAction<T> action)
Perform a search that can be later continued via the search token passed toILuceneConnection.SearcherWithTokenAction.perform(IndexSearcher, long)
.void
withWriter(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:ILuceneConnection
Returns the number ofdocuments
in the index.- Specified by:
getNumDocs
in interfaceILuceneConnection
-
optimize
public void optimize() throws LuceneException
Blocks 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:
optimize
in interfaceILuceneConnection
- Throws:
LuceneException
-
close
public void close() throws LuceneException
Description copied from interface:ILuceneConnection
Closes the reader and the writer. Calling any method on the API after closing the connection will throwLuceneConnectionClosedException
.- Specified by:
close
in interfaceILuceneConnection
- Specified by:
close
in interfaceLuceneAccessor
- Throws:
LuceneException
-
closeWriter
public void closeWriter() throws LuceneException
Description copied from interface:ILuceneConnection
Closes the writer- Specified by:
closeWriter
in 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:
withSearch
in interfaceILuceneConnection
- Throws:
LuceneException
-
withSearcher
public <T> T withSearcher(ILuceneConnection.SearcherWithTokenAction<T> action) throws LuceneException
Description copied from interface:ILuceneConnection
Perform 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:
withSearcher
in 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 SearchTokenExpiredException
Description copied from interface:ILuceneConnection
Perform a search with the specified search token.- Specified by:
withSearcher
in 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:ILuceneConnection
Idempotent operation. Just for querying, do not delete documents with this action. UseILuceneConnection.withWriter(WriterAction)
to perform index deletes.- Specified by:
withReader
in 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:
withWriter
in 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:
withBatchUpdate
in interfaceILuceneConnection
-
truncateIndex
public void truncateIndex() throws LuceneException
Description copied from interface:ILuceneConnection
Removes all documents from the index.- Specified by:
truncateIndex
in interfaceILuceneConnection
- Throws:
LuceneException
- if there was a problem removing the index
-
snapshot
public void snapshot(org.apache.lucene.store.Directory destDir) throws IOException
Description copied from interface:ILuceneConnection
Allows taking a snapshot of the index.- Specified by:
snapshot
in interfaceILuceneConnection
- Specified by:
snapshot
in 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:ILuceneConnection
Closes the reader and the writer and create new ones.- Specified by:
reset
in interfaceILuceneConnection
- Specified by:
reset
in 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:
getAnalyzer
in interfaceLuceneAccessor
-
execute
public void execute(Consumer<org.apache.lucene.index.IndexWriter> writerAction)
- Specified by:
execute
in interfaceLuceneAccessor
-
getSearcherManager
public org.apache.lucene.search.SearcherManager getSearcherManager()
- Specified by:
getSearcherManager
in interfaceLuceneAccessor
-
getSearcherLifetimeManager
public org.apache.lucene.search.SearcherLifetimeManager getSearcherLifetimeManager()
- Specified by:
getSearcherLifetimeManager
in interfaceLuceneAccessor
-
getPath
public Path getPath()
- Specified by:
getPath
in interfaceLuceneAccessor
-
-