Class: Hyrax::CollectionMemberSearchBuilder

Inherits:
CollectionSearchBuilder show all
Includes:
FilterByType
Defined in:
app/search_builders/hyrax/collection_member_search_builder.rb

Overview

This search builder requires that a accessor named “collection” exists in the scope

Instance Attribute Summary collapse

Attributes inherited from CollectionSearchBuilder

#access

Instance Method Summary collapse

Methods included from FilterByType

#filter_models

Methods inherited from CollectionSearchBuilder

#add_sorting_to_solr, #discovery_permissions, #gated_discovery_filters, #sort_field, #with_access

Constructor Details

#initialize(*args, scope: nil, collection: nil, search_includes_models: nil) ⇒ CollectionMemberSearchBuilder

Returns a new instance of CollectionMemberSearchBuilder.

Parameters:

  • scope (Object) (defaults to: nil)

    Typically the controller object

  • search_includes_models (Symbol) (defaults to: nil)

    :works or :collections; (anything else retrieves both)


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 16

def initialize(*args,
               scope: nil,
               collection: nil,
               search_includes_models: nil)
  @collection = collection
  @search_includes_models = search_includes_models

  if args.any?
    super(*args)
  else
    super(scope)
  end
end

Instance Attribute Details

#collectionObject


30
31
32
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 30

def collection
  @collection || (scope.context[:collection] if scope&.respond_to?(:context))
end

#search_includes_modelsObject


34
35
36
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 34

def search_includes_models
  @search_includes_models || :works
end

Instance Method Details

#member_of_collection(solr_parameters) ⇒ Object

include filters into the query to only include the collection memebers


39
40
41
42
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 39

def member_of_collection(solr_parameters)
  solr_parameters[:fq] ||= []
  solr_parameters[:fq] << "#{collection_membership_field}:#{collection.id}"
end

#modelsObject

This overrides the models in FilterByType


45
46
47
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 45

def models
  work_classes + collection_classes
end