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
-
#_source ⇒ Object
readonly
Returns the value of attribute _source.
-
#response ⇒ Object
(also: #solr_response)
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #fetch(key, *default) ⇒ Object
- #first(key) ⇒ Object
-
#has?(k, *values) ⇒ Boolean
(also: #has_field?)
Helper method to check if value/multi-values exist for a given key.
- #has_highlight_field?(_k) ⇒ Boolean
- #highlight_field(_k) ⇒ Object
- #initialize(source_doc = {}, response = nil) ⇒ Object
-
#more_like_this ⇒ Object
Implementations that support More-Like-This should override this method to return an array of documents that are like this one.
- #to_partial_path ⇒ Object
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
Methods included from SchemaOrg
Instance Attribute Details
#_source ⇒ Object (readonly)
Returns the value of attribute _source.
31 32 33 |
# File 'app/models/concerns/blacklight/document.rb', line 31 def _source @_source end |
#response ⇒ Object (readonly) Also known as: solr_response
Returns the value of attribute response.
31 32 33 |
# File 'app/models/concerns/blacklight/document.rb', line 31 def response @response end |
Instance Method Details
#fetch(key, *default) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'app/models/concerns/blacklight/document.rb', line 71 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
81 82 83 |
# File 'app/models/concerns/blacklight/document.rb', line 81 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)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/concerns/blacklight/document.rb', line 50 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
89 90 91 |
# File 'app/models/concerns/blacklight/document.rb', line 89 def has_highlight_field? _k false end |
#highlight_field(_k) ⇒ Object
93 94 95 |
# File 'app/models/concerns/blacklight/document.rb', line 93 def highlight_field _k nil end |
#initialize(source_doc = {}, response = nil) ⇒ Object
36 37 38 39 40 |
# File 'app/models/concerns/blacklight/document.rb', line 36 def initialize(source_doc = {}, response = nil) @_source = ActiveSupport::HashWithIndifferentAccess.new(source_doc).freeze @response = response apply_extensions end |
#more_like_this ⇒ Object
Implementations that support More-Like-This should override this method to return an array of documents that are like this one.
100 101 102 |
# File 'app/models/concerns/blacklight/document.rb', line 100 def more_like_this [] end |
#to_partial_path ⇒ Object
85 86 87 |
# File 'app/models/concerns/blacklight/document.rb', line 85 def to_partial_path 'catalog/document' end |