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

Package org.apache.lucene.document

# Class TextField

java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.document.TextField

All Implemented Interfaces:
  `IndexableField`

public final class TextField extends Field
A field that is indexed and tokenized, without term vectors. For example this would be used on a 'body' field, that contains the bulk of a document's text.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.apache.lucene.document.Field

  `Field.Store`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final FieldType`
  `TYPE_NOT_STORED`
  Indexed, tokenized, not stored.
  `static final FieldType`
  `TYPE_STORED`
  Indexed, tokenized, stored.

  ### Fields inherited from class org.apache.lucene.document.Field

  `fieldsData, name, type`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `TextField(String name, Reader reader)`
  Creates a new un-stored TextField with Reader value.
  `TextField(String name, String value, Field.Store store)`
  Creates a new TextField with String value.
  `TextField(String name, TokenStream stream)`
  Creates a new un-stored TextField with TokenStream value.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `setStringValue(String value)`
  Expert: change the value of this field.
  `StoredValue`
  `storedValue()`
  Stored value.

  ### Methods inherited from class org.apache.lucene.document.Field

  `binaryValue, fieldType, getCharSequenceValue, invertableType, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setTokenStream, stringValue, tokenStream, tokenStreamValue, toString`

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

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

- ## Field Details

  - ### TYPE_NOT_STORED

    public static final FieldType TYPE_NOT_STORED
    Indexed, tokenized, not stored.

  - ### TYPE_STORED

    public static final FieldType TYPE_STORED
    Indexed, tokenized, stored.

- ## Constructor Details

  - ### TextField

    public TextField(String name, Reader reader)
    Creates a new un-stored TextField with Reader value.
    Parameters:
      `name` - field name
      `reader` - reader value
    Throws:
      `IllegalArgumentException` - if the field name is null
      `NullPointerException` - if the reader is null

  - ### TextField

    public TextField(String name, String value, Field.Store store)
    Creates a new TextField with String value.
    Parameters:
      `name` - field name
      `value` - string value
      `store` - Store.YES if the content should also be stored
    Throws:
      `IllegalArgumentException` - if the field name or value is null.

  - ### TextField

    public TextField(String name, TokenStream stream)
    Creates a new un-stored TextField with TokenStream value.
    Parameters:
      `name` - field name
      `stream` - TokenStream value
    Throws:
      `IllegalArgumentException` - if the field name is null.
      `NullPointerException` - if the tokenStream is null

- ## Method Details

  - ### setStringValue

    public void setStringValue(String value)
    Description copied from class: `Field`
    Expert: change the value of this field. This can be used during indexing to re-use a single Field instance to improve indexing speed by avoiding GC cost of new'ing and reclaiming Field instances. Typically a single `Document` instance is re-used as well. This helps most on small documents.

    Each Field instance should only be used once within a single `Document` instance. See ImproveIndexingSpeed for details.

    Overrides:
      `setStringValue` in class `Field`

  - ### storedValue

    public StoredValue storedValue()
    Description copied from interface: `IndexableField`
    Stored value. This method is called to populate stored fields and must return a non-null value if the field stored.
    Specified by:
      `storedValue` in interface `IndexableField`
    Overrides:
      `storedValue` in class `Field`