Class SuggestionBuilder<T extends SuggestionBuilder<T>>

java.lang.Object
org.elasticsearch.search.suggest.SuggestionBuilder<T>
All Implemented Interfaces:
NamedWriteable, Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentFragment
Direct Known Subclasses:
CompletionSuggestionBuilder, PhraseSuggestionBuilder, TermSuggestionBuilder

public abstract class SuggestionBuilder<T extends SuggestionBuilder<T>> extends Object implements NamedWriteable, org.elasticsearch.common.xcontent.ToXContentFragment
Base class for the different suggestion implementations.
  • Field Details

    • field

      protected final String field
    • text

      protected String text
    • prefix

      protected String prefix
    • regex

      protected String regex
    • analyzer

      protected String analyzer
    • size

      protected Integer size
    • shardSize

      protected Integer shardSize
    • TEXT_FIELD

      protected static final org.elasticsearch.common.xcontent.ParseField TEXT_FIELD
    • PREFIX_FIELD

      protected static final org.elasticsearch.common.xcontent.ParseField PREFIX_FIELD
    • REGEX_FIELD

      protected static final org.elasticsearch.common.xcontent.ParseField REGEX_FIELD
    • FIELDNAME_FIELD

      protected static final org.elasticsearch.common.xcontent.ParseField FIELDNAME_FIELD
    • ANALYZER_FIELD

      protected static final org.elasticsearch.common.xcontent.ParseField ANALYZER_FIELD
    • SIZE_FIELD

      protected static final org.elasticsearch.common.xcontent.ParseField SIZE_FIELD
    • SHARDSIZE_FIELD

      protected static final org.elasticsearch.common.xcontent.ParseField SHARDSIZE_FIELD
  • Constructor Details

    • SuggestionBuilder

      protected SuggestionBuilder(String field)
      Creates a new suggestion.
      Parameters:
      field - field to execute suggestions on
    • SuggestionBuilder

      protected SuggestionBuilder(String field, SuggestionBuilder<?> in)
      internal copy constructor that copies over all class fields from second SuggestionBuilder except field name.
    • SuggestionBuilder

      protected SuggestionBuilder(StreamInput in) throws IOException
      Read from a stream.
      Throws:
      IOException
  • Method Details

    • writeTo

      public final void writeTo(StreamOutput out) throws IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      IOException
    • doWriteTo

      protected abstract void doWriteTo(StreamOutput out) throws IOException
      Throws:
      IOException
    • text

      public T text(String text)
      Same as in SuggestBuilder.setGlobalText(String), but in the suggestion scope.
    • text

      public String text()
      get the text for this suggestion
    • prefix

      protected T prefix(String prefix)
    • prefix

      public String prefix()
      get the prefix for this suggestion
    • regex

      protected T regex(String regex)
    • regex

      public String regex()
      get the regex for this suggestion
    • field

      public String field()
      get the field() parameter
    • analyzer

      public T analyzer(String analyzer)
      Sets the analyzer to analyse to suggest text with. Defaults to the search analyzer of the suggest field.
    • analyzer

      public String analyzer()
      get the analyzer() parameter
    • size

      public T size(int size)
      Sets the maximum suggestions to be returned per suggest text term.
    • size

      public Integer size()
      get the size() parameter
    • shardSize

      public T shardSize(Integer shardSize)
      Sets the maximum number of suggested term to be retrieved from each individual shard. During the reduce phase the only the top N suggestions are returned based on the size option. Defaults to the size option.

      Setting this to a value higher than the `size` can be useful in order to get a more accurate document frequency for suggested terms. Due to the fact that terms are partitioned amongst shards, the shard level document frequencies of suggestions may not be precise. Increasing this will make these document frequencies more precise.

    • shardSize

      public Integer shardSize()
      get the shardSize() parameter
    • toXContent

      public org.elasticsearch.common.xcontent.XContentBuilder toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException
      Specified by:
      toXContent in interface org.elasticsearch.common.xcontent.ToXContent
      Throws:
      IOException
    • innerToXContent

      protected abstract org.elasticsearch.common.xcontent.XContentBuilder innerToXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws IOException
      Throws:
      IOException
    • build

      Throws:
      IOException
    • populateCommonFields

      protected void populateCommonFields(SearchExecutionContext context, SuggestionSearchContext.SuggestionContext suggestionContext)
      Transfers the text, prefix, regex, analyzer, field, size and shard size settings from the original SuggestionBuilder to the target SuggestionSearchContext.SuggestionContext
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object
    • doEquals

      protected abstract boolean doEquals(T other)
      Indicates whether some other SuggestionBuilder of the same type is "equal to" this one.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • doHashCode

      protected abstract int doHashCode()
      HashCode for the subclass of SuggestionBuilder to implement.