Module: Blacklight::SearchContext

Extended by:
ActiveSupport::Concern
Included in:
Catalog, SearchHistory
Defined in:
app/controllers/concerns/blacklight/search_context.rb,
app/components/blacklight/search_context/server_applied_params_component.rb,
app/components/blacklight/search_context/server_item_pagination_component.rb

Defined Under Namespace

Classes: ServerAppliedParamsComponent, ServerItemPaginationComponent

Instance Method Summary collapse

Instance Method Details

#current_search_sessionObject

The current search session



22
23
24
# File 'app/controllers/concerns/blacklight/search_context.rb', line 22

def current_search_session
  @current_search_session ||= find_search_session
end

GET previous and next document json for the document specified by the counter param in current search



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

def page_links
  counter_param = params.delete(:counter)
  @page_link_data = {}
  if counter_param
    index = counter_param.to_i - 1
    response, documents = search_service.previous_and_next_documents_for_search index, search_state.reset_search
    if documents.detect(&:present?)
      @page_link_data[:prev] = page_links_document_path(documents.first, index)
      @page_link_data[:next] = page_links_document_path(documents.last, index + 2)
    end
    if response&.total && response.total.positive?
      @page_link_data[:counterRaw] = counter_param
      @page_link_data[:counterDelimited] = helpers.number_with_delimiter(counter_param.to_i)
      @page_link_data[:totalRaw] = response.total
      @page_link_data[:totalDelimited] = helpers.number_with_delimiter(response.total)
    end
  end
  render json: @page_link_data
end

#searches_from_historyObject

Returns a list of Searches from the ids in the user’s history.



27
28
29
# File 'app/controllers/concerns/blacklight/search_context.rb', line 27

def searches_from_history
  session[:history].blank? ? ::Search.none : ::Search.where(id: session[:history]).order("updated_at desc")
end