Caio santos

Joined

10 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Facets with Searchkick

Its not that hard guys

#------- controller ------
    search = params[:search].presence || "*"
    conditions = {}
    conditions[:state] = params[:state] if params[:state].present?
    conditions[:city] = params[:city] if params[:city].present?

    @stores = Store.search search, where: conditions, aggs: [:state,:city]
<%# ---- stores index erb ----- %>
<% if @stores.aggs["state"].present? %>
        <span>State</span>
        <ul  class="menu">
        <% @stores.aggs["state"]["buckets"].each do |filter| %>
          <li><%= link_to "#{filter["key"]} (#{filter["doc_count"]})", "/stores?state=#{filter["key"]}" %></li>
        <% end %>
        </ul>
    <% end %>