Module: BlacklightHighlight::SolrDocumentExtension

Extended by:
ActiveSupport::Concern
Defined in:
lib/blacklight_highlight/solr_document_extension.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object

Override RSolr::Doc methods with highlighting equivalents



22
23
24
25
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 22

def [] key
  return highlight(key) if highlight?(key)
  super(key)
end

#highlight(key) ⇒ Object

Get the (html-safe) highlight values for a field

Parameters:

  • key (String)


37
38
39
40
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 37

def highlight key
  return unless highlight? key
  highlight_fields[key].map { |x| x.html_safe }
end

#highlight?(key) ⇒ Boolean

Does the field have highlighting values?

Parameters:

  • key (String)

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 45

def highlight? key
  return false if key.nil? or key == self.class.unique_key

  if self.class.highlight.include? key.to_sym
    return true
  elsif !self.class.highlight.empty?
    return false
  end

 !highlight_fields[key].blank?
end

#highlight_fieldsObject



57
58
59
60
61
62
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 57

def highlight_fields
  @highlight_fields ||= begin
    return {} unless solr_response and solr_response.respond_to? :highlight
    solr_response.highlight(self)
  end
end

#key?(key) ⇒ Boolean

Override RSolr::Doc methods with highlighting equivalents

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 29

def key? key
  return true if highlight?(key)
  super(key)
end