class Elasticsearch::DSL::Search::Highlight
Wraps the `highlight` part of a search definition
@see www.elastic.co/guide/en/elasticsearch/reference/current/search-request-highlighting.html
Public Class Methods
new(*args, &block)
click to toggle source
Calls superclass method
Elasticsearch::DSL::Search::BaseComponent::new
# File lib/elasticsearch/dsl/search/highlight.rb, line 29 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/elasticsearch/dsl/search/highlight.rb, line 87 def encoder(value) @value[:encoder] = value end
Also aliased as: 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/elasticsearch/dsl/search/highlight.rb, line 69 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/elasticsearch/dsl/search/highlight.rb, line 45 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
to_hash()
click to toggle source
Convert the definition to a Hash
@return [Hash]
# File lib/elasticsearch/dsl/search/highlight.rb, line 101 def to_hash call @hash = @value @hash end