Module: BlacklightHighlight::SolrDocumentExtension

Defined in:
lib/blacklight_highlight/solr_document_extension.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(some_class) ⇒ Object



3
4
5
6
7
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 3

def self.included some_class
  some_class.after_initialize do
    solr_response.send(:extend, RSolr::Ext::Response::Highlight) unless solr_response.is_a? RSolr::Ext::Response::Highlight
  end
end

Instance Method Details

#[](key) ⇒ Object



9
10
11
12
13
14
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 9

def [] key
  return super(key) if key == self.class.unique_key
  return highlight(key) if highlight_fields.key?(key) and not highlight(key).blank?

  super(key)
end

#highlight(key = nil) ⇒ Object



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

def highlight key = nil
  return if key == self.class.unique_key
  highlight_fields[key]
end

#highlight_fieldsObject



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

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

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/blacklight_highlight/solr_document_extension.rb', line 16

def key? key
  return super(key) if key == self.class.unique_key
  return true if highlight_fields.key?(key)

  super(key)
end