Class: Blacklight::Solr::Response
- Inherits:
-
ActiveSupport::HashWithIndifferentAccess
- Object
- ActiveSupport::HashWithIndifferentAccess
- Blacklight::Solr::Response
- Extended by:
- ActiveSupport::Autoload
- 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.
28 29 30 31 32 33 |
# File 'lib/blacklight/solr/response.rb', line 28 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.
24 25 26 |
# File 'lib/blacklight/solr/response.rb', line 24 def blacklight_config @blacklight_config end |
#options ⇒ Object
Returns the value of attribute options.
24 25 26 |
# File 'lib/blacklight/solr/response.rb', line 24 def @options end |
#request_params ⇒ Object (readonly)
Returns the value of attribute request_params.
23 24 25 |
# File 'lib/blacklight/solr/response.rb', line 23 def request_params @request_params end |
Instance Method Details
#documents ⇒ Object Also known as: docs
39 40 41 |
# File 'lib/blacklight/solr/response.rb', line 39 def documents @documents ||= (response['docs'] || []).collect { |doc| document_factory.build(doc, self, ) } end |
#export_formats ⇒ Object
69 70 71 |
# File 'lib/blacklight/solr/response.rb', line 69 def export_formats documents.map { |x| x.export_formats.keys }.flatten.uniq end |
#group(key) ⇒ Object
61 62 63 |
# File 'lib/blacklight/solr/response.rb', line 61 def group key grouped.find { |x| x.key == key } end |
#grouped ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/blacklight/solr/response.rb', line 44 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
65 66 67 |
# File 'lib/blacklight/solr/response.rb', line 65 def grouped? key? "grouped" end |
#header ⇒ Object
35 36 37 |
# File 'lib/blacklight/solr/response.rb', line 35 def header self['responseHeader'] || {} end |