Module: Blacklight::Catalog

Extended by:
ActiveSupport::Concern, Deprecation
Includes:
ActionController::MimeResponds, Base, 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 Attribute Summary

Attributes included from Configurable

#blacklight_config

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

Methods included from Configurable

default_configuration, default_configuration=

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:



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

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



135
136
137
# File 'app/controllers/concerns/blacklight/catalog.rb', line 135

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

#advanced_searchObject



62
63
64
# File 'app/controllers/concerns/blacklight/catalog.rb', line 62

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)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/concerns/blacklight/catalog.rb', line 91

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.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'app/controllers/concerns/blacklight/catalog.rb', line 155

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)


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

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

#indexObject

get search results from the solr index



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/concerns/blacklight/catalog.rb', line 31

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.')

  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



111
112
113
114
115
116
# File 'app/controllers/concerns/blacklight/catalog.rb', line 111

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)


67
68
69
70
71
72
# File 'app/controllers/concerns/blacklight/catalog.rb', line 67

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



51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/concerns/blacklight/catalog.rb', line 51

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.')

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

#suggestObject



118
119
120
121
122
123
124
# File 'app/controllers/concerns/blacklight/catalog.rb', line 118

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)



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/concerns/blacklight/catalog.rb', line 75

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