Package org.elasticsearch.search.suggest
Class SuggestBuilder
java.lang.Object
org.elasticsearch.search.suggest.SuggestBuilder
- All Implemented Interfaces:
Writeable
,ToXContent
,ToXContentObject
public class SuggestBuilder extends java.lang.Object implements Writeable, ToXContentObject
Defines how to perform suggesting. This builders allows a number of global options to be specified and
an arbitrary number of
SuggestionBuilder
instances.
Suggesting works by suggesting terms/phrases that appear in the suggest text that are similar compared to the terms in provided text. These suggestions are based on several options described in this class.
-
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 static ParseField
GLOBAL_TEXT_FIELD
-
Constructor Summary
Constructors Constructor Description SuggestBuilder()
Build an empty SuggestBuilder.SuggestBuilder(StreamInput in)
Read from a stream. -
Method Summary
Modifier and Type Method Description SuggestBuilder
addSuggestion(java.lang.String name, SuggestionBuilder<?> suggestion)
Adds anSuggestionBuilder
instance under a user defined name.SuggestionSearchContext
build(QueryShardContext context)
boolean
equals(java.lang.Object other)
static SuggestBuilder
fromXContent(XContentParser parser)
java.lang.String
getGlobalText()
Gets the global suggest textjava.util.Map<java.lang.String,SuggestionBuilder<?>>
getSuggestions()
Get all theSuggestions
that were added to the globalSuggestBuilder
, together with their namesint
hashCode()
SuggestBuilder
setGlobalText(java.lang.String globalText)
Sets the text to provide suggestions for.java.lang.String
toString()
XContentBuilder
toXContent(XContentBuilder builder, ToXContent.Params params)
void
writeTo(StreamOutput out)
Write this into the StreamOutput.
-
Field Details
-
Constructor Details
-
SuggestBuilder
public SuggestBuilder()Build an empty SuggestBuilder. -
SuggestBuilder
Read from a stream.- Throws:
java.io.IOException
-
-
Method Details
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput. -
setGlobalText
Sets the text to provide suggestions for. The suggest text is a required option that needs to be set either via this setter or via theSuggestionBuilder.text(String)
method.The suggest text gets analyzed by the suggest analyzer or the suggest field search analyzer. For each analyzed token, suggested terms are suggested if possible.
-
getGlobalText
Gets the global suggest text -
addSuggestion
Adds anSuggestionBuilder
instance under a user defined name. The order in which theSuggestions
are added, is the same as in the response.- Throws:
java.lang.IllegalArgumentException
- if two suggestions added have the same name
-
getSuggestions
Get all theSuggestions
that were added to the globalSuggestBuilder
, together with their names -
toXContent
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException- Specified by:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
fromXContent
- Throws:
java.io.IOException
-
build
- Throws:
java.io.IOException
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-