Module org.apache.lucene.suggest
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ContextSuggestField.PrefixTokenFilter
TheContextSuggestField.PrefixTokenFilter
wraps aTokenStream
and adds a set prefixes ahead.-
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 valueprivate java.util.Set<java.lang.CharSequence>
contexts
(package private) static byte
TYPE
-
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(java.lang.String name, java.lang.String value, int weight, java.lang.CharSequence... contexts)
Creates a context-enabled suggest field
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Iterable<java.lang.CharSequence>
contexts()
Expert: Sub-classes can inject contexts at index-timeprotected byte
type()
Returns a byte to denote the type of the fieldprivate void
validate(java.lang.CharSequence value)
protected 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, invertableType, name, numericValue, readerValue, setBytesValue, setBytesValue, setByteValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setReaderValue, setShortValue, setStringValue, setTokenStream, storedValue, 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
-
TYPE
static final byte TYPE
- See Also:
- Constant Field Values
-
contexts
private final java.util.Set<java.lang.CharSequence> contexts
-
-
Constructor Detail
-
ContextSuggestField
public ContextSuggestField(java.lang.String name, java.lang.String value, int weight, java.lang.CharSequence... contexts)
Creates a context-enabled suggest field- Parameters:
name
- field namevalue
- field value to get suggestion onweight
- field weightcontexts
- associated contexts- Throws:
java.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 characters
-
-
Method Detail
-
contexts
protected java.lang.Iterable<java.lang.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
-
validate
private void validate(java.lang.CharSequence value)
-
-