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.Modifier and Type | Class and Description |
---|---|
private static class |
ContextSuggestField.PrefixTokenFilter
The
ContextSuggestField.PrefixTokenFilter wraps a TokenStream and adds a set
prefixes ahead. |
Field.Store
Modifier and Type | Field and Description |
---|---|
static int |
CONTEXT_SEPARATOR
Separator used between context value and the suggest field value
|
private java.util.Set<java.lang.CharSequence> |
contexts |
(package private) static byte |
TYPE |
FIELD_TYPE
fieldsData, name, tokenStream, type
Constructor and Description |
---|
ContextSuggestField(java.lang.String name,
java.lang.String value,
int weight,
java.lang.CharSequence... contexts)
Creates a context-enabled suggest field
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Iterable<java.lang.CharSequence> |
contexts()
Expert: Sub-classes can inject contexts at
index-time
|
protected byte |
type()
Returns a byte to denote the type of the field
|
private void |
validate(java.lang.CharSequence value) |
protected CompletionTokenStream |
wrapTokenStream(TokenStream stream)
Wraps a
stream with a CompletionTokenStream. |
tokenStream
binaryValue, fieldType, getCharSequenceValue, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStreamValue, toString
public static final int CONTEXT_SEPARATOR
static final byte TYPE
private final java.util.Set<java.lang.CharSequence> contexts
public ContextSuggestField(java.lang.String name, java.lang.String value, int weight, java.lang.CharSequence... contexts)
name
- field namevalue
- field value to get suggestion onweight
- field weightcontexts
- associated contextsjava.lang.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 charactersprotected java.lang.Iterable<java.lang.CharSequence> contexts()
protected CompletionTokenStream wrapTokenStream(TokenStream stream)
SuggestField
stream
with a CompletionTokenStream.
Subclasses can override this method to change the indexing pipeline.wrapTokenStream
in class SuggestField
protected byte type()
SuggestField
type
in class SuggestField
private void validate(java.lang.CharSequence value)