Module: Blacklight::Catalog

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

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 SearchContext

#current_search_session, #page_links, #searches_from_history

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:



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

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

  @documents
end

#action_success_redirect_pathObject



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

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

#advanced_searchObject



53
54
55
# File 'app/controllers/concerns/blacklight/catalog.rb', line 53

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)


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

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

#has_search_parameters?Boolean

Check if any search parameters have been set

Returns:

  • (Boolean)


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

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

#indexObject

get search results from the solr index



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/concerns/blacklight/catalog.rb', line 25

def index
  @response = search_service.search_results

  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



102
103
104
105
106
107
# File 'app/controllers/concerns/blacklight/catalog.rb', line 102

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)


58
59
60
61
62
63
# File 'app/controllers/concerns/blacklight/catalog.rb', line 58

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

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

#search_facet_path(options = {}) ⇒ Object



135
136
137
138
139
140
141
142
# File 'app/controllers/concerns/blacklight/catalog.rb', line 135

def search_facet_path(options = {})
  opts = search_state
         .to_h
         .merge(action: "facet", only_path: true)
         .merge(options)
         .except(:page)
  url_for opts
end

#showObject

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



43
44
45
46
47
48
49
50
51
# File 'app/controllers/concerns/blacklight/catalog.rb', line 43

def show
  @document = search_service.fetch(params[:id])

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

#suggestObject

Returns the dropdown list for autocomplete



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

def suggest
  @suggestions = suggestions_service.suggestions
  render 'suggest', layout: false
end

#trackObject

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



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/concerns/blacklight/catalog.rb', line 66

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