Class: Dbla::Response
- Inherits:
-
AbstractResponse
- Object
- HashWithIndifferentAccess
- AbstractResponse
- Dbla::Response
- Defined in:
- lib/dbla/response.rb
Defined Under Namespace
Modules: Facets Classes: Words
Instance Attribute Summary
Attributes inherited from AbstractResponse
#blacklight_config, #document_model, #documents, #limit, #request_params, #start, #total
Instance Method Summary collapse
- #aggregations ⇒ Object
- #facet_by_field_name(facet_field) ⇒ Object
-
#initialize(data, request_params, options = {}) ⇒ Response
constructor
A new instance of Response.
- #spelling ⇒ Object
Methods inherited from AbstractResponse
#export_formats, #grouped?, #header, #more_like, #params, #sort
Constructor Details
#initialize(data, request_params, options = {}) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/dbla/response.rb', line 6 def initialize(data, request_params, = {}) super(force_to_utf8(data)) @request_params = request_params self.document_model = [:solr_document_model] || [:document_model] || Item self.blacklight_config = [:blacklight_config] if data @total = data.fetch('count',0) @documents = (data['docs'] || []).map {|d| document_model.new(d,self)} @start = data.fetch('start',0) @limit = data.fetch('limit',10) @aggregations = (data['facets'] || {}) else @aggregations = {} @total = 0 @start = 0 @limit = 10 @documents = [] end end |
Instance Method Details
#aggregations ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dbla/response.rb', line 25 def aggregations # "facets":{"sourceResource.format":{"_type":"terms","missing":77,"total":250,"other":16,"terms":[{"term":"Photographs","count":44}, Hash[@aggregations.map do |k,v| next unless v['terms'] items = v['terms'].map {|term| Facets::FacetItem.new(value: term['term'], hits: term['count'])} [k, Facets::FacetField.new(k,items)] end] end |
#facet_by_field_name(facet_field) ⇒ Object
33 34 35 |
# File 'lib/dbla/response.rb', line 33 def facet_by_field_name(facet_field) aggregations[facet_field.to_s] end |