org.apache.lucene.search
Class NRTManager

java.lang.Object
  extended by org.apache.lucene.search.NRTManager
All Implemented Interfaces:
Closeable

public class NRTManager
extends Object
implements Closeable

Utility class to manage sharing near-real-time searchers across multiple searching threads.

NOTE: to use this class, you must call maybeReopen(boolean) periodically. The NRTManagerReopenThread is a simple class to do this on a periodic basis. 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.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Nested Class Summary
static interface NRTManager.WaitingListener
          NRTManager invokes this interface to notify it when a caller is waiting for a specific generation searcher to be visible.
 
Constructor Summary
NRTManager(IndexWriter writer, ExecutorService es, SearcherWarmer warmer)
          Create new NRTManager.
NRTManager(IndexWriter writer, ExecutorService es, SearcherWarmer warmer, boolean alwaysApplyDeletes)
          Expert: just like NRTManager(IndexWriter,ExecutorService,SearcherWarmer), but you can also specify whether every searcher must apply deletes.
NRTManager(IndexWriter writer, SearcherWarmer warmer)
          Create new NRTManager.
 
Method Summary
 long addDocument(Document d)
           
 long addDocument(Document d, Analyzer a)
           
 long addDocuments(Collection<Document> docs)
           
 long addDocuments(Collection<Document> docs, Analyzer a)
           
 long addIndexes(Directory... dirs)
           
 long addIndexes(IndexReader... readers)
           
 void addWaitingListener(NRTManager.WaitingListener l)
          Adds a listener, to be notified when a caller is waiting for a specific generation searcher to be visible.
 void close()
          Close this NRTManager to future searching.
 long deleteAll()
           
 long deleteDocuments(Query... queries)
           
 long deleteDocuments(Query q)
           
 long deleteDocuments(Term... terms)
           
 long deleteDocuments(Term t)
           
 long getCurrentSearchingGen(boolean applyAllDeletes)
          Returns generation of current searcher.
 SearcherManager getSearcherManager(boolean applyAllDeletes)
          Returns a SearcherManager.
 boolean maybeReopen(boolean applyAllDeletes)
           
 void removeWaitingListener(NRTManager.WaitingListener l)
          Remove a listener added with addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener).
 long updateDocument(Term t, Document d)
           
 long updateDocument(Term t, Document d, Analyzer a)
           
 long updateDocuments(Term t, Collection<Document> docs)
           
 long updateDocuments(Term t, Collection<Document> docs, Analyzer a)
           
 SearcherManager waitForGeneration(long targetGen, boolean requireDeletes)
          Waits for a given SearcherManager target generation to be available via getSearcherManager(boolean).
 SearcherManager waitForGeneration(long targetGen, boolean requireDeletes, long time, TimeUnit unit)
          Waits for a given SearcherManager target generation to be available via getSearcherManager(boolean).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NRTManager

public NRTManager(IndexWriter writer,
                  SearcherWarmer warmer)
           throws IOException
Create new NRTManager.

Parameters:
writer - IndexWriter to open near-real-time readers
warmer - optional SearcherWarmer. Pass null if you don't require the searcher to warmed before going live. If this is non-null then a merged segment warmer is installed on the provided IndexWriter's config.

NOTE: the provided SearcherWarmer is not invoked for the initial searcher; you should warm it yourself if necessary.

Throws:
IOException

NRTManager

public NRTManager(IndexWriter writer,
                  ExecutorService es,
                  SearcherWarmer warmer)
           throws IOException
Create new NRTManager.

Parameters:
writer - IndexWriter to open near-real-time readers
es - optional ExecutorService so different segments can be searched concurrently (see IndexSearcher.IndexSearcher(IndexReader, ExecutorService). Pass null to search segments sequentially.
warmer - optional SearcherWarmer. Pass null if you don't require the searcher to warmed before going live. If this is non-null then a merged segment warmer is installed on the provided IndexWriter's config.

NOTE: the provided SearcherWarmer is not invoked for the initial searcher; you should warm it yourself if necessary.

Throws:
IOException

NRTManager

public NRTManager(IndexWriter writer,
                  ExecutorService es,
                  SearcherWarmer warmer,
                  boolean alwaysApplyDeletes)
           throws IOException
Expert: just like NRTManager(IndexWriter,ExecutorService,SearcherWarmer), but you can also specify whether every 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.

Throws:
IOException
Method Detail

addWaitingListener

public void addWaitingListener(NRTManager.WaitingListener l)
Adds a listener, to be notified when a caller is waiting for a specific generation searcher to be visible.


removeWaitingListener

public void removeWaitingListener(NRTManager.WaitingListener l)
Remove a listener added with addWaitingListener(org.apache.lucene.search.NRTManager.WaitingListener).


updateDocument

public long updateDocument(Term t,
                           Document d,
                           Analyzer a)
                    throws IOException
Throws:
IOException

updateDocument

public long updateDocument(Term t,
                           Document d)
                    throws IOException
Throws:
IOException

updateDocuments

public long updateDocuments(Term t,
                            Collection<Document> docs,
                            Analyzer a)
                     throws IOException
Throws:
IOException

updateDocuments

public long updateDocuments(Term t,
                            Collection<Document> docs)
                     throws IOException
Throws:
IOException

deleteDocuments

public long deleteDocuments(Term t)
                     throws IOException
Throws:
IOException

deleteDocuments

public long deleteDocuments(Term... terms)
                     throws IOException
Throws:
IOException

deleteDocuments

public long deleteDocuments(Query q)
                     throws IOException
Throws:
IOException

deleteDocuments

public long deleteDocuments(Query... queries)
                     throws IOException
Throws:
IOException

deleteAll

public long deleteAll()
               throws IOException
Throws:
IOException

addDocument

public long addDocument(Document d,
                        Analyzer a)
                 throws IOException
Throws:
IOException

addDocuments

public long addDocuments(Collection<Document> docs,
                         Analyzer a)
                  throws IOException
Throws:
IOException

addDocument

public long addDocument(Document d)
                 throws IOException
Throws:
IOException

addDocuments

public long addDocuments(Collection<Document> docs)
                  throws IOException
Throws:
IOException

addIndexes

public long addIndexes(Directory... dirs)
                throws CorruptIndexException,
                       IOException
Throws:
CorruptIndexException
IOException

addIndexes

public long addIndexes(IndexReader... readers)
                throws CorruptIndexException,
                       IOException
Throws:
CorruptIndexException
IOException

waitForGeneration

public SearcherManager waitForGeneration(long targetGen,
                                         boolean requireDeletes)
Waits for a given SearcherManager target generation to be available via getSearcherManager(boolean). If the current generation is less than the given target generation this method will block until the correspondent SearcherManager is reopened by another thread via maybeReopen(boolean) or until the NRTManager is closed.

Parameters:
targetGen - the generation to wait for
requireDeletes - true iff the generation requires deletes to be applied otherwise false
Returns:
the SearcherManager with the given target generation

waitForGeneration

public SearcherManager waitForGeneration(long targetGen,
                                         boolean requireDeletes,
                                         long time,
                                         TimeUnit unit)
Waits for a given SearcherManager target generation to be available via getSearcherManager(boolean). If the current generation is less than the given target generation this method will block until the correspondent SearcherManager is reopened by another thread via maybeReopen(boolean), 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 latest SearcherManager is returned instead.

Parameters:
targetGen - the generation to wait for
requireDeletes - true iff the generation requires deletes to be applied otherwise false
time - the time to wait for the target generation
unit - the waiting time's time unit
Returns:
the SearcherManager with the given target generation or the latest SearcherManager if the waiting time elapsed before the requested generation is available.

getCurrentSearchingGen

public long getCurrentSearchingGen(boolean applyAllDeletes)
Returns generation of current searcher.


maybeReopen

public boolean maybeReopen(boolean applyAllDeletes)
                    throws IOException
Throws:
IOException

close

public void close()
           throws IOException
Close this NRTManager to future searching. Any searches still in process in other threads won't be affected, and they should still call SearcherManager.release(IndexSearcher) after they are done.

NOTE: caller must separately close the writer.

Specified by:
close in interface Closeable
Throws:
IOException

getSearcherManager

public SearcherManager getSearcherManager(boolean applyAllDeletes)
Returns a SearcherManager. If applyAllDeletes is true the returned manager is guaranteed to have all deletes applied on the last reopen. Otherwise the latest manager with or without deletes is returned.



Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.