Class: Hyrax::CustomQueries::FindCountBy
- Inherits:
-
Object
- Object
- Hyrax::CustomQueries::FindCountBy
- Defined in:
- app/services/hyrax/custom_queries/find_count_by.rb
Overview
Instance Attribute Summary collapse
-
#query_service ⇒ Object
readonly
Returns the value of attribute query_service.
Class Method Summary collapse
Instance Method Summary collapse
- #find_count_by(hash = {}, models: nil) ⇒ Object
-
#initialize(query_service:) ⇒ FindCountBy
constructor
A new instance of FindCountBy.
Constructor Details
#initialize(query_service:) ⇒ FindCountBy
Returns a new instance of FindCountBy.
11 12 13 |
# File 'app/services/hyrax/custom_queries/find_count_by.rb', line 11 def initialize(query_service:) @query_service = query_service end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
15 16 17 |
# File 'app/services/hyrax/custom_queries/find_count_by.rb', line 15 def query_service @query_service end |
Class Method Details
.queries ⇒ Object
7 8 9 |
# File 'app/services/hyrax/custom_queries/find_count_by.rb', line 7 def self.queries [:find_count_by] end |
Instance Method Details
#find_count_by(hash = {}, models: nil) ⇒ Object
Note:
this is an unoptimized default implementation of this custom query. it’s Hyrax’s policy to provide such implementations of custom queries in use for cross-compatibility of Valkyrie query services. it’s advisable to provide an optimized query for the specific adapter.
26 27 28 29 30 31 |
# File 'app/services/hyrax/custom_queries/find_count_by.rb', line 26 def find_count_by(hash = {}, models: nil) return nil if models.empty? && hash.blank? flat_hash = hash.map { |k, v| "#{k}: \"#{v}\"" }.join(' ') flat_hash += " has_model_ssim: (#{models.map { |m| "\"#{m}\"" }.join(' OR ')})" unless models.empty? Hyrax::SolrService.count(flat_hash) end |