Class LuceneConnection
java.lang.Object
com.atlassian.confluence.internal.search.v2.lucene.LuceneConnection
- All Implemented Interfaces:
ILuceneConnection
,LuceneAccessor
The implementation of
ILuceneConnection
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
ConstructorsConstructorDescriptionLuceneConnection
(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
Modifier and TypeMethodDescriptionvoid
close()
Closes the reader and the writer.void
Closes the writervoid
org.apache.lucene.analysis.Analyzer
int
Returns the number ofdocuments
in the index.getPath()
org.apache.lucene.search.SearcherLifetimeManager
org.apache.lucene.search.SearcherManager
long
Get total size of the index in bytes.void
optimize()
Blocks and waits until all write operations to the index complete.void
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
Removes all documents from the index.void
Blocks and waits until all write operations to the index complete.Idempotent operation.void
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
Perform a search that can be later continued via the search token passed toILuceneConnection.SearcherWithTokenAction.perform(IndexSearcher, long)
.void
Blocks and waits until all write operations to the index complete.
-
Constructor Details
-
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
-
-
Method Details
-
getNumDocs
public int getNumDocs()Description copied from interface:ILuceneConnection
Returns the number ofdocuments
in the index.- Specified by:
getNumDocs
in interfaceILuceneConnection
-
getSizeInBytes
Description copied from interface:ILuceneConnection
Get total size of the index in bytes.- Specified by:
getSizeInBytes
in interfaceILuceneConnection
- Returns:
- size of the index in bytes
- Throws:
IOException
-
optimize
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
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
Description copied from interface:ILuceneConnection
Closes the writer- Specified by:
closeWriter
in interfaceILuceneConnection
- Throws:
LuceneException
-
withSearch
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
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
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
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
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
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
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
-
getAnalyzer
public org.apache.lucene.analysis.Analyzer getAnalyzer()- Specified by:
getAnalyzer
in interfaceLuceneAccessor
-
execute
- 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
- Specified by:
getPath
in interfaceLuceneAccessor
-