Sha256: 06da3f963c9c8c2dc47e8550012bd250c8f7e24cc15257b1376d98e368fa71d8

Contents?: true

Size: 1.1 KB

Versions: 21

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Blacklight
  class JsonPresenter
    # @param [Solr::Response] response raw solr response.
    # @param [Configuration] blacklight_config the configuration
    def initialize(response, blacklight_config)
      @response = response
      @blacklight_config = blacklight_config
    end

    attr_reader :blacklight_config

    delegate :facet_field_names, :facet_configuration_for_field, to: :blacklight_config

    def documents
      @response.documents
    end

    # @return [Array<Blacklight::Solr::Response::Facets::FacetField>]
    def search_facets
      facet_field_names
        .map { |field| @response.aggregations[facet_configuration_for_field(field).field] }
        .compact
        .select { |display_facet| display_facet.items.present? }
    end

    # extract the pagination info from the response object
    def pagination_info
      h = {}

      [:current_page, :next_page, :prev_page, :total_pages,
       :limit_value, :offset_value, :total_count,
       :first_page?, :last_page?].each do |k|
        h[k] = @response.send(k)
      end

      h
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
blacklight-8.6.1 app/presenters/blacklight/json_presenter.rb
blacklight-8.6.0 app/presenters/blacklight/json_presenter.rb
blacklight-8.5.1 app/presenters/blacklight/json_presenter.rb
blacklight-8.5.0 app/presenters/blacklight/json_presenter.rb
blacklight-8.4.0 app/presenters/blacklight/json_presenter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/blacklight-8.3.0/app/presenters/blacklight/json_presenter.rb
blacklight-8.3.0 app/presenters/blacklight/json_presenter.rb
blacklight-8.2.2 app/presenters/blacklight/json_presenter.rb
blacklight-8.2.1 app/presenters/blacklight/json_presenter.rb
blacklight-8.2.0 app/presenters/blacklight/json_presenter.rb
blacklight-8.1.0 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.1 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0.beta8 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0.beta7 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0.beta6 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0.beta5 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0.beta4 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0.beta3 app/presenters/blacklight/json_presenter.rb
blacklight-8.0.0.beta2 app/presenters/blacklight/json_presenter.rb