Class: Hyrax::CustomQueries::FindCountBy

Inherits:
Object
  • Object
show all
Defined in:
app/services/hyrax/custom_queries/find_count_by.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_serviceObject (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

.queriesObject



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.

Parameters:

  • hash (Hash) (defaults to: {})

    the hash representation of the query



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