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
- 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.
34 35 36 |
# File 'app/models/concerns/blacklight/document.rb', line 34 def _source @_source end |
#response ⇒ Object (readonly) Also known as: solr_response
Returns the value of attribute response.
34 35 36 |
# File 'app/models/concerns/blacklight/document.rb', line 34 def response @response end |
Instance Method Details
#fetch(key, default = NO_DEFAULT_PROVIDED) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/concerns/blacklight/document.rb', line 75 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
91 92 93 |
# File 'app/models/concerns/blacklight/document.rb', line 91 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)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/concerns/blacklight/document.rb', line 53 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
104 105 106 |
# File 'app/models/concerns/blacklight/document.rb', line 104 def has_highlight_field? _k false end |
#highlight_field(_k) ⇒ Object
108 109 110 |
# File 'app/models/concerns/blacklight/document.rb', line 108 def highlight_field _k nil end |
#initialize(source_doc = {}, response = nil) ⇒ Object
39 40 41 42 43 |
# File 'app/models/concerns/blacklight/document.rb', line 39 def initialize(source_doc = {}, response = nil) @_source = ActiveSupport::HashWithIndifferentAccess.new(source_doc).freeze @response = response apply_extensions end |
#inspect ⇒ Object
95 96 97 98 |
# File 'app/models/concerns/blacklight/document.rb', line 95 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.
115 116 117 |
# File 'app/models/concerns/blacklight/document.rb', line 115 def more_like_this [] end |
#to_partial_path ⇒ Object
100 101 102 |
# File 'app/models/concerns/blacklight/document.rb', line 100 def to_partial_path 'catalog/document' end |