org.apache.lucene.index
Class BaseCompositeReader<R extends IndexReader>

java.lang.Object
  extended by org.apache.lucene.index.IndexReader
      extended by org.apache.lucene.index.CompositeReader
          extended by org.apache.lucene.index.BaseCompositeReader<R>
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
DirectoryReader, MultiReader, ParallelCompositeReader

public abstract class BaseCompositeReader<R extends IndexReader>
extends CompositeReader

Base class for implementing CompositeReaders based on an array of sub-readers. The implementing class has to add code for correctly refcounting and closing the sub-readers.

User code will most likely use MultiReader to build a composite reader on a set of sub-readers (like several DirectoryReaders).

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.

See Also:
MultiReader
NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader
IndexReader.ReaderClosedListener
 
Constructor Summary
protected BaseCompositeReader(R[] subReaders)
          Constructs a BaseCompositeReader on the given subReaders.
 
Method Summary
 int docFreq(String field, BytesRef t)
          Returns the number of documents containing the term.
 void document(int docID, StoredFieldVisitor visitor)
          Expert: visits the fields of a stored document, for custom processing/loading of each field.
 List<? extends R> getSequentialSubReaders()
          Expert: returns the sequential sub readers that this reader is logically composed of.
 Fields getTermVectors(int docID)
          Retrieve term vectors for this document, or null if term vectors were not indexed.
 boolean hasDeletions()
          Returns true if any documents have been deleted
 int maxDoc()
          Returns one greater than the largest possible document number.
 int numDocs()
          Returns the number of documents in this index.
protected  int readerBase(int readerIndex)
          Helper method for subclasses to get the docBase of the given sub-reader index.
protected  int readerIndex(int docID)
          Helper method for subclasses to get the corresponding reader for a doc ID
 
Methods inherited from class org.apache.lucene.index.CompositeReader
getTopReaderContext, toString
 
Methods inherited from class org.apache.lucene.index.IndexReader
addReaderClosedListener, close, decRef, docFreq, doClose, document, document, ensureOpen, equals, getCombinedCoreAndDeletesKey, getCoreCacheKey, getRefCount, getTermVector, hashCode, incRef, numDeletedDocs, open, open, open, open, open, registerParentReader, removeReaderClosedListener, tryIncRef
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BaseCompositeReader

protected BaseCompositeReader(R[] subReaders)
Constructs a BaseCompositeReader on the given subReaders.

Parameters:
subReaders - the wrapped sub-readers. This array is returned by getSequentialSubReaders() and used to resolve the correct subreader for docID-based methods. Please note: This array is not cloned and not protected for modification, the subclass is responsible to do this.
Method Detail

getTermVectors

public final Fields getTermVectors(int docID)
                            throws IOException
Description copied from class: IndexReader
Retrieve term vectors for this document, or null if term vectors were not indexed. The returned Fields instance acts like a single-document inverted index (the docID will be 0).

Specified by:
getTermVectors in class IndexReader
Throws:
IOException

numDocs

public final int numDocs()
Description copied from class: IndexReader
Returns the number of documents in this index.

Specified by:
numDocs in class IndexReader

maxDoc

public final int maxDoc()
Description copied from class: IndexReader
Returns one greater than the largest possible document number. This may be used to, e.g., determine how big to allocate an array which will have an element for every document number in an index.

Specified by:
maxDoc in class IndexReader

document

public final void document(int docID,
                           StoredFieldVisitor visitor)
                    throws IOException
Description copied from class: IndexReader
Expert: visits the fields of a stored document, for custom processing/loading of each field. If you simply want to load all fields, use IndexReader.document(int). If you want to load a subset, use DocumentStoredFieldVisitor.

Specified by:
document in class IndexReader
Throws:
IOException

hasDeletions

public final boolean hasDeletions()
Description copied from class: IndexReader
Returns true if any documents have been deleted

Specified by:
hasDeletions in class IndexReader

docFreq

public final int docFreq(String field,
                         BytesRef t)
                  throws IOException
Description copied from class: IndexReader
Returns the number of documents containing the term. This method returns 0 if the term or field does not exists. This method does not take into account deleted documents that have not yet been merged away.

Specified by:
docFreq in class IndexReader
Throws:
IOException

readerIndex

protected final int readerIndex(int docID)
Helper method for subclasses to get the corresponding reader for a doc ID


readerBase

protected final int readerBase(int readerIndex)
Helper method for subclasses to get the docBase of the given sub-reader index.


getSequentialSubReaders

public final List<? extends R> getSequentialSubReaders()
Description copied from class: CompositeReader
Expert: returns the sequential sub readers that this reader is logically composed of. It contrast to previous Lucene versions may not return null. If this method returns an empty array, that means this reader is a null reader (for example a MultiReader that has no sub readers).

Specified by:
getSequentialSubReaders in class CompositeReader


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