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));
UseContextQuery
to boost and/or filter suggestions at query-time. UsePrefixCompletionQuery
,RegexCompletionQuery
orFuzzyCompletionQuery
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 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, tokenStream, type
-
-
Constructor Summary
Constructors Constructor Description ContextSuggestField(String name, String value, int weight, CharSequence... contexts)
Creates a context-enabled suggest field
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Iterable<CharSequence>
contexts()
Expert: Sub-classes can inject contexts at index-timeprotected byte
type()
Returns a byte to denote the type of the fieldprotected CompletionTokenStream
wrapTokenStream(TokenStream stream)
Wraps astream
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, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, stringValue, tokenStreamValue, toString
-
-
-
-
Field Detail
-
CONTEXT_SEPARATOR
public static final int CONTEXT_SEPARATOR
Separator used between context value and the suggest field value- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ContextSuggestField
public ContextSuggestField(String name, String value, int weight, CharSequence... contexts)
Creates a context-enabled suggest field- Parameters:
name
- field namevalue
- field value to get suggestion onweight
- field weightcontexts
- 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 Detail
-
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 astream
with a CompletionTokenStream.Subclasses can override this method to change the indexing pipeline.
- Overrides:
wrapTokenStream
in classSuggestField
-
type
protected byte type()
Description copied from class:SuggestField
Returns a byte to denote the type of the field- Overrides:
type
in classSuggestField
-
-