Sha256: f414ccf9c711dda91c2f230c36cc78911fe3df373a70ca1f53cd4c5a4950583f

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

# returns a list of solr documents for collections the item is a part of
module Sufia
  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.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 ||= CollectionSearchBuilder.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

8 entries across 8 versions & 1 rubygems

Version Path
sufia-7.1.0 app/services/sufia/collection_size_service.rb
sufia-7.0.0 app/services/sufia/collection_size_service.rb
sufia-7.0.0.rc2 app/services/sufia/collection_size_service.rb
sufia-7.0.0.rc1 app/services/sufia/collection_size_service.rb
sufia-7.0.0.beta4 app/services/sufia/collection_size_service.rb
sufia-7.0.0.beta3 app/services/sufia/collection_size_service.rb
sufia-7.0.0.beta2 app/services/sufia/collection_size_service.rb
sufia-7.0.0.beta1 app/services/sufia/collection_size_service.rb