class Sunspot::Search::Highlight
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.
Attributes
field_name[R]
The name of the field in which the highlight appeared.
Public Instance Methods
format(&block)
click to toggle source
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.
Example¶ ↑
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
Also aliased as: formatted