Package org.apache.lucene.index

# Class StoredFields

java.lang.Object
org.apache.lucene.index.StoredFields

Direct Known Subclasses:
  `StoredFieldsReader`

public abstract class StoredFields extends Object
API for reading stored fields.

NOTE: This class is not thread-safe and should only be consumed in the thread where it was acquired.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`protected`
`StoredFields()`
Sole constructor.

## Method Summary

Modifier and Type
Method
Description
`final Document`
`document(int docID)`
Returns the stored fields of the `n`th `Document` in this index.
`final Document`
`document(int docID, Set<String> fieldsToLoad)`
Like `document(int)` but only loads the specified fields.
`abstract void`
`document(int docID, StoredFieldVisitor visitor)`
Expert: visits the fields of a stored document, for custom processing/loading of each field.
`void`
`prefetch(int docID)`
Optional method: Give a hint to this `StoredFields` instance that the given document will be read in the near future.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### StoredFields

protected StoredFields()
Sole constructor. (For invocation by subclass constructors, typically implicit.)

## Method Details

### prefetch

public void prefetch(int docID) throws IOException
Optional method: Give a hint to this `StoredFields` instance that the given document will be read in the near future. This typically delegates to `IndexInput.prefetch(long, long)` and is useful to parallelize I/O across multiple documents.

NOTE: This API is expected to be called on a small enough set of doc IDs that they could all fit in the page cache. If you plan on retrieving a very large number of documents, it may be a good idea to perform calls to `prefetch(int)` and `document(int)` in batches instead of prefetching all documents up-front.

Throws:
  `IOException`

### document

public final Document document(int docID) throws IOException
Returns the stored fields of the `n`th `Document` in this index. This is just sugar for using `DocumentStoredFieldVisitor`.

NOTE: for performance reasons, this method does not check if the requested document is deleted, and therefore asking for a deleted document may yield unspecified results. Usually this is not required, however you can test if the doc is deleted by checking the `Bits` returned from `MultiBits.getLiveDocs(org.apache.lucene.index.IndexReader)`.

NOTE: only the content of a field is returned, if that field was stored during indexing. Metadata like boost, omitNorm, IndexOptions, tokenized, etc., are not preserved.

Throws:
  `CorruptIndexException` - if the index is corrupt
  `IOException` - if there is a low-level IO error

### document

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

Throws:
  `IOException`

### document

public final Document document(int docID, Set<String> fieldsToLoad) throws IOException
Like `document(int)` but only loads the specified fields. Note that this is simply sugar for `DocumentStoredFieldVisitor(Set)`.

Throws:
  `IOException`