Module org.apache.lucene.suggest
Class SuggestField
java.lang.Object
org.apache.lucene.document.Field
org.apache.lucene.search.suggest.document.SuggestField
- All Implemented Interfaces:
IndexableField
- Direct Known Subclasses:
ContextSuggestField
Field that indexes a string value and a weight as a weighted completion against a named
suggester. Field is tokenized, not stored and stores documents, frequencies and positions. Field
can be used to provide near real time document suggestions.
Besides the usual Analyzer
s, CompletionAnalyzer
can
be used to tune suggest field only parameters (e.g. preserving token separators, preserving
position increments when converting the token stream to an automaton)
Example indexing usage:
document.add(new SuggestField(name, "suggestion", 4));To perform document suggestions based on the field, use
SuggestIndexSearcher.suggest(CompletionQuery, int, boolean)
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.lucene.document.Field
Field.Store
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FieldType
Default field type for suggest fieldprivate final BytesRef
(package private) static final byte
private final int
Fields inherited from class org.apache.lucene.document.Field
fieldsData, name, type
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate BytesRef
private boolean
isReserved
(char c) tokenStream
(Analyzer analyzer, TokenStream reuse) Creates the TokenStream used for indexing this field.protected 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.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
-
FIELD_TYPE
Default field type for suggest field -
TYPE
static final byte TYPE- See Also:
-
surfaceForm
-
weight
private final int weight
-
-
Constructor Details
-
SuggestField
Creates aSuggestField
- Parameters:
name
- field namevalue
- field value to get suggestions onweight
- field weight- Throws:
IllegalArgumentException
- if either the name or value is null, if value is an empty string, if the weight is negative, if value contains any reserved characters
-
-
Method Details
-
tokenStream
Description copied from interface:IndexableField
Creates the TokenStream used for indexing this field. If appropriate, implementations should use the given Analyzer to create the TokenStreams.- Specified by:
tokenStream
in interfaceIndexableField
- Overrides:
tokenStream
in classField
- Parameters:
analyzer
- Analyzer that should be used to create the TokenStreams fromreuse
- TokenStream for a previous instance of this field name. This allows custom field types (like StringField and NumericField) that do not use the analyzer to still have good performance. Note: the passed-in type may be inappropriate, for example if you mix up different types of Fields for the same field name. So it's the responsibility of the implementation to check.- Returns:
- TokenStream value for indexing the document. Should always return a non-null value if the field is to be indexed
-
wrapTokenStream
Wraps astream
with a CompletionTokenStream.Subclasses can override this method to change the indexing pipeline.
-
type
protected byte type()Returns a byte to denote the type of the field -
buildSuggestPayload
-
isReserved
private boolean isReserved(char c)
-