Class CompletionSuggestionBuilder
- java.lang.Object
-
- org.elasticsearch.search.suggest.SuggestionBuilder<CompletionSuggestionBuilder>
-
- org.elasticsearch.search.suggest.completion.CompletionSuggestionBuilder
-
- All Implemented Interfaces:
NamedWriteable
,Writeable
,ToXContent
,ToXContentFragment
public class CompletionSuggestionBuilder extends SuggestionBuilder<CompletionSuggestionBuilder>
Defines a suggest command based on a prefix, typically to provide "auto-complete" functionality for users as they type search terms. The implementation of the completion service uses FSTs that are created at index-time and so must be defined in the mapping with the type "completion" before indexing.
-
-
Nested Class Summary
-
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 Modifier and Type Field Description protected BytesReference
contextBytes
protected FuzzyOptions
fuzzyOptions
protected RegexOptions
regexOptions
protected boolean
skipDuplicates
-
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 CompletionSuggestionBuilder(java.lang.String field)
CompletionSuggestionBuilder(StreamInput in)
Read from a stream.
-
Method Summary
Modifier and Type Method Description SuggestionSearchContext.SuggestionContext
build(QueryShardContext context)
CompletionSuggestionBuilder
contexts(java.util.Map<java.lang.String,java.util.List<? extends ToXContent>> queryContexts)
Sets query contexts for completionprotected boolean
doEquals(CompletionSuggestionBuilder 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 CompletionSuggestionBuilder
fromXContent(XContentParser parser)
java.lang.String
getWriteableName()
Returns the name of the writeable objectprotected XContentBuilder
innerToXContent(XContentBuilder builder, ToXContent.Params params)
CompletionSuggestionBuilder
prefix(java.lang.String prefix)
Sets the prefix to provide completions for.CompletionSuggestionBuilder
prefix(java.lang.String prefix, Fuzziness fuzziness)
Same asprefix(String)
with fuzziness offuzziness
CompletionSuggestionBuilder
prefix(java.lang.String prefix, FuzzyOptions fuzzyOptions)
Same asprefix(String)
with full fuzzy options seeFuzzyOptions.Builder
CompletionSuggestionBuilder
regex(java.lang.String regex)
Sets a regular expression pattern for prefixes to provide completions for.CompletionSuggestionBuilder
regex(java.lang.String regex, RegexOptions regexOptions)
Same asregex(String)
with full regular expression options seeRegexOptions.Builder
boolean
skipDuplicates()
Returns whether duplicate suggestions should be filtered out.CompletionSuggestionBuilder
skipDuplicates(boolean skipDuplicates)
Should duplicates be filtered or not.-
Methods inherited from class org.elasticsearch.search.suggest.SuggestionBuilder
analyzer, analyzer, equals, field, hashCode, populateCommonFields, prefix, 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
-
-
-
-
Field Detail
-
fuzzyOptions
protected FuzzyOptions fuzzyOptions
-
regexOptions
protected RegexOptions regexOptions
-
contextBytes
protected BytesReference contextBytes
-
skipDuplicates
protected boolean skipDuplicates
-
-
Constructor Detail
-
CompletionSuggestionBuilder
public CompletionSuggestionBuilder(java.lang.String field)
-
CompletionSuggestionBuilder
public CompletionSuggestionBuilder(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<CompletionSuggestionBuilder>
- Throws:
java.io.IOException
-
prefix
public CompletionSuggestionBuilder prefix(java.lang.String prefix)
Sets the prefix to provide completions for. The prefix gets analyzed by the suggest analyzer.- Overrides:
prefix
in classSuggestionBuilder<CompletionSuggestionBuilder>
-
prefix
public CompletionSuggestionBuilder prefix(java.lang.String prefix, Fuzziness fuzziness)
Same asprefix(String)
with fuzziness offuzziness
-
prefix
public CompletionSuggestionBuilder prefix(java.lang.String prefix, FuzzyOptions fuzzyOptions)
Same asprefix(String)
with full fuzzy options seeFuzzyOptions.Builder
-
regex
public CompletionSuggestionBuilder regex(java.lang.String regex)
Sets a regular expression pattern for prefixes to provide completions for.- Overrides:
regex
in classSuggestionBuilder<CompletionSuggestionBuilder>
-
regex
public CompletionSuggestionBuilder regex(java.lang.String regex, RegexOptions regexOptions)
Same asregex(String)
with full regular expression options seeRegexOptions.Builder
-
contexts
public CompletionSuggestionBuilder contexts(java.util.Map<java.lang.String,java.util.List<? extends ToXContent>> queryContexts)
Sets query contexts for completion- Parameters:
queryContexts
- named query contexts seeCategoryQueryContext
andGeoQueryContext
-
skipDuplicates
public boolean skipDuplicates()
Returns whether duplicate suggestions should be filtered out.
-
skipDuplicates
public CompletionSuggestionBuilder skipDuplicates(boolean skipDuplicates)
Should duplicates be filtered or not. Defaults tofalse
.
-
innerToXContent
protected XContentBuilder innerToXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
- Specified by:
innerToXContent
in classSuggestionBuilder<CompletionSuggestionBuilder>
- Throws:
java.io.IOException
-
fromXContent
public static CompletionSuggestionBuilder 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<CompletionSuggestionBuilder>
- 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(CompletionSuggestionBuilder other)
Description copied from class:SuggestionBuilder
Indicates whether some otherSuggestionBuilder
of the same type is "equal to" this one.- Specified by:
doEquals
in classSuggestionBuilder<CompletionSuggestionBuilder>
-
doHashCode
protected int doHashCode()
Description copied from class:SuggestionBuilder
HashCode for the subclass ofSuggestionBuilder
to implement.- Specified by:
doHashCode
in classSuggestionBuilder<CompletionSuggestionBuilder>
-
-