public final class NRTManager extends ReferenceManager<IndexSearcher>
You must create an IndexWriter, then create a NRTManager.TrackingIndexWriter
from it, and pass that to the
NRTManager. You may want to create two NRTManagers, once
that always applies deletes on refresh and one that does
not. In this case you should use a single NRTManager.TrackingIndexWriter
instance for both.
Then, use ReferenceManager.acquire()
to obtain the
IndexSearcher
, and ReferenceManager.release(G)
(ideally,
from within a finally
clause) to release it.
NOTE: to use this class, you must call ReferenceManager.maybeRefresh()
periodically. The NRTManagerReopenThread
is a
simple class to do this on a periodic basis, and reopens
more quickly if a request is waiting. If you implement
your own reopener, be sure to call addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener)
so your reopener is notified when a
caller is waiting for a specific generation
searcher.
SearcherFactory
Modifier and Type | Class and Description |
---|---|
static class |
NRTManager.TrackingIndexWriter
Class that tracks changes to a delegated
IndexWriter.
|
static interface |
NRTManager.WaitingListener
NRTManager invokes this interface to notify it when a
caller is waiting for a specific generation searcher
to be visible.
|
ReferenceManager.RefreshListener
current
Constructor and Description |
---|
NRTManager(NRTManager.TrackingIndexWriter writer,
SearcherFactory searcherFactory)
Create new NRTManager.
|
NRTManager(NRTManager.TrackingIndexWriter writer,
SearcherFactory searcherFactory,
boolean applyAllDeletes)
Expert: just like
NRTManager(TrackingIndexWriter,SearcherFactory) ,
but you can also specify whether each reopened searcher must
apply deletes. |
Modifier and Type | Method and Description |
---|---|
void |
addWaitingListener(NRTManager.WaitingListener l)
Adds a listener, to be notified when a caller is
waiting for a specific generation searcher to be
visible.
|
protected void |
afterClose()
Called after close(), so subclass can free any resources.
|
protected void |
afterMaybeRefresh()
Called after a refresh was attempted, regardless of
whether a new reference was in fact created.
|
protected void |
decRef(IndexSearcher reference)
Decrement reference counting on the given reference.
|
long |
getCurrentSearchingGen()
Returns generation of current searcher.
|
boolean |
isSearcherCurrent()
Returns
true if no changes have occured since this searcher
ie. |
protected IndexSearcher |
refreshIfNeeded(IndexSearcher referenceToRefresh)
Refresh the given reference if needed.
|
void |
removeWaitingListener(NRTManager.WaitingListener l)
Remove a listener added with
addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener) . |
protected boolean |
tryIncRef(IndexSearcher reference)
Try to increment reference counting on the given reference.
|
void |
waitForGeneration(long targetGen)
Waits for the target generation to become visible in
the searcher.
|
void |
waitForGeneration(long targetGen,
long time,
TimeUnit unit)
Waits for the target generation to become visible in
the searcher.
|
acquire, addListener, close, maybeRefresh, maybeRefreshBlocking, release, removeListener
public NRTManager(NRTManager.TrackingIndexWriter writer, SearcherFactory searcherFactory) throws IOException
writer
- TrackingIndexWriter to open near-real-time
readerssearcherFactory
- An optional SearcherFactory
. Pass
null
if you don't require the searcher to be warmed
before going live or other custom behavior.IOException
public NRTManager(NRTManager.TrackingIndexWriter writer, SearcherFactory searcherFactory, boolean applyAllDeletes) throws IOException
NRTManager(TrackingIndexWriter,SearcherFactory)
,
but you can also specify whether each reopened searcher must
apply deletes. This is useful for cases where certain
uses can tolerate seeing some deleted docs, since
reopen time is faster if deletes need not be applied.IOException
protected void decRef(IndexSearcher reference) throws IOException
ReferenceManager
decRef
in class ReferenceManager<IndexSearcher>
IOException
- if reference decrement on the given resource failed.protected boolean tryIncRef(IndexSearcher reference)
ReferenceManager
tryIncRef
in class ReferenceManager<IndexSearcher>
public void addWaitingListener(NRTManager.WaitingListener l)
public void removeWaitingListener(NRTManager.WaitingListener l)
addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener)
.public void waitForGeneration(long targetGen)
ReferenceManager.maybeRefresh()
or until the NRTManager
is closed.targetGen
- the generation to wait forpublic void waitForGeneration(long targetGen, long time, TimeUnit unit)
ReferenceManager.maybeRefresh()
, the given waiting time has elapsed, or until
the NRTManager is closed.
NOTE: if the waiting time elapses before the requested target generation is
available the current SearcherManager
is returned instead.
targetGen
- the generation to wait fortime
- the time to wait for the target generationunit
- the waiting time's time unitpublic long getCurrentSearchingGen()
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
- if the refresh operation failedprotected void afterMaybeRefresh()
ReferenceManager
afterMaybeRefresh
in class ReferenceManager<IndexSearcher>
protected void afterClose() throws IOException
ReferenceManager
afterClose
in class ReferenceManager<IndexSearcher>
IOException
- if the after close operation in a sub-class throws an IOException
public boolean isSearcherCurrent() throws IOException
true
if no changes have occured since this searcher
ie. reader was opened, otherwise false
.IOException
DirectoryReader.isCurrent()
Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.