|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.search.ReferenceManager<IndexSearcher> org.apache.lucene.search.SearcherManager
public final class SearcherManager
Utility class to safely share IndexSearcher
instances across multiple
threads, while periodically reopening. This class ensures each searcher is
closed only once all threads have finished using it.
Use ReferenceManager.acquire()
to obtain the current searcher, and ReferenceManager.release(G)
to
release it, like this:
IndexSearcher s = manager.acquire(); try { // Do searching, doc retrieval, etc. with s } finally { manager.release(s); } // Do not use s after this! s = null;
In addition you should periodically call ReferenceManager.maybeRefresh()
. While it's
possible to call this just before running each query, this is discouraged
since it penalizes the unlucky queries that do the reopen. It's better to use
a separate background thread, that periodically calls maybeReopen. Finally,
be sure to call ReferenceManager.close()
once you are done.
SearcherFactory
Field Summary |
---|
Fields inherited from class org.apache.lucene.search.ReferenceManager |
---|
current |
Constructor Summary | |
---|---|
SearcherManager(Directory dir,
SearcherFactory searcherFactory)
Creates and returns a new SearcherManager from the given Directory . |
|
SearcherManager(IndexWriter writer,
boolean applyAllDeletes,
SearcherFactory searcherFactory)
Creates and returns a new SearcherManager from the given IndexWriter . |
Method Summary | |
---|---|
protected void |
decRef(IndexSearcher reference)
Decrement reference counting on the given reference. |
boolean |
isSearcherCurrent()
Returns true if no changes have occured since this searcher
ie. |
boolean |
maybeReopen()
Deprecated. see ReferenceManager.maybeRefresh() . |
protected IndexSearcher |
refreshIfNeeded(IndexSearcher referenceToRefresh)
Refresh the given reference if needed. |
protected boolean |
tryIncRef(IndexSearcher reference)
Try to increment reference counting on the given reference. |
Methods inherited from class org.apache.lucene.search.ReferenceManager |
---|
acquire, afterClose, afterRefresh, close, maybeRefresh, release |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SearcherManager(IndexWriter writer, boolean applyAllDeletes, SearcherFactory searcherFactory) throws IOException
IndexWriter
.
writer
- the IndexWriter to open the IndexReader from.applyAllDeletes
- If true
, all buffered deletes will
be applied (made visible) in the IndexSearcher
/ IndexReader
.
If false
, the deletes may or may not be applied, but remain buffered
(in IndexWriter) so that they will be applied in the future.
Applying deletes can be costly, so if your app can tolerate deleted documents
being returned you might gain some performance by passing false
.
See IndexReader.openIfChanged(IndexReader, IndexWriter, boolean)
.searcherFactory
- An optional SearcherFactory
. Pass
null
if you don't require the searcher to be warmed
before going live or other custom behavior.
IOException
public SearcherManager(Directory dir, SearcherFactory searcherFactory) throws IOException
Directory
.
dir
- the directory to open the DirectoryReader on.searcherFactory
- An optional SearcherFactory
. Pass
null
if you don't require the searcher to be warmed
before going live or other custom behavior.
IOException
Method Detail |
---|
protected void decRef(IndexSearcher reference) throws IOException
ReferenceManager
decRef
in class ReferenceManager<IndexSearcher>
IOException
protected IndexSearcher refreshIfNeeded(IndexSearcher referenceToRefresh) throws IOException
ReferenceManager
null
if no refresh
was needed, otherwise a new refreshed reference.
refreshIfNeeded
in class ReferenceManager<IndexSearcher>
IOException
protected boolean tryIncRef(IndexSearcher reference)
ReferenceManager
tryIncRef
in class ReferenceManager<IndexSearcher>
@Deprecated public boolean maybeReopen() throws IOException
ReferenceManager.maybeRefresh()
.
IOException
public boolean isSearcherCurrent() throws IOException
true
if no changes have occured since this searcher
ie. reader was opened, otherwise false
.
IOException
IndexReader.isCurrent()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |