Class: Hyrax::Collections::CollectionMemberService

Inherits:
SearchService
  • Object
show all
Defined in:
app/services/hyrax/collections/collection_member_service.rb

Overview

Retrieves collection members

Instance Attribute Summary

Attributes inherited from SearchService

#blacklight_config, #context

Instance Method Summary collapse

Methods inherited from SearchService

#fetch, #search_builder, #search_results

Constructor Details

#initialize(scope:, collection:, params:, user_params: nil, current_ability: nil, search_builder_class: Hyrax::CollectionMemberSearchBuilder) ⇒ CollectionMemberService

Returns a new instance of CollectionMemberService.

Parameters:

  • scope (#repository)

    Typically a controller object which responds to :repository

  • collection (::Collection)
  • params (ActionController::Parameters)

    the query params

  • user_params (ActionController::Parameters) (defaults to: nil)
  • current_ability (::Ability) (defaults to: nil)
  • search_builder_class (Class) (defaults to: Hyrax::CollectionMemberSearchBuilder)

    a SearchBuilder


14
15
16
17
18
19
20
21
22
23
# File 'app/services/hyrax/collections/collection_member_service.rb', line 14

def initialize(scope:, collection:, params:, user_params: nil, current_ability: nil, search_builder_class: Hyrax::CollectionMemberSearchBuilder) # rubocop:disable Metrics/ParameterLists
  super(
    config: scope.blacklight_config,
    user_params: user_params || params,
    collection: collection,
    scope: scope,
    current_ability: current_ability || scope.current_ability,
    search_builder_class: search_builder_class
  )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hyrax::SearchService

Instance Method Details

#available_member_subcollectionsBlacklight::Solr::Response

Collections which are members of the given collection

Returns:

  • (Blacklight::Solr::Response)

    (up to 50 solr documents)


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

def available_member_subcollections
  response, _docs = search_results do |builder|
    # To differentiate current page for works vs subcollections, we have to use a sub_collection_page
    # param. Map this to the page param before querying for subcollections, if it's present
    builder.page(user_params[:sub_collection_page])
    builder.search_includes_models = :collections
    builder
  end
  response
end

#available_member_work_idsBlacklight::Solr::Response

Work ids of the works which are members of the given collection

Returns:

  • (Blacklight::Solr::Response)

62
63
64
65
66
67
68
69
# File 'app/services/hyrax/collections/collection_member_service.rb', line 62

def available_member_work_ids
  response, _docs = search_results do |builder|
    builder.search_includes_models = :works
    builder.merge(fl: 'id')
    builder
  end
  response
end

#available_member_worksBlacklight::Solr::Response

Works which are members of the given collection

Returns:

  • (Blacklight::Solr::Response)

48
49
50
51
52
53
54
# File 'app/services/hyrax/collections/collection_member_service.rb', line 48

def available_member_works
  response, _docs = search_results do |builder|
    builder.search_includes_models = :works
    builder
  end
  response
end