## org.apache.lucene.index
Class NRTManager

    java.lang.Object
      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(org.apache.lucene.index.IndexWriter writer)` Create new NRTManager.
`NRTManager(org.apache.lucene.index.IndexWriter writer, ExecutorService es)` Create new NRTManager.

Method Summary
`long` `addDocument(org.apache.lucene.document.Document d)`
`long` `addDocument(org.apache.lucene.document.Document d, org.apache.lucene.analysis.Analyzer a)`
`long` `addDocuments(Collection<org.apache.lucene.document.Document> docs)`
`long` `addDocuments(Collection<org.apache.lucene.document.Document> docs, org.apache.lucene.analysis.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(org.apache.lucene.search.Query q)`
`long` `deleteDocuments(org.apache.lucene.index.Term t)`
`org.apache.lucene.search.IndexSearcher` `get()` Returns the most current searcher.
`org.apache.lucene.search.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.
`org.apache.lucene.search.IndexSearcher` `get(long targetGen)` Call this if you require a searcher reflecting all changes as of the target generation.
`org.apache.lucene.search.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(org.apache.lucene.search.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(org.apache.lucene.index.Term t, org.apache.lucene.document.Document d)`
`long` `updateDocument(org.apache.lucene.index.Term t, org.apache.lucene.document.Document d, org.apache.lucene.analysis.Analyzer a)`
`long` `updateDocuments(org.apache.lucene.index.Term t, Collection<org.apache.lucene.document.Document> docs)`
`long` `updateDocuments(org.apache.lucene.index.Term t, Collection<org.apache.lucene.document.Document> docs, org.apache.lucene.analysis.Analyzer a)`
`protected void` `warm(org.apache.lucene.index.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(org.apache.lucene.index.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(org.apache.lucene.index.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(org.apache.lucene.index.Term t,
                               org.apache.lucene.document.Document d,
                               org.apache.lucene.analysis.Analyzer a)
                        throws IOException

  Throws:
    `IOException`

### updateDocument

    public long updateDocument(org.apache.lucene.index.Term t,
                               org.apache.lucene.document.Document d)
                        throws IOException

  Throws:
    `IOException`

### updateDocuments

    public long updateDocuments(org.apache.lucene.index.Term t,
                                Collection<org.apache.lucene.document.Document> docs,
                                org.apache.lucene.analysis.Analyzer a)
                         throws IOException

  Throws:
    `IOException`

### updateDocuments

    public long updateDocuments(org.apache.lucene.index.Term t,
                                Collection<org.apache.lucene.document.Document> docs)
                         throws IOException

  Throws:
    `IOException`

### deleteDocuments

    public long deleteDocuments(org.apache.lucene.index.Term t)
                         throws IOException

  Throws:
    `IOException`

### deleteDocuments

    public long deleteDocuments(org.apache.lucene.search.Query q)
                         throws IOException

  Throws:
    `IOException`

### addDocument

    public long addDocument(org.apache.lucene.document.Document d,
                            org.apache.lucene.analysis.Analyzer a)
                     throws IOException

  Throws:
    `IOException`

### addDocuments

    public long addDocuments(Collection<org.apache.lucene.document.Document> docs,
                             org.apache.lucene.analysis.Analyzer a)
                      throws IOException

  Throws:
    `IOException`

### addDocument

    public long addDocument(org.apache.lucene.document.Document d)
                     throws IOException

  Throws:
    `IOException`

### addDocuments

    public long addDocuments(Collection<org.apache.lucene.document.Document> docs)
                      throws IOException

  Throws:
    `IOException`

### get

    public org.apache.lucene.search.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 org.apache.lucene.search.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 org.apache.lucene.search.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 org.apache.lucene.search.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(org.apache.lucene.search.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(org.apache.lucene.index.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.