Class: Hyrax::CollectionMemberSearchBuilder

Inherits:
SearchBuilder
  • Object
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

Instance Method Summary collapse

Methods included from FilterByType

#filter_models

Constructor Details

#initialize(scope:, collection:, search_includes_models: :works) ⇒ CollectionMemberSearchBuilder

Returns a new instance of CollectionMemberSearchBuilder.

Parameters:

  • Typically (scope)

    the controller object

  • :works, (Symbol)

    :collections, (anything else retrieves both)


15
16
17
18
19
20
21
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 15

def initialize(scope:,
               collection:,
               search_includes_models: :works)
  @collection = collection
  @search_includes_models = search_includes_models
  super(scope)
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection


5
6
7
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 5

def collection
  @collection
end

#search_includes_modelsObject (readonly)

Returns the value of attribute search_includes_models


5
6
7
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 5

def search_includes_models
  @search_includes_models
end

Instance Method Details

#member_of_collection(solr_parameters) ⇒ Object

include filters into the query to only include the collection memebers


24
25
26
27
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 24

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


30
31
32
33
34
35
36
37
38
# File 'app/search_builders/hyrax/collection_member_search_builder.rb', line 30

def models
  case search_includes_models
  when :collections
    collection_classes
  when :works
    work_classes
  else super # super includes both works and collections
  end
end