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 `IndexReader.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 and Description
    `DocumentStoredFieldVisitor()` Load all stored fields.
    `DocumentStoredFieldVisitor(Set<String> fieldsToAdd)` Load only fields named in the provided `Set<String>`.
    `DocumentStoredFieldVisitor(String... fields)` Load only fields named in the provided fields.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and 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, byte[] value)` Process a string field; the provided byte[] value is a UTF-8 encoded string value.

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

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

- - ### Constructor Detail

    - #### 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 Detail

    - #### binaryField

          public void binaryField(FieldInfo fieldInfo,
                                  byte[] value)
                           throws IOException

      Description copied from class: `StoredFieldVisitor`
      Process a binary field.
      Overrides:
        `binaryField` in class `StoredFieldVisitor`
        `value` - newly allocated byte array with the binary contents.
      Throws:
        `IOException`

    - #### stringField

          public void stringField(FieldInfo fieldInfo,
                                  byte[] value)
                           throws IOException

      Description copied from class: `StoredFieldVisitor`
      Process a string field; the provided byte[] value is a UTF-8 encoded string value.
      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.

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