Sha256: 749102bde46e0406b356ac8aafa4aa55ceba33128699982d2596ddbdeccc6081

Contents?: true

Size: 1.36 KB

Versions: 35

Compression:

Stored size: 1.36 KB

Contents

module Hyrax
  # This search builder requires that a accessor named "collection" exists in the scope
  class CollectionMemberSearchBuilder < ::SearchBuilder
    include Hyrax::FilterByType
    attr_reader :collection, :search_includes_models

    class_attribute :collection_membership_field
    self.collection_membership_field = 'member_of_collection_ids_ssim'

    # Defines which search_params_logic should be used when searching for Collection members
    self.default_processor_chain += [:member_of_collection]

    # @param [scope] Typically the controller object
    # @param [Symbol] :works, :collections, (anything else retrieves both)
    def initialize(scope:,
                   collection:,
                   search_includes_models: :works)
      @collection = collection
      @search_includes_models = search_includes_models
      super(scope)
    end

    # include filters into the query to only include the collection memebers
    def member_of_collection(solr_parameters)
      solr_parameters[:fq] ||= []
      solr_parameters[:fq] << "#{collection_membership_field}:#{collection.id}"
    end

    # This overrides the models in FilterByType
    def models
      case search_includes_models
      when :collections
        collection_classes
      when :works
        work_classes
      else super # super includes both works and collections
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
hyrax-2.9.6 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.9.5 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.9.4 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.9.3 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.9.2 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.9.1 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.9.0 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.8.0 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.7.2 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.7.1 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.7.0 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.6.0 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-3.0.0.pre.rc1 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-3.0.0.pre.beta3 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.5.1 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.5.0 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-3.0.0.pre.beta2 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.4.1 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-3.0.0.pre.beta1 app/search_builders/hyrax/collection_member_search_builder.rb
hyrax-2.4.0 app/search_builders/hyrax/collection_member_search_builder.rb