Sha256: dfd0f560286b2e4ecaa6d6561efd891d48a33ff294f9419b1b83129b6ed137f1

Contents?: true

Size: 1.53 KB

Versions: 6

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true
module Hyrax
  module FilterByType
    extend ActiveSupport::Concern

    included do
      self.default_processor_chain += [:filter_models]
    end

    # Add queries that excludes everything except for works and collections
    def filter_models(solr_parameters)
      solr_parameters[:fq] ||= []
      solr_parameters[:fq] << "{!terms f=has_model_ssim}#{models_to_solr_clause}"
    end

    private

    def only_collections?
      generic_type_field.include?('Collection')
    end

    def only_works?
      generic_type_field.include?('Work')
    end

    # Override this method if you want to filter for a different set of models.
    # @return [Array<Class>] a list of classes to include
    def models
      work_classes + collection_classes
    end

    def models_to_solr_clause
      models.map do |model|
        model.respond_to?(:to_rdf_representation) ? model.to_rdf_representation : model.name
      end.join(',')
    end

    def generic_type_field
      Array.wrap(blacklight_params.fetch(:f, {}).fetch(:generic_type_sim, []))
    end

    # Override this method if you want to limit some of the registered
    # types from appearing in search results
    # @return [Array<Class>] the list of work types to include in searches
    def work_types
      Hyrax.config.curation_concerns
    end

    def work_classes
      return [] if only_collections?
      work_types
    end

    def collection_classes
      return [] if only_works?
      # to_class_uri is deprecated in AF 11
      [::Collection]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
hyrax-3.1.0 app/search_builders/hyrax/filter_by_type.rb
hyrax-3.0.2 app/search_builders/hyrax/filter_by_type.rb
hyrax-3.0.1 app/search_builders/hyrax/filter_by_type.rb
hyrax-3.0.0 app/search_builders/hyrax/filter_by_type.rb
hyrax-3.0.0.pre.rc4 app/search_builders/hyrax/filter_by_type.rb
hyrax-3.0.0.pre.rc3 app/search_builders/hyrax/filter_by_type.rb