Package org.apache.lucene.index

# Class TermVectors

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

Direct Known Subclasses:
  `TermVectorsReader`

public abstract class TermVectors extends Object
API for reading term vectors.

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

## Field Summary

Fields
Modifier and Type
Field
Description
`static final TermVectors`
`EMPTY`
Instance that never returns term vectors

## Constructor Summary

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

## Method Summary

Modifier and Type
Method
Description
`abstract Fields`
`get(int doc)`
Returns term vectors for this document, or null if term vectors were not indexed.
`final Terms`
`get(int doc, String field)`
Retrieve term vector for this document and field, or null if term vectors were not indexed.
`void`
`prefetch(int docID)`
Optional method: Give a hint to this `TermVectors` 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`

## Field Details

### EMPTY

public static final TermVectors EMPTY
Instance that never returns term vectors

## Constructor Details

### TermVectors

protected TermVectors()
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 `TermVectors` 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 `get(int)` in batches instead of prefetching all documents up-front.

Throws:
  `IOException`

### get

public abstract Fields get(int doc) throws IOException
Returns 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). If offsets are available they are in an `OffsetAttribute` available from the `PostingsEnum`.

Throws:
  `IOException`

### get

public final Terms get(int doc, String field) throws IOException
Retrieve term vector for this document and field, or null if term vectors were not indexed.

The returned Terms instance acts like a single-document inverted index (the docID will be 0). If offsets are available they are in an `OffsetAttribute` available from the `PostingsEnum`.

Throws:
  `IOException`