DocumentStoredFieldVisitor (Lucene 10.5.0 core API)
Description: declaration: package: org.apache.lucene.document, class: DocumentStoredFieldVisitor

Package org.apache.lucene.document

# Class DocumentStoredFieldVisitor

java.lang.Object
org.apache.lucene.index.StoredFieldVisitor
org.apache.lucene.document.DocumentStoredFieldVisitor

public class DocumentStoredFieldVisitor extends StoredFieldVisitor
A `StoredFieldVisitor` that creates a `Document` from stored fields.

This visitor supports loading all stored fields, or only specific requested fields provided from a `Set`.

This is used by `StoredFields.document(int)` to load a document.

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

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.lucene.index.StoredFieldVisitor

  `StoredFieldVisitor.Status`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DocumentStoredFieldVisitor()`
  Load all stored fields.
  `DocumentStoredFieldVisitor(String... fields)`
  Load only fields named in the provided fields.
  `DocumentStoredFieldVisitor(Set<String> fieldsToAdd)`
  Load only fields named in the provided `Set<String>`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `binaryField(FieldInfo fieldInfo, byte[] value)`
  Process a binary field.
  `void`
  `doubleField(FieldInfo fieldInfo, double value)`
  Process a double numeric field.
  `void`
  `floatField(FieldInfo fieldInfo, float value)`
  Process a float numeric field.
  `Document`
  `getDocument()`
  Retrieve the visited document.
  `void`
  `intField(FieldInfo fieldInfo, int value)`
  Process a int numeric field.
  `void`
  `longField(FieldInfo fieldInfo, long value)`
  Process a long numeric field.
  `StoredFieldVisitor.Status`
  `needsField(FieldInfo fieldInfo)`
  Hook before processing a field.
  `void`
  `stringField(FieldInfo fieldInfo, String value)`
  Process a string field.

  ### Methods inherited from class org.apache.lucene.index.StoredFieldVisitor

  `binaryField`

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

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

- ## Constructor Details

  - ### DocumentStoredFieldVisitor

    public DocumentStoredFieldVisitor(Set<String> fieldsToAdd)
    Load only fields named in the provided `Set<String>`.
    Parameters:
      `fieldsToAdd` - Set of fields to load, or `null` (all fields).

  - ### DocumentStoredFieldVisitor

    public DocumentStoredFieldVisitor(String... fields)
    Load only fields named in the provided fields.

  - ### DocumentStoredFieldVisitor

    public DocumentStoredFieldVisitor()
    Load all stored fields.

- ## Method Details

  - ### binaryField

    public void binaryField(FieldInfo fieldInfo, byte[] value) throws IOException
    Description copied from class: `StoredFieldVisitor`
    Process a binary field.
    Overrides:
      `binaryField` in class `StoredFieldVisitor`
    Parameters:
      `value` - newly allocated byte array with the binary contents.
    Throws:
      `IOException`

  - ### stringField

    public void stringField(FieldInfo fieldInfo, String value) throws IOException
    Description copied from class: `StoredFieldVisitor`
    Process a string field.
    Overrides:
      `stringField` in class `StoredFieldVisitor`
    Throws:
      `IOException`

  - ### intField

    public void intField(FieldInfo fieldInfo, int value)
    Description copied from class: `StoredFieldVisitor`
    Process a int numeric field.
    Overrides:
      `intField` in class `StoredFieldVisitor`

  - ### longField

    public void longField(FieldInfo fieldInfo, long value)
    Description copied from class: `StoredFieldVisitor`
    Process a long numeric field.
    Overrides:
      `longField` in class `StoredFieldVisitor`

  - ### floatField

    public void floatField(FieldInfo fieldInfo, float value)
    Description copied from class: `StoredFieldVisitor`
    Process a float numeric field.
    Overrides:
      `floatField` in class `StoredFieldVisitor`

  - ### doubleField

    public void doubleField(FieldInfo fieldInfo, double value)
    Description copied from class: `StoredFieldVisitor`
    Process a double numeric field.
    Overrides:
      `doubleField` in class `StoredFieldVisitor`

  - ### needsField

    public StoredFieldVisitor.Status needsField(FieldInfo fieldInfo) throws IOException
    Description copied from class: `StoredFieldVisitor`
    Hook before processing a field. Before a field is processed, this method is invoked so that subclasses can return a `StoredFieldVisitor.Status` representing whether they need that particular field or not, or to stop processing entirely.
    Specified by:
      `needsField` in class `StoredFieldVisitor`
    Throws:
      `IOException`

  - ### getDocument

    public Document getDocument()
    Retrieve the visited document.
    Returns:
      `Document` populated with stored fields. Note that only the stored information in the field instances is valid, data such as indexing options, term vector options, etc is not set.