Sha256: 0f2b88c1c831976e0cd14fc7250b2e4af6e097ee1767f864a005527ffc59d16e

Contents?: true

Size: 1.04 KB

Versions: 29

Compression:

Stored size: 1.04 KB

Contents

# returns a list of solr documents for collections the item is a part of
module Hyrax
  class CollectionSizeService
    include Blacklight::Configurable
    include Blacklight::SearchHelper

    attr_reader :collection

    copy_blacklight_config_from(CatalogController)

    def self.run(collection)
      new(collection).collection_size
    end

    def initialize(collection)
      @collection = collection
    end

    def collection_size
      query = collection_search_builder.with('id' => collection.id).rows(max_collection_size).merge(fl: [size_field])
      resp = repository.search(query)
      field_name = size_field
      resp.documents.reduce(0) do |total, doc|
        total + (doc[field_name].blank? ? 0 : doc[field_name][0].to_f)
      end
    end

    def collection_search_builder
      @collection_search_builder ||= MemberWithFilesSearchBuilder.new([:include_contained_files, :add_paging_to_solr], self)
    end

    def size_field
      Solrizer.solr_name(:file_size, :symbol)
    end

    def max_collection_size
      1000
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
hyrax-1.1.1 app/services/hyrax/collection_size_service.rb
hyrax-2.0.3 app/services/hyrax/collection_size_service.rb
hyrax-2.1.0 app/services/hyrax/collection_size_service.rb
hyrax-2.1.0.rc4 app/services/hyrax/collection_size_service.rb
hyrax-2.1.0.rc3 app/services/hyrax/collection_size_service.rb
hyrax-2.1.0.rc2 app/services/hyrax/collection_size_service.rb
hyrax-2.1.0.rc1 app/services/hyrax/collection_size_service.rb
hyrax-1.1.0 app/services/hyrax/collection_size_service.rb
hyrax-2.1.0.beta2 app/services/hyrax/collection_size_service.rb
hyrax-2.0.2 app/services/hyrax/collection_size_service.rb
hyrax-2.1.0.beta1 app/services/hyrax/collection_size_service.rb
hyrax-2.0.1 app/services/hyrax/collection_size_service.rb
hyrax-2.0.0 app/services/hyrax/collection_size_service.rb
hyrax-2.0.0.rc3 app/services/hyrax/collection_size_service.rb
hyrax-2.0.0.rc2 app/services/hyrax/collection_size_service.rb
hyrax-2.0.0.rc1 app/services/hyrax/collection_size_service.rb
hyrax-1.0.5 app/services/hyrax/collection_size_service.rb
hyrax-2.0.0.beta5 app/services/hyrax/collection_size_service.rb
hyrax-2.0.0.beta4 app/services/hyrax/collection_size_service.rb
hyrax-2.0.0.beta3 app/services/hyrax/collection_size_service.rb