<div class="box">
  <%= form_with url: '/search', method: :get do |f| %>
    <div class="boxline">
        <%= f.text_field "q", { :value => @search.q, :size => 40 }.
        merge(@search.q.present? ? {} : { :autofocus => "autofocus" }) %>
      <input type="submit" value="Search">
    </div>

    <div class="boxline">
      <label class="required">Search:</label>

      <%= f.radio_button "what", "stories", :checked => @search.what == "stories" %>
        <label for="what_stories" class="normal">Stories</label>

      &nbsp;

      <%= f.radio_button "what", "comments", :checked => @search.what == "comments" %>
        <label for="what_comments" class="normal">Comments</label>

      <br>

      <label class="required">Order By:</label>

      <%= f.radio_button "order", "newest", :checked => @search.order == "newest" %>
        <label for="order_newest" class="normal">Newest</label>

      &nbsp;

      <%= f.radio_button "order", "relevance", :checked => @search.order == "relevance" %>
        <label for="order_relevance" class="normal">Relevance</label>

      &nbsp;

      <%= f.radio_button "order", "points", :checked => @search.order == "points" %>
        <label for="order_points" class="normal">Points</label>
    </div>
  <% end %>
</div>

<% if @search.total_results > -1 %>
  <div class="box">
    <h2>
      <%= @search.total_results %> result<%= @search.total_results == 1 ? "" :
        "s" %> for "<%= @search.q %>"
    </h2>
  </div>

  <ol class="search_results">
    <% @search.results.each do |res| %>
      <% if res.class == Story %>
        <%= render :partial => "stories/listdetail",
          :locals => { :story => res } %>
      <% elsif res.class == Comment %>
        <li><%= render "comments/comment", :comment => res,
          :show_story => true, :hide_voters => true %></li>
      <% end %>
    <% end %>
  </ol>

  <% if @search.total_results > @search.per_page %>
    <div class="page_link_buttons">
      Page:

      <% page_numbers_for_pagination(@search.page_count, @search.page).each do |p| %>
        <% if p.is_a?(Integer) %>
          <a href="/search?<%= raw(@search.to_url_params) %>&amp;page=<%= p
            %>" class="<%= @search.page == p ? "cur" : "" %>"><%= p
            %></a>
        <% else %>
          <span>...</span>
        <% end %>
      <% end %>
    </div>
  <% elsif @search.total_results == 1 %>
    <div class="page_link_buttons">
      <p>Hapax legomenon</p>
    </div>
  <% end %>
<% else %>
  <div class="help">
    Search hints:
    <ul>
      <li>Use <a href="https://mariadb.com/kb/en/full-text-index-overview/#in-boolean-mode">search operators</a> like <code>+</code> to require terms, <code>-</code> to ignore terms, and <code>"quotes for phrases"</code>.</li>
      <li>Search by domain with <code>domain:example.com</code> (implicit <code>+</code>)</li>
      <li>Search by <%= link_to 'tag', tags_path %> with <code>tag:meta</code> (implicit <code>+</code>)</li>
    </ul>
  </div>
<% end %>
