Module: Blacklight::Document
- Extended by:
- ActiveSupport::Concern
- Includes:
- Attributes, CacheKey, Export, SchemaOrg, SemanticFields
- Included in:
- Solr::Document
- Defined in:
- app/models/concerns/blacklight/document.rb,
app/components/blacklight/document/group_component.rb,
app/models/concerns/blacklight/document/attributes.rb,
app/components/blacklight/document/action_component.rb,
app/components/blacklight/document/actions_component.rb,
app/components/blacklight/document/sidebar_component.rb,
app/components/blacklight/document/bookmark_component.rb,
app/components/blacklight/document/citation_component.rb,
app/components/blacklight/document/thumbnail_component.rb,
app/components/blacklight/document/show_tools_component.rb,
app/models/concerns/blacklight/document/semantic_fields.rb,
app/components/blacklight/document/page_header_component.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, Attributes, CacheKey, DublinCore, Export, Extensions, SchemaOrg, SemanticFields Classes: ActionComponent, ActionsComponent, BookmarkComponent, CitationComponent, GroupComponent, MoreLikeThisComponent, PageHeaderComponent, ShowToolsComponent, SidebarComponent, ThumbnailComponent
Constant Summary collapse
- Email =
Module.new do def self.included(mod) Blacklight.deprecation.warn("Blacklight::Document::Email is deprecated and will be removed (included in #{mod}).") end end
- Sms =
Module.new do def self.included(mod) Blacklight.deprecation.warn("Blacklight::Document::Sms is deprecated and will be removed (included in #{mod}).") end end
- NO_DEFAULT_PROVIDED =
:nodoc:
Object.new
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 = NO_DEFAULT_PROVIDED) ⇒ 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
- #inspect ⇒ 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.
45 46 47 |
# File 'app/models/concerns/blacklight/document.rb', line 45 def _source @_source end |
#response ⇒ Object (readonly) Also known as: solr_response
Returns the value of attribute response.
45 46 47 |
# File 'app/models/concerns/blacklight/document.rb', line 45 def response @response end |
Instance Method Details
#fetch(key, default = NO_DEFAULT_PROVIDED) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/models/concerns/blacklight/document.rb', line 86 def fetch key, default = NO_DEFAULT_PROVIDED if key? key self[key] elsif block_given? yield(self) if block_given? elsif default != NO_DEFAULT_PROVIDED if default.respond_to?(:call) default.call(self) else default end else raise KeyError, "key not found \"#{key}\"" end end |
#first(key) ⇒ Object
102 103 104 |
# File 'app/models/concerns/blacklight/document.rb', line 102 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)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/concerns/blacklight/document.rb', line 64 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
115 116 117 |
# File 'app/models/concerns/blacklight/document.rb', line 115 def has_highlight_field? _k false end |
#highlight_field(_k) ⇒ Object
119 120 121 |
# File 'app/models/concerns/blacklight/document.rb', line 119 def highlight_field _k nil end |
#initialize(source_doc = {}, response = nil) ⇒ Object
50 51 52 53 54 |
# File 'app/models/concerns/blacklight/document.rb', line 50 def initialize(source_doc = {}, response = nil) @_source = ActiveSupport::HashWithIndifferentAccess.new(source_doc).freeze @response = response apply_extensions end |
#inspect ⇒ Object
106 107 108 109 |
# File 'app/models/concerns/blacklight/document.rb', line 106 def inspect fields = inspector_fields.map { |field| "#{field}: #{public_send(field)}" }.join(", ") "#<#{self.class.name}:#{object_id} #{fields}>" 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.
126 127 128 |
# File 'app/models/concerns/blacklight/document.rb', line 126 def more_like_this [] end |
#to_partial_path ⇒ Object
111 112 113 |
# File 'app/models/concerns/blacklight/document.rb', line 111 def to_partial_path 'catalog/document' end |