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
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
FieldsModifier and TypeFieldDescriptionstatic final intSeparator used between context value and the suggest field valueFields inherited from class org.apache.lucene.search.suggest.document.SuggestField
FIELD_TYPEFields inherited from class org.apache.lucene.document.Field
fieldsData, name, type -
Constructor Summary
ConstructorsConstructorDescriptionContextSuggestField(String name, String value, int weight, CharSequence... contexts) Creates a context-enabled suggest field -
Method Summary
Modifier and TypeMethodDescriptionprotected Iterable<CharSequence> contexts()Expert: Sub-classes can inject contexts at index-timeprotected bytetype()Returns a byte to denote the type of the fieldprotected CompletionTokenStreamwrapTokenStream(TokenStream stream) Wraps astreamwith a CompletionTokenStream.Methods inherited from class org.apache.lucene.search.suggest.document.SuggestField
tokenStreamMethods 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
-
Field Details
-
CONTEXT_SEPARATOR
public static final int CONTEXT_SEPARATORSeparator used between context value and the suggest field value- See Also:
-
-
Constructor Details
-
ContextSuggestField
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 Details
-
contexts
Expert: Sub-classes can inject contexts at index-time -
wrapTokenStream
Description copied from class:SuggestFieldWraps astreamwith a CompletionTokenStream.Subclasses can override this method to change the indexing pipeline.
- Overrides:
wrapTokenStreamin classSuggestField
-
type
protected byte type()Description copied from class:SuggestFieldReturns a byte to denote the type of the field- Overrides:
typein classSuggestField
-