Class: Hyrax::CollectionSizeService
- Inherits:
-
Object
- Object
- Hyrax::CollectionSizeService
- Includes:
- Blacklight::Configurable, Blacklight::SearchHelper
- Defined in:
- app/services/hyrax/collection_size_service.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Class Method Summary collapse
Instance Method Summary collapse
- #collection_search_builder ⇒ Object
- #collection_size ⇒ Object
-
#initialize(collection) ⇒ CollectionSizeService
constructor
A new instance of CollectionSizeService.
- #max_collection_size ⇒ Object
- #size_field ⇒ Object
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
#collection ⇒ Object (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_builder ⇒ Object
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_size ⇒ Object
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_size ⇒ Object
36 37 38 |
# File 'app/services/hyrax/collection_size_service.rb', line 36 def max_collection_size 1000 end |
#size_field ⇒ Object
32 33 34 |
# File 'app/services/hyrax/collection_size_service.rb', line 32 def size_field Solrizer.solr_name(:file_size, :symbol) end |