Facets with Searchkick
Great job on the Searchkick tutorial! However, I'm really interested in faceted search for an application I'm building, and the documentation on the internet is not really good enough. Any ideas? Thanks!
Looks like they recently renamed these to "Aggregations". The SearchKick readme has some code there, but you'll have to adapt it for the UI. You'll want to render out the aggregation names as links and then pass those into the URL as params so you can pass them into the search query. I'll do an episode on this sometime soon!
Yes - that's true! The documentation isn't detailed though. Looking forward to the episode! Cheers :)
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 %>
Hi Chris, Tried this. It worked! But now, it works in an individual capacity. If I have three sets of aggs, how do I filter across all three results? I can do this through the url, but not in the view. Thanks.