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 TypeMethodDescriptionvoidclose()Closes the reader and the writer.voidCloses the writervoidorg.apache.lucene.analysis.AnalyzerintReturns the number ofdocumentsin the index.getPath()org.apache.lucene.search.SearcherLifetimeManagerorg.apache.lucene.search.SearcherManagerlongGet total size of the index in bytes.voidoptimize()Blocks and waits until all write operations to the index complete.voidCloses the reader and the writer and create new ones.voidsnapshot(org.apache.lucene.store.Directory destDir) Allows taking a snapshot of the index.voidRemoves all documents from the index.voidBlocks and waits until all write operations to the index complete.Idempotent operation.voidThis 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> TPerform a search that can be later continued via the search token passed toILuceneConnection.SearcherWithTokenAction.perform(IndexSearcher, long).voidBlocks 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:ILuceneConnectionReturns the number ofdocumentsin the index.- Specified by:
getNumDocsin interfaceILuceneConnection
-
getSizeInBytes
Description copied from interface:ILuceneConnectionGet total size of the index in bytes.- Specified by:
getSizeInBytesin 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:
optimizein interfaceILuceneConnection- Throws:
LuceneException
-
close
Description 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
Description copied from interface:ILuceneConnectionCloses the writer- Specified by:
closeWriterin interfaceILuceneConnection- Throws:
LuceneException
-
withSearch
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 SearchTokenExpiredException Description 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
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
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
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
Description copied from interface:ILuceneConnectionRemoves all documents from the index.- Specified by:
truncateIndexin interfaceILuceneConnection- Throws:
LuceneException- if there was a problem removing the index
-
snapshot
Description 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
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
-
getAnalyzer
public org.apache.lucene.analysis.Analyzer getAnalyzer()- Specified by:
getAnalyzerin interfaceLuceneAccessor
-
execute
- 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
- Specified by:
getPathin interfaceLuceneAccessor
-