Module: Blacklight::Catalog

Extended by:
ActiveSupport::Concern, Deprecation
Includes:
ActionController::MimeResponds, Facet, Searchable
Included in:
CatalogController
Defined in:
app/controllers/concerns/blacklight/catalog.rb

Constant Summary collapse

DEFAULT_FACET_LIMIT =

TODO: deprecate this constant with #facet_limit_for

10

Instance Method Summary collapse

Methods included from Searchable

#search_service, #search_service_context, #suggestions_service

Methods included from Facet

#facet_by_field_name, #facet_paginator, #facets_from_request

Instance Method Details

#action_documentsArray

Returns first value is a Blacklight::Solr::Response and the second is a list of documents.

Returns:

  • (Array)

    first value is a Blacklight::Solr::Response and the second is a list of documents

Raises:



139
140
141
142
143
144
# File 'app/controllers/concerns/blacklight/catalog.rb', line 139

def action_documents
  deprecated_response, @documents = search_service.fetch(Array(params[:id]))
  raise Blacklight::Exceptions::RecordNotFound if @documents.blank?

  [deprecated_response, @documents]
end

#action_success_redirect_pathObject



146
147
148
# File 'app/controllers/concerns/blacklight/catalog.rb', line 146

def action_success_redirect_path
  search_state.url_for_document(blacklight_config.document_model.new(id: params[:id]))
end

#advanced_searchObject



73
74
75
# File 'app/controllers/concerns/blacklight/catalog.rb', line 73

def advanced_search
  (@response, _deprecated_document_list) = blacklight_advanced_search_form_search_service.search_results
end

#facetObject

displays values and pagination links for a single facet field

Raises:

  • (ActionController::RoutingError)


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'app/controllers/concerns/blacklight/catalog.rb', line 102

def facet
  @facet = blacklight_config.facet_fields[params[:id]]
  raise ActionController::RoutingError, 'Not Found' unless @facet

  @response = search_service.facet_field_response(@facet.key)
  @display_facet = @response.aggregations[@facet.field]

  @presenter = (@facet.presenter || Blacklight::FacetFieldPresenter).new(@facet, @display_facet, view_context)
  @pagination = @presenter.paginator
  respond_to do |format|
    format.html do
      # Draw the partial for the "more" facet modal window:
      return render layout: false if request.xhr?
      # Otherwise draw the facet selector for users who have javascript disabled.
    end
    format.json
  end
end

#facet_limit_for(facet_field) ⇒ Object

Look up facet limit for given facet_field. Will look at config, and if config is ‘true’ will look up from Solr @response if available. If no limit is available, returns nil. Used from #add_facetting_to_solr to supply f.fieldname.facet.limit values in solr request (no @response available), and used in display (with @response available) to create a facet paginator with the right limit.



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'app/controllers/concerns/blacklight/catalog.rb', line 166

def facet_limit_for(facet_field)
  facet = blacklight_config.facet_fields[facet_field]
  return if facet.blank?

  if facet.limit && @response && @response.aggregations[facet.field]
    limit = @response.aggregations[facet.field].limit

    if limit.nil? # we didn't get or a set a limit, so infer one.
      facet.limit if facet.limit != true
    elsif limit == -1 # limit -1 is solr-speak for unlimited
      nil
    else
      limit.to_i - 1 # we added 1 to find out if we needed to paginate
    end
  elsif facet.limit
    facet.limit == true ? DEFAULT_FACET_LIMIT : facet.limit
  end
end

#has_search_parameters?Boolean

Check if any search parameters have been set

Returns:

  • (Boolean)


153
154
155
# File 'app/controllers/concerns/blacklight/catalog.rb', line 153

def has_search_parameters?
  params[:search_field].present? || search_state.has_constraints?
end

#indexObject

get search results from the solr index



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/concerns/blacklight/catalog.rb', line 34

def index
  (@response, deprecated_document_list) = search_service.search_results

  @document_list = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(
    deprecated_document_list,
    'The @document_list instance variable is deprecated; use @response.documents instead.',
    ActiveSupport::Deprecation.new("8.0", "blacklight")
  )

  respond_to do |format|
    format.html { store_preferred_view }
    format.rss  { render layout: false }
    format.atom { render layout: false }
    format.json do
      @presenter = Blacklight::JsonPresenter.new(@response,
                                                 blacklight_config)
    end
    additional_response_formats(format)
    document_export_formats(format)
  end
end

#opensearchObject

method to serve up XML OpenSearch description and JSON autocomplete response



122
123
124
125
126
127
# File 'app/controllers/concerns/blacklight/catalog.rb', line 122

def opensearch
  respond_to do |format|
    format.xml { render layout: false }
    format.json { render json: search_service.opensearch_response }
  end
end

#rawObject

get a single document from the index

Raises:

  • (ActionController::RoutingError)


78
79
80
81
82
83
# File 'app/controllers/concerns/blacklight/catalog.rb', line 78

def raw
  raise(ActionController::RoutingError, 'Not Found') unless blacklight_config.raw_endpoint.enabled

  _, @document = search_service.fetch(params[:id])
  render json: @document
end

#showObject

get a single document from the index to add responses for formats other than html or json see Blacklight::Document::Export



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/concerns/blacklight/catalog.rb', line 58

def show
  deprecated_response, @document = search_service.fetch(params[:id])
  @response = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(
    deprecated_response,
    'The @response instance variable is deprecated; use @document.response instead.',
    ActiveSupport::Deprecation.new("8.0", "blacklight")
  )

  respond_to do |format|
    format.html { @search_context = setup_next_and_previous_documents }
    format.json
    additional_export_formats(@document, format)
  end
end

#suggestObject



129
130
131
132
133
134
135
# File 'app/controllers/concerns/blacklight/catalog.rb', line 129

def suggest
  respond_to do |format|
    format.json do
      render json: suggestions_service.suggestions
    end
  end
end

#trackObject

updates the search counter (allows the show view to paginate)



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'app/controllers/concerns/blacklight/catalog.rb', line 86

def track
  search_session['counter'] = params[:counter]
  search_session['id'] = params[:search_id]
  search_session['per_page'] = params[:per_page]
  search_session['document_id'] = params[:document_id]

  if params[:redirect] && (params[:redirect].starts_with?('/') || params[:redirect] =~ URI::DEFAULT_PARSER.make_regexp)
    uri = URI.parse(params[:redirect])
    path = uri.query ? "#{uri.path}?#{uri.query}" : uri.path
    redirect_to path, status: :see_other
  else
    redirect_to({ action: :show, id: params[:id] }, status: :see_other)
  end
end