SuggestField (Lucene 10.5.1 suggest API)
Description: declaration: package: org.apache.lucene.search.suggest.document, class: SuggestField

Package org.apache.lucene.search.suggest.document

# Class SuggestField

java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.search.suggest.document.SuggestField

All Implemented Interfaces:
  `IndexableField`

Direct Known Subclasses:
  `ContextSuggestField`

public class SuggestField extends Field
Field that indexes a string value and a weight as a weighted completion against a named suggester. Field is tokenized, not stored and stores documents, frequencies and positions. Field can be used to provide near real time document suggestions.

Besides the usual `Analyzer`s, `CompletionAnalyzer` can be used to tune suggest field only parameters (e.g. preserving token separators, preserving position increments when converting the token stream to an automaton)

Example indexing usage:

     document.add(new SuggestField(name, "suggestion", 4));

To perform document suggestions based on the field, use `SuggestIndexSearcher.suggest(CompletionQuery, int, boolean)`

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.document.Field

  `Field.Store`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final FieldType`
  `FIELD_TYPE`
  Default field type for suggest field

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

  `fieldsData, name, type`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SuggestField(String name, String value, int weight)`
  Creates a `SuggestField`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `TokenStream`
  `tokenStream(Analyzer analyzer, TokenStream reuse)`
  `protected byte`
  `type()`
  Returns a byte to denote the type of the field
  `protected CompletionTokenStream`
  `wrapTokenStream(TokenStream stream)`
  Wraps a `stream` with a CompletionTokenStream.

  ### 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, setStringValue, setTokenStream, storedValue, stringValue, tokenStreamValue, toString`

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

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

- ## Field Details

  - ### FIELD_TYPE

    public static final FieldType FIELD_TYPE
    Default field type for suggest field

- ## Constructor Details

  - ### SuggestField

    public SuggestField(String name, String value, int weight)
    Creates a `SuggestField`
    Parameters:
      `name` - field name
      `value` - field value to get suggestions on
      `weight` - field weight
    Throws:
      `IllegalArgumentException` - if either the name or value is null, if value is an empty string, if the weight is negative, if value contains any reserved characters

- ## Method Details

  - ### tokenStream

    public TokenStream tokenStream(Analyzer analyzer, TokenStream reuse)
    Specified by:
      `tokenStream` in interface `IndexableField`
    Overrides:
      `tokenStream` in class `Field`

  - ### wrapTokenStream

    protected CompletionTokenStream wrapTokenStream(TokenStream stream)
    Wraps a `stream` with a CompletionTokenStream.

    Subclasses can override this method to change the indexing pipeline.

  - ### type

    protected byte type()
    Returns a byte to denote the type of the field