class OpenSearch::DSL::Search::Highlight

Wraps the ‘highlight` part of a search definition

Public Class Methods

new(*args, &block) click to toggle source
# File lib/opensearch/dsl/search/highlight.rb, line 37
def initialize(*args, &block)
  @value = args.pop || {}
  super
end

Public Instance Methods

encoder(value) click to toggle source

Specify the ‘encoder` option for highlighting

# File lib/opensearch/dsl/search/highlight.rb, line 95
def encoder(value)
  @value[:encoder] = value
end
Also aliased as: encoder=
encoder=(value)
Alias for: encoder
field(name, options={}) click to toggle source

Specify a single field to highlight

@example

search do
  highlight do
    field :title, fragment_size: 0
    field :body if options[:comments]
  end
end
# File lib/opensearch/dsl/search/highlight.rb, line 77
def field(name, options={})
  (@value[:fields] ||= {}).update name.to_sym => options
end
fields(value_or_name) click to toggle source

Specify the fields to highlight

@example

search do
  highlight do
    fields [:title, :body]
    field  :comments.body if options[:comments]
  end
end
# File lib/opensearch/dsl/search/highlight.rb, line 53
def fields(value_or_name)
  value = case value_or_name
    when Hash
      value_or_name
    when Array
      value_or_name.reduce({}) { |sum, item| sum.update item.to_sym => {}; sum }
    else
  end

  (@value[:fields] ||= {}).update value
  self
end
post_tags(*value) click to toggle source

Specify the closing tags for the highlighted snippets

# File lib/opensearch/dsl/search/highlight.rb, line 89
def post_tags(*value)
  @value[:post_tags] = value.flatten
end
Also aliased as: post_tags=
post_tags=(*value)
Alias for: post_tags
pre_tags(*value) click to toggle source

Specify the opening tags for the highlighted snippets

# File lib/opensearch/dsl/search/highlight.rb, line 83
def pre_tags(*value)
  @value[:pre_tags] = value.flatten
end
Also aliased as: pre_tags=
pre_tags=(*value)
Alias for: pre_tags
tags_schema(value) click to toggle source

Specify the ‘tags_schema` option for highlighting

# File lib/opensearch/dsl/search/highlight.rb, line 101
def tags_schema(value)
  @value[:tags_schema] = value
end
Also aliased as: tags_schema=
tags_schema=(value)
Alias for: tags_schema
to_hash() click to toggle source

Convert the definition to a Hash

@return [Hash]

# File lib/opensearch/dsl/search/highlight.rb, line 109
def to_hash
  call
  @hash = @value
  @hash
end