<%= link_to 'Search New York Times articles', root_path %>
<%= form_tag search_path, method: 'get', role: 'search' do %>
<%= text_field_tag :q, params[:q], class: 'form-control', placeholder: 'Search...' %>
<% end %>
<% if @articles.size < 1 && @articles.response.suggestions.present? %>
No documents have been found.
<% if @articles.response.suggestions.terms.present? %>
Maybe you mean
<%= @articles.response.suggestions.terms.map do |term|
link_to term, search_path(params.except(:controller, :action).merge q: term)
end.to_sentence(last_word_connector: ' or ').html_safe %>?
<% end %>
<% end %>
<% unless @articles.size < 1 %>
<%= link_to 'All Sections →'.html_safe, search_path(params.except(:controller, :action).merge(c: nil))%>
<% @articles.response.response['aggregations']['categories']['categories']['buckets'].each do |c| %>
<%=
link_to search_path(params.except(:controller, :action).merge(c: c['key'])),
class: "list-group-item#{' active' if params[:c] == c['key']}" do
c['key'].titleize.html_safe + content_tag(:small, c['doc_count'], class: 'badge').html_safe
end
%>
<% end %>
<%= link_to 'All Authors →'.html_safe, search_path(params.except(:controller, :action).merge(a: nil))%>
<% @articles.response.response['aggregations']['authors']['authors']['buckets'].each do |a| %>
<%=
link_to search_path(params.except(:controller, :action).merge(a: a['key'])),
class: "list-group-item#{' active' if params[:a] == a['key']}" do
a['key'].titleize.html_safe + content_tag(:small, a['doc_count'], class: 'badge').html_safe
end
%>
<% end %>
<%= link_to 'Any Date →'.html_safe, search_path(params.except(:controller, :action).merge(w: nil))%>
<% @articles.response.response['aggregations']['published']['published']['buckets'].each do |w| %>
<%=
__start = Time.at(w['key']/1000)
__end = __start.end_of_week
__date = __start.to_date.to_s(:iso)
link_to search_path(params.except(:controller, :action).merge(w: __date)),
class: "list-group-item#{' active' if params[:w] == __date}" do
"#{__start.to_date.to_s(:short)} — #{__end.to_date.to_s(:short)}".html_safe + \
content_tag(:small, w['doc_count'], class: 'badge').html_safe
end
%>
<% end %>
<% end %>