Sha256: a90b5189a1f74f8877ef1df5481b799a50445fcd1c68e490691496a108be874a

Contents?: true

Size: 1.61 KB

Versions: 48

Compression:

Stored size: 1.61 KB

Contents

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
        # to_class_uri is deprecated in AF 11
        [ActiveFedora::Base.respond_to?(:to_rdf_representation) ? models.map(&:to_rdf_representation) : models.map(&:to_class_uri)].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

48 entries across 48 versions & 1 rubygems

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