Class: Hyrax::AdminSetService

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

Overview

Returns AdminSets that the current user has permission to use.

Defined Under Namespace

Classes: SearchResultForWorkCount

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, search_builder = default_search_builder) ⇒ AdminSetService

Returns a new instance of AdminSetService.

Parameters:

  • context (#repository, #blacklight_config, #current_ability)


11
12
13
14
# File 'app/services/hyrax/admin_set_service.rb', line 11

def initialize(context, search_builder = default_search_builder)
  @context = context
  @search_builder = search_builder
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'app/services/hyrax/admin_set_service.rb', line 6

def context
  @context
end

#search_builderObject (readonly)

Returns the value of attribute search_builder.



6
7
8
# File 'app/services/hyrax/admin_set_service.rb', line 6

def search_builder
  @search_builder
end

Instance Method Details

#search_results(access) ⇒ Object

Parameters:

  • access (Symbol)

    :deposit, :read or :edit



17
18
19
20
# File 'app/services/hyrax/admin_set_service.rb', line 17

def search_results(access)
  response = context.blacklight_config.repository.search(builder(access))
  response.documents
end

#search_results_with_work_count(access, join_field: "#{Hyrax.config.admin_set_predicate.qname.last}_ssim") ⇒ Array<Hyrax::AdminSetService::SearchResultForWorkCount>

This performs a two pass query, first getting the AdminSets and then getting the work and file counts

Parameters:

  • access (Symbol)

    :read or :edit

  • join_field (String) (defaults to: "#{Hyrax.config.admin_set_predicate.qname.last}_ssim")

    how are we joining the admin_set ids (by default “isPartOf_ssim”)

Returns:



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/hyrax/admin_set_service.rb', line 29

def search_results_with_work_count(access, join_field: "#{Hyrax.config.admin_set_predicate.qname.last}_ssim")
  admin_sets = search_results(access)
  ids = admin_sets.map(&:id).join(',')
  query = "{!terms f=#{join_field}}#{ids}"
  results = Hyrax::SolrService.get(fq: query, rows: 0, 'facet.field': join_field)

  counts = results['facet_counts']['facet_fields'][join_field].each_slice(2).to_h
  file_counts = count_files(admin_sets)
  admin_sets.map do |admin_set|
    SearchResultForWorkCount.new(admin_set, counts[admin_set.id].to_i, file_counts[admin_set.id].to_i)
  end
end