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

# Class ContextSuggestField

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

All Implemented Interfaces:
  `IndexableField`

public class ContextSuggestField extends SuggestField
`SuggestField` which additionally takes in a set of contexts. Example usage of adding a suggestion with contexts is as follows:

      document.add(
       new ContextSuggestField(name, "suggestion", Arrays.asList("context1", "context2"),  4));

Use `ContextQuery` to boost and/or filter suggestions at query-time. Use `PrefixCompletionQuery`, `RegexCompletionQuery` or `FuzzyCompletionQuery` if context boost/filtering are not needed.

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 int`
`CONTEXT_SEPARATOR`
Separator used between context value and the suggest field value

### Fields inherited from class org.apache.lucene.search.suggest.document.SuggestField

`FIELD_TYPE`

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

`fieldsData, name, type`

## Constructor Summary

Constructors
Constructor
Description
`ContextSuggestField(String name, String value, int weight, CharSequence... contexts)`
Creates a context-enabled suggest field

## Method Summary

Modifier and Type
Method
Description
`protected Iterable<CharSequence>`
`contexts()`
Expert: Sub-classes can inject contexts at index-time
`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.search.suggest.document.SuggestField

`tokenStream`

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

### CONTEXT_SEPARATOR

public static final int CONTEXT_SEPARATOR
Separator used between context value and the suggest field value

See Also:
  - Constant Field Values

## Constructor Details

### ContextSuggestField

public ContextSuggestField(String name, String value, int weight, CharSequence... contexts)
Creates a context-enabled suggest field

Parameters:
  `name` - field name
  `value` - field value to get suggestion on
  `weight` - field weight
  `contexts` - associated contexts
Throws:
  `IllegalArgumentException` - if either the name or value is null, if value is an empty string, if the weight is negative, if value or contexts contains any reserved characters

## Method Details

### contexts

protected Iterable<CharSequence> contexts()
Expert: Sub-classes can inject contexts at index-time

### wrapTokenStream

protected CompletionTokenStream wrapTokenStream(TokenStream stream)
Description copied from class: `SuggestField`
Wraps a `stream` with a CompletionTokenStream.

Subclasses can override this method to change the indexing pipeline.

Overrides:
  `wrapTokenStream` in class `SuggestField`

### type

protected byte type()
Description copied from class: `SuggestField`
Returns a byte to denote the type of the field

Overrides:
  `type` in class `SuggestField`