Class: Hyrax::CollectionSizeService

Inherits:
Object
  • Object
show all
Includes:
Blacklight::Configurable, Blacklight::SearchHelper
Defined in:
app/services/hyrax/collection_size_service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection) ⇒ CollectionSizeService

Returns a new instance of CollectionSizeService.



15
16
17
# File 'app/services/hyrax/collection_size_service.rb', line 15

def initialize(collection)
  @collection = collection
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



7
8
9
# File 'app/services/hyrax/collection_size_service.rb', line 7

def collection
  @collection
end

Class Method Details

.run(collection) ⇒ Object



11
12
13
# File 'app/services/hyrax/collection_size_service.rb', line 11

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

Instance Method Details

#collection_search_builderObject



28
29
30
# File 'app/services/hyrax/collection_size_service.rb', line 28

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

#collection_sizeObject



19
20
21
22
23
24
25
26
# File 'app/services/hyrax/collection_size_service.rb', line 19

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

#max_collection_sizeObject



36
37
38
# File 'app/services/hyrax/collection_size_service.rb', line 36

def max_collection_size
  1000
end

#size_fieldObject



32
33
34
# File 'app/services/hyrax/collection_size_service.rb', line 32

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