Class HighlightBuilder

All Implemented Interfaces:
Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentObject, Rewriteable<HighlightBuilder>

public class HighlightBuilder extends AbstractHighlighterBuilder<HighlightBuilder>
A builder for search highlighting. Settings can control how large fields are summarized to show only selected snippets ("fragments") containing search terms.
See Also:
SearchSourceBuilder.highlight()
  • Field Details

    • DEFAULT_FORCE_SOURCE

      public static final boolean DEFAULT_FORCE_SOURCE
      default for whether to highlight fields based on the source even if stored separately
      See Also:
      Constant Field Values
    • DEFAULT_REQUIRE_FIELD_MATCH

      public static final boolean DEFAULT_REQUIRE_FIELD_MATCH
      default for whether a field should be highlighted only if a query matches that field
      See Also:
      Constant Field Values
    • DEFAULT_MAX_ANALYZED_OFFSET

      public static final Integer DEFAULT_MAX_ANALYZED_OFFSET
      default for whether to stop highlighting at the defined max_analyzed_offset to avoid exceptions for longer texts
    • DEFAULT_HIGHLIGHT_FILTER

      public static final boolean DEFAULT_HIGHLIGHT_FILTER
      default for whether fvh should provide highlighting on filter clauses
      See Also:
      Constant Field Values
    • DEFAULT_SCORE_ORDERED

      public static final boolean DEFAULT_SCORE_ORDERED
      default for highlight fragments being ordered by score
      See Also:
      Constant Field Values
    • DEFAULT_ENCODER

      public static final String DEFAULT_ENCODER
      the default encoder setting
      See Also:
      Constant Field Values
    • DEFAULT_PHRASE_LIMIT

      public static final int DEFAULT_PHRASE_LIMIT
      default for the maximum number of phrases the fvh will consider
      See Also:
      Constant Field Values
    • DEFAULT_NO_MATCH_SIZE

      public static final int DEFAULT_NO_MATCH_SIZE
      default for fragment size when there are no matches
      See Also:
      Constant Field Values
    • DEFAULT_NUMBER_OF_FRAGMENTS

      public static final int DEFAULT_NUMBER_OF_FRAGMENTS
      the default number of fragments for highlighting
      See Also:
      Constant Field Values
    • DEFAULT_FRAGMENT_CHAR_SIZE

      public static final int DEFAULT_FRAGMENT_CHAR_SIZE
      the default number of fragments size in characters
      See Also:
      Constant Field Values
    • DEFAULT_STYLED_PRE_TAG

      public static final String[] DEFAULT_STYLED_PRE_TAG
      the default opening tags when tag_schema = "styled"
    • DEFAULT_STYLED_POST_TAGS

      public static final String[] DEFAULT_STYLED_POST_TAGS
      the default closing tags when tag_schema = "styled"
  • Constructor Details

  • Method Details

    • doWriteTo

      protected void doWriteTo(StreamOutput out) throws IOException
      Specified by:
      doWriteTo in class AbstractHighlighterBuilder<HighlightBuilder>
      Throws:
      IOException
    • field

      public HighlightBuilder field(String name)
      Adds a field to be highlighted with default fragment size of 100 characters, and default number of fragments of 5 using the default encoder
      Parameters:
      name - The field to highlight
    • field

      public HighlightBuilder field(String name, int fragmentSize)
      Adds a field to be highlighted with a provided fragment size (in characters), and default number of fragments of 5.
      Parameters:
      name - The field to highlight
      fragmentSize - The size of a fragment in characters
    • field

      public HighlightBuilder field(String name, int fragmentSize, int numberOfFragments)
      Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.
      Parameters:
      name - The field to highlight
      fragmentSize - The size of a fragment in characters
      numberOfFragments - The (maximum) number of fragments
    • field

      public HighlightBuilder field(String name, int fragmentSize, int numberOfFragments, int fragmentOffset)
      Adds a field to be highlighted with a provided fragment size (in characters), and a provided (maximum) number of fragments.
      Parameters:
      name - The field to highlight
      fragmentSize - The size of a fragment in characters
      numberOfFragments - The (maximum) number of fragments
      fragmentOffset - The offset from the start of the fragment to the start of the highlight
    • field

      public HighlightBuilder field(HighlightBuilder.Field field)
    • fields

      public List<HighlightBuilder.Field> fields()
    • tagsSchema

      public HighlightBuilder tagsSchema(String schemaName)
      Set a tag scheme that encapsulates a built in pre and post tags. The allowed schemes are styled and default.
      Parameters:
      schemaName - The tag scheme name
    • encoder

      public HighlightBuilder encoder(String encoder)
      Set encoder for the highlighting are html and default.
      Parameters:
      encoder - name
    • encoder

      public String encoder()
      Getter for encoder(String)
    • useExplicitFieldOrder

      public HighlightBuilder useExplicitFieldOrder(boolean useExplicitFieldOrder)
      Send the fields to be highlighted using a syntax that is specific about the order in which they should be highlighted.
      Returns:
      this for chaining
    • useExplicitFieldOrder

      public Boolean useExplicitFieldOrder()
      Gets value set with useExplicitFieldOrder(boolean)
    • 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
      Overrides:
      toXContent in class AbstractHighlighterBuilder<HighlightBuilder>
      Throws:
      IOException
    • fromXContent

      public static HighlightBuilder fromXContent(org.elasticsearch.common.xcontent.XContentParser p)
    • build

      public SearchHighlightContext build(SearchExecutionContext context) throws IOException
      Throws:
      IOException
    • innerXContent

      public void innerXContent(org.elasticsearch.common.xcontent.XContentBuilder builder) throws IOException
      Specified by:
      innerXContent in class AbstractHighlighterBuilder<HighlightBuilder>
      Throws:
      IOException
    • doHashCode

      protected int doHashCode()
      Description copied from class: AbstractHighlighterBuilder
      fields only present in subclass should contribute to hashCode in the implementation
      Specified by:
      doHashCode in class AbstractHighlighterBuilder<HighlightBuilder>
    • doEquals

      protected boolean doEquals(HighlightBuilder other)
      Description copied from class: AbstractHighlighterBuilder
      fields only present in subclass should be checked for equality in the implementation
      Specified by:
      doEquals in class AbstractHighlighterBuilder<HighlightBuilder>
    • rewrite

      public HighlightBuilder rewrite(QueryRewriteContext ctx) throws IOException
      Description copied from interface: Rewriteable
      Rewrites this instance based on the provided context. The returned objects will be the same instance as this if no changes during the rewrite were applied.
      Throws:
      IOException