org.apache.lucene.index
Class NRTManager

java.lang.Object
  extended by org.apache.lucene.index.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 reopen 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.index.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)
          Create new NRTManager.
NRTManager(IndexWriter writer, ExecutorService es)
          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)
           
 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()
          NOTE: caller must separately close the writer.
 long deleteDocuments(Query q)
           
 long deleteDocuments(Term t)
           
 IndexSearcher get()
          Returns the most current searcher.
 IndexSearcher get(boolean requireDeletes)
          Just like get(), but by passing false for requireDeletes, you can get faster reopen time, but the returned reader is allowed to not reflect all deletions.
 IndexSearcher get(long targetGen)
          Call this if you require a searcher reflecting all changes as of the target generation.
 IndexSearcher get(long targetGen, boolean requireDeletes)
          Call this if you require a searcher reflecting all changes as of the target generation, and you don't require deletions to be reflected.
 long getCurrentSearchingGen(boolean requiresDeletes)
          Returns generation of current searcher.
 void release(IndexSearcher s)
          Release the searcher obtained from get() or get(long).
 void removeWaitingListener(NRTManager.WaitingListener l)
          Remove a listener added with addWaitingListener(org.apache.lucene.index.NRTManager.WaitingListener).
 boolean reopen(boolean applyDeletes)
          Call this when you need the NRT reader to reopen.
 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)
           
protected  void warm(IndexReader reader)
          Override this to warm the newly opened reader before it's swapped in.
 
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)
           throws IOException
Create new NRTManager. Note that this installs a merged segment warmer on the provided IndexWriter's config.

Parameters:
writer - IndexWriter to open near-real-time readers
Throws:
IOException

NRTManager

public NRTManager(IndexWriter writer,
                  ExecutorService es)
           throws IOException
Create new NRTManager. Note that this installs a merged segment warmer on the provided IndexWriter's config.

Parameters:
writer - IndexWriter to open near-real-time readers
es - ExecutorService to pass to the IndexSearcher
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.index.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(Query q)
                     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

get

public IndexSearcher get()
Returns the most current searcher. If you require a certain indexing generation be visible in the returned searcher, call get(long) instead.


get

public IndexSearcher get(boolean requireDeletes)
Just like get(), but by passing false for requireDeletes, you can get faster reopen time, but the returned reader is allowed to not reflect all deletions. See IndexReader.open(IndexWriter,boolean)


get

public IndexSearcher get(long targetGen)
Call this if you require a searcher reflecting all changes as of the target generation.

Parameters:
targetGen - Returned searcher must reflect changes as of this generation

get

public IndexSearcher get(long targetGen,
                         boolean requireDeletes)
Call this if you require a searcher reflecting all changes as of the target generation, and you don't require deletions to be reflected. Note that the returned searcher may still reflect some or all deletions.

Parameters:
targetGen - Returned searcher must reflect changes as of this generation
requireDeletes - If true, the returned searcher must reflect all deletions. This can be substantially more costly than not applying deletes. Note that if you pass false, it's still possible that some or all deletes may have been applied.

getCurrentSearchingGen

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


release

public void release(IndexSearcher s)
             throws IOException
Release the searcher obtained from get() or get(long).

Throws:
IOException

reopen

public boolean reopen(boolean applyDeletes)
               throws IOException
Call this when you need the NRT reader to reopen.

Parameters:
applyDeletes - If true, the newly opened reader will reflect all deletes
Throws:
IOException

warm

protected void warm(IndexReader reader)
             throws IOException
Override this to warm the newly opened reader before it's swapped in. Note that this is called both for newly merged segments and for new top-level readers opened by #reopen.

Throws:
IOException

close

public void close()
           throws IOException
NOTE: caller must separately close the writer.

Specified by:
close in interface Closeable
Throws:
IOException


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