Sha256: da8986f941f071795ecde1672ef721d58bf3eea24e9ed25b072f4a432237292e

Contents?: true

Size: 1.24 KB

Versions: 18

Compression:

Stored size: 1.24 KB

Contents

module CurationConcerns
  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] << '(' + (work_clauses + collection_clauses).join(' OR ') + ')'
    end

    private

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

      def work_clauses
        return [] if blacklight_params.key?(:f) && Array(blacklight_params[:f][:generic_type_sim]).include?('Collection')
        work_types.map do |klass|
          ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: klass.to_class_uri)
        end
      end

      def collection_clauses
        return [] if blacklight_params.key?(:f) && Array(blacklight_params[:f][:generic_type_sim]).include?('Work')
        [ActiveFedora::SolrQueryBuilder.construct_query_for_rel(has_model: ::Collection.to_class_uri)]
      end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
curation_concerns-0.14.0.pre4 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.14.0.pre3 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.14.0.pre2 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.14.0.pre1 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.13.1 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.13.0 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre9 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre8 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre7 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre6 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre5 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre4 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre3 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre2 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.12.0.pre1 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.11.0 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.11.0.rc1 app/search_builders/curation_concerns/filter_by_type.rb