Sha256: 4f953a4b2a5486cc8bfc13f0abb478e67c788fbff4335ef7d4ab20c422850db2

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 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

      def work_clauses
        return [] if blacklight_params.key?(:f) && Array(blacklight_params[:f][:generic_type_sim]).include?('Collection')
        CurationConcerns.config.registered_curation_concern_types.map(&:constantize).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

5 entries across 5 versions & 1 rubygems

Version Path
curation_concerns-0.10.0 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.9.0 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.8.0 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.7.0 app/search_builders/curation_concerns/filter_by_type.rb
curation_concerns-0.6.0 app/search_builders/curation_concerns/filter_by_type.rb