org.apache.lucene.index
Class AtomicReader

java.lang.Object
  extended by org.apache.lucene.index.IndexReader
      extended by org.apache.lucene.index.AtomicReader
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
FilterAtomicReader, ParallelAtomicReader, SegmentReader, SlowCompositeReaderWrapper

public abstract class AtomicReader
extends IndexReader

AtomicReader is an abstract class, providing an interface for accessing an index. Search of an index is done entirely through this abstract interface, so that any subclass which implements it is searchable. IndexReaders implemented by this subclass do not consist of several sub-readers, they are atomic. They support retrieval of stored fields, doc values, terms, and postings.

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.


Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.lucene.index.IndexReader
IndexReader.ReaderClosedListener
 
Constructor Summary
protected AtomicReader()
           
 
Method Summary
 int docFreq(String field, BytesRef term)
          Returns the number of documents containing the term.
abstract  DocValues docValues(String field)
          Returns DocValues for this field.
abstract  Fields fields()
          Returns Fields for this reader.
abstract  FieldInfos getFieldInfos()
          Get the FieldInfos describing all fields in this reader.
abstract  Bits getLiveDocs()
          Returns the Bits representing live (not deleted) docs.
 AtomicReaderContext getTopReaderContext()
          Expert: Returns a the root IndexReaderContext for this IndexReader's sub-reader tree.
 long getUniqueTermCount()
          Returns the number of unique terms (across all fields) in this reader.
 boolean hasNorms(String field)
          Deprecated. (4.0) use getFieldInfos() and check FieldInfo.hasNorms() for the field instead.
abstract  DocValues normValues(String field)
          Returns DocValues for this field's normalization values.
 DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term)
          Returns DocsEnum for the specified field & term.
 DocsEnum termDocsEnum(Bits liveDocs, String field, BytesRef term, int flags)
          Returns DocsEnum for the specified field & term, with control over whether freqs are required.
 DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term)
          Returns DocsAndPositionsEnum for the specified field & term.
 DocsAndPositionsEnum termPositionsEnum(Bits liveDocs, String field, BytesRef term, int flags)
          Returns DocsAndPositionsEnum for the specified field & term, with control over whether offsets and payloads are required.
 Terms terms(String field)
          This may return null if the field does not exist.
 long totalTermFreq(String field, BytesRef term)
          Returns the number of documents containing the term t.
 
Methods inherited from class org.apache.lucene.index.IndexReader
addReaderClosedListener, close, decRef, docFreq, doClose, document, document, document, ensureOpen, equals, getCombinedCoreAndDeletesKey, getCoreCacheKey, getRefCount, getTermVector, getTermVectors, hasDeletions, hashCode, incRef, maxDoc, numDeletedDocs, numDocs, open, open, open, open, open, registerParentReader, removeReaderClosedListener, tryIncRef
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AtomicReader

protected AtomicReader()
Method Detail

getTopReaderContext

public final AtomicReaderContext getTopReaderContext()
Description copied from class: IndexReader
Expert: Returns a the root IndexReaderContext for this IndexReader's sub-reader tree. Iff this reader is composed of sub readers ,ie. this reader being a composite reader, this method returns a CompositeReaderContext holding the reader's direct children as well as a view of the reader tree's atomic leaf contexts. All sub- IndexReaderContext instances referenced from this readers top-level context are private to this reader and are not shared with another context tree. For example, IndexSearcher uses this API to drive searching by one atomic leaf reader at a time. If this reader is not composed of child readers, this method returns an AtomicReaderContext.

Note: Any of the sub-CompositeReaderContext instances reference from this top-level context holds a null CompositeReaderContext.leaves() reference. Only the top-level context maintains the convenience leaf-view for performance reasons.

Specified by:
getTopReaderContext in class IndexReader

hasNorms

@Deprecated
public final boolean hasNorms(String field)
                       throws IOException
Deprecated. (4.0) use getFieldInfos() and check FieldInfo.hasNorms() for the field instead.

Returns true if there are norms stored for this field.

Throws:
IOException

fields

public abstract Fields fields()
                       throws IOException
Returns Fields for this reader. This method may return null if the reader has no postings.

Throws:
IOException

docFreq

public final int docFreq(String field,
                         BytesRef term)
                  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

totalTermFreq

public final long totalTermFreq(String field,
                                BytesRef term)
                         throws IOException
Returns the number of documents containing the term t. 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.

Throws:
IOException

terms

public final Terms terms(String field)
                  throws IOException
This may return null if the field does not exist.

Throws:
IOException

termDocsEnum

public final DocsEnum termDocsEnum(Bits liveDocs,
                                   String field,
                                   BytesRef term)
                            throws IOException
Returns DocsEnum for the specified field & term. This will return null if either the field or term does not exist.

Throws:
IOException

termDocsEnum

public final DocsEnum termDocsEnum(Bits liveDocs,
                                   String field,
                                   BytesRef term,
                                   int flags)
                            throws IOException
Returns DocsEnum for the specified field & term, with control over whether freqs are required. Some codecs may be able to optimize their implementation when freqs are not required. This will return null if the field or term does not exist. See TermsEnum.docs(Bits,DocsEnum,int).

Throws:
IOException

termPositionsEnum

public final DocsAndPositionsEnum termPositionsEnum(Bits liveDocs,
                                                    String field,
                                                    BytesRef term)
                                             throws IOException
Returns DocsAndPositionsEnum for the specified field & term. This will return null if the field or term does not exist or positions weren't indexed.

Throws:
IOException
See Also:
termPositionsEnum(Bits, String, BytesRef, int)

termPositionsEnum

public final DocsAndPositionsEnum termPositionsEnum(Bits liveDocs,
                                                    String field,
                                                    BytesRef term,
                                                    int flags)
                                             throws IOException
Returns DocsAndPositionsEnum for the specified field & term, with control over whether offsets and payloads are required. Some codecs may be able to optimize their implementation when offsets and/or payloads are not required. This will return null if the field or term does not exist or positions weren't indexed. See TermsEnum.docsAndPositions(Bits,DocsAndPositionsEnum,int).

Throws:
IOException

getUniqueTermCount

public final long getUniqueTermCount()
                              throws IOException
Returns the number of unique terms (across all fields) in this reader.

Throws:
IOException

docValues

public abstract DocValues docValues(String field)
                             throws IOException
Returns DocValues for this field. This method may return null if the reader has no per-document values stored.

Throws:
IOException

normValues

public abstract DocValues normValues(String field)
                              throws IOException
Returns DocValues for this field's normalization values. This method may return null if the field has no norms.

Throws:
IOException

getFieldInfos

public abstract FieldInfos getFieldInfos()
Get the FieldInfos describing all fields in this reader.

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

getLiveDocs

public abstract Bits getLiveDocs()
Returns the Bits representing live (not deleted) docs. A set bit indicates the doc ID has not been deleted. If this method returns null it means there are no deleted documents (all documents are live). The returned instance has been safely published for use by multiple threads without additional synchronization.



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