Module: Blacklight::Document

Extended by:
ActiveSupport::Concern
Includes:
CacheKey, Export, SchemaOrg, SemanticFields
Included in:
Solr::Document
Defined in:
app/models/concerns/blacklight/document.rb,
app/components/blacklight/document/group_component.rb,
app/components/blacklight/document/action_component.rb,
app/components/blacklight/document/actions_component.rb,
app/components/blacklight/document/bookmark_component.rb,
app/components/blacklight/document/citation_component.rb,
app/components/blacklight/document/thumbnail_component.rb,
app/models/concerns/blacklight/document/semantic_fields.rb,
app/models/concerns/blacklight/document/active_model_shim.rb,
app/components/blacklight/document/more_like_this_component.rb

Overview

Introduction

Blacklight::Document is the module with logic for a class representing an individual document returned from Solr results. It can be added in to any local class you want, but in default Blacklight a SolrDocument class is provided for you which is pretty much a blank class “include”ing Blacklight::Document.

Blacklight::Document provides some DefaultFinders.

It also provides support for Document Extensions, which advertise supported transformation formats.

Defined Under Namespace

Modules: ActiveModelShim, CacheKey, DublinCore, Email, Export, Extensions, SchemaOrg, SemanticFields, Sms Classes: ActionComponent, ActionsComponent, BookmarkComponent, CitationComponent, GroupComponent, MoreLikeThisComponent, ThumbnailComponent

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Export

#export_as, #export_formats, #exports_as?, #will_export_as

Methods included from CacheKey

#cache_key, #cache_version_key

Methods included from SemanticFields

#to_semantic_values

Methods included from SchemaOrg

#itemtype

Instance Attribute Details

#_sourceObject (readonly)

Returns the value of attribute _source.



33
34
35
# File 'app/models/concerns/blacklight/document.rb', line 33

def _source
  @_source
end

#responseObject (readonly) Also known as: solr_response

Returns the value of attribute response.



33
34
35
# File 'app/models/concerns/blacklight/document.rb', line 33

def response
  @response
end

Instance Method Details

#fetch(key, *default) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'app/models/concerns/blacklight/document.rb', line 73

def fetch key, *default
  if key? key
    self[key]
  elsif default.empty? && !block_given?
    raise KeyError, "key not found \"#{key}\""
  else
    (yield(self) if block_given?) || default.first
  end
end

#first(key) ⇒ Object



83
84
85
# File 'app/models/concerns/blacklight/document.rb', line 83

def first key
  Array(self[key]).first
end

#has?(k, *values) ⇒ Boolean Also known as: has_field?

Helper method to check if value/multi-values exist for a given key. The value can be a string, or a RegExp Multiple “values” can be given; only one needs to match.

Example: doc.has?(:location_facet) doc.has?(:location_facet, 'Clemons') doc.has?(:id, 'h009', /^u/i)

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/models/concerns/blacklight/document.rb', line 52

def has?(k, *values)
  if !key?(k)
    false
  elsif values.empty?
    self[k].present?
  else
    Array(values).any? do |expected|
      Array(self[k]).any? do |actual|
        case expected
        when Regexp
          actual =~ expected
        else
          actual == expected
        end
      end
    end
  end
end

#has_highlight_field?(_k) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'app/models/concerns/blacklight/document.rb', line 96

def has_highlight_field? _k
  false
end

#highlight_field(_k) ⇒ Object



100
101
102
# File 'app/models/concerns/blacklight/document.rb', line 100

def highlight_field _k
  nil
end

#initialize(source_doc = {}, response = nil) ⇒ Object



38
39
40
41
42
# File 'app/models/concerns/blacklight/document.rb', line 38

def initialize(source_doc = {}, response = nil)
  @_source = ActiveSupport::HashWithIndifferentAccess.new(source_doc).freeze
  @response = response
  apply_extensions
end

#inspectObject



87
88
89
90
# File 'app/models/concerns/blacklight/document.rb', line 87

def inspect
  fields = inspector_fields.map { |field| "#{field}: #{public_send(field)}" }.join(", ")
  "#<#{self.class.name}:#{object_id} #{fields}>"
end

#more_like_thisObject

Implementations that support More-Like-This should override this method to return an array of documents that are like this one.



107
108
109
# File 'app/models/concerns/blacklight/document.rb', line 107

def more_like_this
  []
end

#to_partial_pathObject



92
93
94
# File 'app/models/concerns/blacklight/document.rb', line 92

def to_partial_path
  'catalog/document'
end