Class TermSuggestionBuilder
- java.lang.Object
-
- org.elasticsearch.search.suggest.SuggestionBuilder<TermSuggestionBuilder>
-
- org.elasticsearch.search.suggest.term.TermSuggestionBuilder
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentFragment
public class TermSuggestionBuilder extends SuggestionBuilder<TermSuggestionBuilder>
Defines the actual suggest command. Each command uses the global options unless defined in the suggestion itself. All options are the same as the global options, but are only applicable for this suggestion.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TermSuggestionBuilder.StringDistanceImpl
An enum representing the valid string edit distance algorithms for determining suggestions.static class
TermSuggestionBuilder.SuggestMode
An enum representing the valid suggest modes.-
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
-
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
-
Field Summary
-
Fields inherited from class org.elasticsearch.search.suggest.SuggestionBuilder
analyzer, ANALYZER_FIELD, field, FIELDNAME_FIELD, prefix, PREFIX_FIELD, regex, REGEX_FIELD, shardSize, SHARDSIZE_FIELD, size, SIZE_FIELD, text, TEXT_FIELD
-
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
-
Constructor Summary
Constructors Constructor Description TermSuggestionBuilder(java.lang.String field)
TermSuggestionBuilder(StreamInput in)
Read from a stream.
-
Method Summary
Modifier and Type Method Description float
accuracy()
Get the accuracy setting.TermSuggestionBuilder
accuracy(float accuracy)
s how similar the suggested terms at least need to be compared to the original suggest text tokens.SuggestionSearchContext.SuggestionContext
build(QueryShardContext context)
protected boolean
doEquals(TermSuggestionBuilder other)
Indicates whether some otherSuggestionBuilder
of the same type is "equal to" this one.protected int
doHashCode()
HashCode for the subclass ofSuggestionBuilder
to implement.void
doWriteTo(StreamOutput out)
static TermSuggestionBuilder
fromXContent(XContentParser parser)
java.lang.String
getWriteableName()
Returns the name of the writeable objectXContentBuilder
innerToXContent(XContentBuilder builder, ToXContent.Params params)
int
maxEdits()
Get the maximum edit distance setting.TermSuggestionBuilder
maxEdits(int maxEdits)
Sets the maximum edit distance candidate suggestions can have in order to be considered as a suggestion.int
maxInspections()
Get the factor for inspecting more candidate suggestions setting.TermSuggestionBuilder
maxInspections(int maxInspections)
A factor that is used to multiply with the size in order to inspect more candidate suggestions.float
maxTermFreq()
Get the maximum term frequency threshold setting.TermSuggestionBuilder
maxTermFreq(float maxTermFreq)
Sets a maximum threshold in number of documents a suggest text token can exist in order to be corrected.float
minDocFreq()
Get the minimal threshold for the frequency of a term appearing in the document set setting.TermSuggestionBuilder
minDocFreq(float minDocFreq)
Sets a minimal threshold in number of documents a suggested term should appear in.int
minWordLength()
Get the minimum length of a text term to be corrected setting.TermSuggestionBuilder
minWordLength(int minWordLength)
The minimum length a suggest text term must have in order to be corrected.int
prefixLength()
Get the minimum prefix length that must match setting.TermSuggestionBuilder
prefixLength(int prefixLength)
Sets the number of minimal prefix characters that must match in order be a candidate suggestion.SortBy
sort()
Get the sort setting.TermSuggestionBuilder
sort(SortBy sort)
Sets how to sort the suggest terms per suggest text token.TermSuggestionBuilder.StringDistanceImpl
stringDistance()
Get the string distance implementation setting.TermSuggestionBuilder
stringDistance(TermSuggestionBuilder.StringDistanceImpl stringDistance)
Sets what string distance implementation to use for comparing how similar suggested terms are.TermSuggestionBuilder.SuggestMode
suggestMode()
Get the suggest mode setting.TermSuggestionBuilder
suggestMode(TermSuggestionBuilder.SuggestMode suggestMode)
The global suggest mode controls what suggested terms are included or controls for what suggest text tokens, terms should be suggested for.-
Methods inherited from class org.elasticsearch.search.suggest.SuggestionBuilder
analyzer, analyzer, equals, field, hashCode, populateCommonFields, prefix, prefix, regex, regex, shardSize, shardSize, size, size, text, text, toXContent, writeTo
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.elasticsearch.common.xcontent.ToXContentFragment
isFragment
-
-
-
-
Constructor Detail
-
TermSuggestionBuilder
public TermSuggestionBuilder(java.lang.String field)
-
TermSuggestionBuilder
public TermSuggestionBuilder(StreamInput in) throws java.io.IOException
Read from a stream.- Throws:
java.io.IOException
-
-
Method Detail
-
doWriteTo
public void doWriteTo(StreamOutput out) throws java.io.IOException
- Specified by:
doWriteTo
in classSuggestionBuilder<TermSuggestionBuilder>
- Throws:
java.io.IOException
-
suggestMode
public TermSuggestionBuilder suggestMode(TermSuggestionBuilder.SuggestMode suggestMode)
The global suggest mode controls what suggested terms are included or controls for what suggest text tokens, terms should be suggested for. Three possible values can be specified:missing
- Only suggest terms in the suggest text that aren't in the index. This is the default.popular
- Only suggest terms that occur in more docs then the original suggest text term.always
- Suggest any matching suggest terms based on tokens in the suggest text.
-
suggestMode
public TermSuggestionBuilder.SuggestMode suggestMode()
Get the suggest mode setting.
-
accuracy
public TermSuggestionBuilder accuracy(float accuracy)
s how similar the suggested terms at least need to be compared to the original suggest text tokens. A value between 0 and 1 can be specified. This value will be compared to the string distance result of each candidate spelling correction.Default is
0.5
-
accuracy
public float accuracy()
Get the accuracy setting.
-
sort
public TermSuggestionBuilder sort(SortBy sort)
Sets how to sort the suggest terms per suggest text token. Two possible values:score
- Sort should first be based on score, then document frequency and then the term itself.frequency
- Sort should first be based on document frequency, then score and then the term itself.
What the score is depends on the suggester being used.
-
sort
public SortBy sort()
Get the sort setting.
-
stringDistance
public TermSuggestionBuilder stringDistance(TermSuggestionBuilder.StringDistanceImpl stringDistance)
Sets what string distance implementation to use for comparing how similar suggested terms are. Five possible values can be specified:internal
- This is the default and is based ondamerau_levenshtein
, but highly optimized for comparing string distance for terms inside the index.damerau_levenshtein
- String distance algorithm based on Damerau-Levenshtein algorithm.levenshtein
- String distance algorithm based on Levenshtein edit distance algorithm.jaro_winkler
- String distance algorithm based on Jaro-Winkler algorithm.ngram
- String distance algorithm based on character n-grams.
-
stringDistance
public TermSuggestionBuilder.StringDistanceImpl stringDistance()
Get the string distance implementation setting.
-
maxEdits
public TermSuggestionBuilder maxEdits(int maxEdits)
Sets the maximum edit distance candidate suggestions can have in order to be considered as a suggestion. Can only be a value between 1 and 2. Any other value result in an bad request error being thrown. Defaults to2
.
-
maxEdits
public int maxEdits()
Get the maximum edit distance setting.
-
maxInspections
public TermSuggestionBuilder maxInspections(int maxInspections)
A factor that is used to multiply with the size in order to inspect more candidate suggestions. Can improve accuracy at the cost of performance. Defaults to5
.
-
maxInspections
public int maxInspections()
Get the factor for inspecting more candidate suggestions setting.
-
maxTermFreq
public TermSuggestionBuilder maxTermFreq(float maxTermFreq)
Sets a maximum threshold in number of documents a suggest text token can exist in order to be corrected. Can be a relative percentage number (e.g 0.4) or an absolute number to represent document frequencies. If an value higher than 1 is specified then fractional can not be specified. Defaults to0.01
.This can be used to exclude high frequency terms from being suggested. High frequency terms are usually spelled correctly on top of this this also improves the suggest performance.
-
maxTermFreq
public float maxTermFreq()
Get the maximum term frequency threshold setting.
-
prefixLength
public TermSuggestionBuilder prefixLength(int prefixLength)
Sets the number of minimal prefix characters that must match in order be a candidate suggestion. Defaults to 1. Increasing this number improves suggest performance. Usually misspellings don't occur in the beginning of terms.
-
prefixLength
public int prefixLength()
Get the minimum prefix length that must match setting.
-
minWordLength
public TermSuggestionBuilder minWordLength(int minWordLength)
The minimum length a suggest text term must have in order to be corrected. Defaults to4
.
-
minWordLength
public int minWordLength()
Get the minimum length of a text term to be corrected setting.
-
minDocFreq
public TermSuggestionBuilder minDocFreq(float minDocFreq)
Sets a minimal threshold in number of documents a suggested term should appear in. This can be specified as an absolute number or as a relative percentage of number of documents. This can improve quality by only suggesting high frequency terms. Defaults to 0f and is not enabled. If a value higher than 1 is specified then the number cannot be fractional.
-
minDocFreq
public float minDocFreq()
Get the minimal threshold for the frequency of a term appearing in the document set setting.
-
innerToXContent
public XContentBuilder innerToXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
innerToXContent
in classSuggestionBuilder<TermSuggestionBuilder>
- Throws:
java.io.IOException
-
fromXContent
public static TermSuggestionBuilder fromXContent(XContentParser parser) throws java.io.IOException
- Throws:
java.io.IOException
-
build
public SuggestionSearchContext.SuggestionContext build(QueryShardContext context) throws java.io.IOException
- Specified by:
build
in classSuggestionBuilder<TermSuggestionBuilder>
- Throws:
java.io.IOException
-
getWriteableName
public java.lang.String getWriteableName()
Description copied from interface:NamedWriteable
Returns the name of the writeable object
-
doEquals
protected boolean doEquals(TermSuggestionBuilder other)
Description copied from class:SuggestionBuilder
Indicates whether some otherSuggestionBuilder
of the same type is "equal to" this one.- Specified by:
doEquals
in classSuggestionBuilder<TermSuggestionBuilder>
-
doHashCode
protected int doHashCode()
Description copied from class:SuggestionBuilder
HashCode for the subclass ofSuggestionBuilder
to implement.- Specified by:
doHashCode
in classSuggestionBuilder<TermSuggestionBuilder>
-
-