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.
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
#context ⇒ Object (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_builder ⇒ Object (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
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
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 |