Class: Blacklight::Solr::Response
- Inherits:
-
ActiveSupport::HashWithIndifferentAccess
- Object
- ActiveSupport::HashWithIndifferentAccess
- Blacklight::Solr::Response
- Includes:
- Facets, MoreLikeThis, PaginationMethods, Params, Response, Spelling
- Defined in:
- lib/blacklight/solr/response.rb
Defined Under Namespace
Modules: Facets, MoreLikeThis, PaginationMethods, Params, Response, Spelling Classes: Group, GroupResponse
Constant Summary
Constants included from Params
Params::QUERY_PARAMETER_TO_JSON_PARAMETER_MAPPING
Instance Attribute Summary collapse
-
#blacklight_config ⇒ Object
Returns the value of attribute blacklight_config.
-
#options ⇒ Object
Returns the value of attribute options.
-
#request_params ⇒ Object
readonly
Returns the value of attribute request_params.
Instance Method Summary collapse
- #documents ⇒ Object (also: #docs)
- #export_formats ⇒ Object
- #group(key) ⇒ Object
- #grouped ⇒ Object
- #grouped? ⇒ Boolean
- #header ⇒ Object
-
#initialize(data, request_params, options = {}) ⇒ Response
constructor
A new instance of Response.
Methods included from Params
#facet_field_aggregation_options, #params, #rows, #sort, #start
Methods included from MoreLikeThis
Methods included from Response
#empty?, #response, #start, #total
Methods included from Facets
#aggregations, #facet_counts, #facet_fields, #facet_pivot, #facet_queries, #merge_facet
Methods included from Spelling
Methods included from PaginationMethods
#entry_name, #limit_value, #offset_value, #size, #total_count
Constructor Details
#initialize(data, request_params, options = {}) ⇒ Response
Returns a new instance of Response.
16 17 18 19 20 21 |
# File 'lib/blacklight/solr/response.rb', line 16 def initialize(data, request_params, = {}) super(force_to_utf8(ActiveSupport::HashWithIndifferentAccess.new(data))) @request_params = ActiveSupport::HashWithIndifferentAccess.new(request_params) self.blacklight_config = [:blacklight_config] self. = end |
Instance Attribute Details
#blacklight_config ⇒ Object
Returns the value of attribute blacklight_config.
12 13 14 |
# File 'lib/blacklight/solr/response.rb', line 12 def blacklight_config @blacklight_config end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/blacklight/solr/response.rb', line 12 def @options end |
#request_params ⇒ Object (readonly)
Returns the value of attribute request_params.
11 12 13 |
# File 'lib/blacklight/solr/response.rb', line 11 def request_params @request_params end |
Instance Method Details
#documents ⇒ Object Also known as: docs
27 28 29 |
# File 'lib/blacklight/solr/response.rb', line 27 def documents @documents ||= (response['docs'] || []).collect { |doc| document_factory.build(doc, self, ) } end |
#export_formats ⇒ Object
57 58 59 |
# File 'lib/blacklight/solr/response.rb', line 57 def export_formats documents.map { |x| x.export_formats.keys }.flatten.uniq end |
#group(key) ⇒ Object
49 50 51 |
# File 'lib/blacklight/solr/response.rb', line 49 def group key grouped.find { |x| x.key == key } end |
#grouped ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/blacklight/solr/response.rb', line 32 def grouped @groups ||= self["grouped"].map do |field, group| # grouped responses can either be grouped by: # - field, where this key is the field name, and there will be a list # of documents grouped by field value, or: # - function, where the key is the function, and the documents will be # further grouped by function value, or: # - query, where the key is the query, and the matching documents will be # in the doclist on THIS object if group["groups"] # field or function GroupResponse.new field, group, self else # query Group.new field, group, self end end end |
#grouped? ⇒ Boolean
53 54 55 |
# File 'lib/blacklight/solr/response.rb', line 53 def grouped? key? "grouped" end |
#header ⇒ Object
23 24 25 |
# File 'lib/blacklight/solr/response.rb', line 23 def header self['responseHeader'] || {} end |