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)


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

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.



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

def context
  @context
end

#search_builderObject (readonly)

Returns the value of attribute search_builder.



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

def search_builder
  @search_builder
end

Instance Method Details

#search_results(access) ⇒ Object

Parameters:

  • access (Symbol)

    :read or :edit



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

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

#search_results_with_work_count(access, join_field: "isPartOf_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: "isPartOf_ssim")

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

Returns:



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

def search_results_with_work_count(access, join_field: "isPartOf_ssim")
  admin_sets = search_results(access)
  ids = admin_sets.map(&:id).join(',')
  query = "{!terms f=#{join_field}}#{ids}"
  results = ActiveFedora::SolrService.instance.conn.get(
    ActiveFedora::SolrService.select_path,
    params: { fq: query,
              'facet.field' => join_field }
  )
  counts = results['facet_counts']['facet_fields'][join_field].each_slice(2).to_h
  file_counts = count_files(results)
  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