A CompositeReader which reads multiple indexes, appending their content. It can be used
to create a view on several sub-readers (like DirectoryReader) and execute searches on
it.
For efficiency, in this API documents are often referred to via document numbers, non-negative integers which each name a unique document in the index. These document numbers are ephemeral -- they may change as documents are added to and deleted from an index. Clients should thus not rely on a given document having the same number between sessions.
NOTE: IndexReader instances are completely thread safe, meaning multiple
threads can call any of its methods, concurrently. If your application requires external
synchronization, you should not synchronize on the IndexReader instance; use
your own (non-Lucene) objects instead.
Construct a MultiReader aggregating the named set of (sub)readers.
Note that all subreaders are closed if this Multireader is closed.
| name | type | description |
|---|---|---|
| sub_readers | org.apache.lucene.index.IndexReader[] | set of (sub)readers |
<init>(org.apache.lucene.index.IndexReader[] subReaders, boolean closeSubReaders)Construct a MultiReader aggregating the named set of (sub)readers.
| name | type | description |
|---|---|---|
| sub_readers | org.apache.lucene.index.IndexReader[] | set of (sub)readers; this array will be cloned. |
| close_sub_readers | boolean | indicates whether the subreaders should be closed when this MultiReader is closed |
<init>(org.apache.lucene.index.IndexReader[] subReaders, Comparator<org.apache.lucene.index.IndexReader> subReadersSorter, boolean closeSubReaders)Construct a MultiReader aggregating the named set of (sub)readers.
| name | type | description |
|---|---|---|
| sub_readers | org.apache.lucene.index.IndexReader[] | set of (sub)readers; this array will be cloned. |
| sub_readers_sorter | Comparator<org.apache.lucene.index.IndexReader> | – a comparator, that if not null is used for sorting sub
readers. |
| close_sub_readers | boolean | indicates whether the subreaders should be closed when this MultiReader is closed |
getReaderCacheHelper() · also: get_reader_cache_helperclose()Closes files associated with this index. Also saves any new deletions to disk. No other methods should be called after this has been called.
| IOException | if there is a low-level IO error | |
decRef()Expert: decreases the refCount of this IndexReader instance. If the refCount drops to 0, then this reader is closed. If an exception is hit, the refCount is unchanged.
| IOException | in case an IOException occurs in doClose() | |
equals(Object obj)
IndexReader subclasses are not allowed to implement equals/hashCode, so methods are
declared final.
hasDeletions() · also: has_deletionsReturns true if any documents have been deleted. Implementers should consider overriding this
method if #maxDoc() or #numDocs() are not constant-time operations.
hashCode()
IndexReader subclasses are not allowed to implement equals/hashCode, so methods are
declared final.
incRef()Expert: increments the refCount of this IndexReader instance. RefCounts are used to determine
when a reader can be closed safely, i.e. as soon as there are no more references. Be sure to
always call a corresponding #decRef, in a finally clause; otherwise the reader may
never be closed. Note that #close simply calls decRef(), which means that the
IndexReader will not really be closed until #decRef has been called for all outstanding
references.
Returns the reader's leaves, or itself if this reader is atomic. This is a convenience method
calling this.getContext().leaves().
numDeletedDocs()Returns the number of deleted documents.
NOTE: This operation may run in O(maxDoc).
getRefCount() · also: get_ref_countExpert: returns the current refCount for this reader
registerParentReader(org.apache.lucene.index.IndexReader reader)Expert: This method is called by IndexReaders which wrap other readers (e.g. CompositeReader or FilterLeafReader) to register the parent at the child (this reader)
on construction of the parent. When this reader is closed, it will mark all registered parents
as closed, too. The references to parent readers are weak only, so they can be GCed once they
are no longer in use.
tryIncRef()Expert: increments the refCount of this IndexReader instance only if the IndexReader has not
been closed yet and returns true iff the refCount was successfully incremented,
otherwise false. If this method returns false the reader is either
already closed or is currently being closed. Either way this reader instance shouldn't be used
by an application unless true is returned.
RefCounts are used to determine when a reader can be closed safely, i.e. as soon as there
are no more references. Be sure to always call a corresponding #decRef, in a finally
clause; otherwise the reader may never be closed. Note that #close simply calls
decRef(), which means that the IndexReader will not really be closed until #decRef has
been called for all outstanding references.
toString()getDocCount(String field)getSumDocFreq(String field)getSumTotalTermFreq(String field)maxDoc()numDocs()