A Highlight represents a single highlighted fragment of text from a document. Depending on the highlighting parameters used for search, there may be more than one Highlight object for a given field in a given result.
The name of the field in which the highlight appeared.
Returns the highlighted text with formatting according to the template given in &block. When no block is given, <em> and </em> are used to surround the highlight.
search.highlights(:body).first.format { |word| "<strong>#{word}</strong>" }
# File lib/sunspot/search/highlight.rb, line 29 def format(&block) block ||= proc { |word| "<em>#{word}</em>" } @highlight.gsub(HIGHLIGHT_MATCHER) do block.call(Regexp.last_match[1]) end end