Class: Hyrax::AdminSetService
- Inherits:
-
Object
- Object
- Hyrax::AdminSetService
- 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
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#search_builder ⇒ Object
readonly
Returns the value of attribute search_builder.
Instance Method Summary collapse
-
#initialize(context, search_builder = default_search_builder) ⇒ AdminSetService
constructor
A new instance of AdminSetService.
- #search_results(access) ⇒ Object
-
#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.
Constructor Details
#initialize(context, search_builder = default_search_builder) ⇒ AdminSetService
Returns a new instance of AdminSetService.
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
#context ⇒ Object (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_builder ⇒ Object (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
17 18 19 20 |
# File 'app/services/hyrax/admin_set_service.rb', line 17 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/services/hyrax/admin_set_service.rb', line 29 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 |