filter search results by facet

45 views
Skip to first unread message

shollin...@gmail.com

unread,
Nov 26, 2014, 6:19:34 AM11/26/14
to ruby-s...@googlegroups.com
Hi,

I currently have the searching working and the facets are being displayed.

If I search for something the brands facet will show up on the left telling me what brands there are and how many it has found.

However when I click on the facet on the left for a particular brand it searches everything by that brand not by the brand on the search results, how do I do this?

This is my facet code

<% @search.facet(:brand).rows.each do |row| %>
  <ul>
    <li>
      <% if params[:brand].blank? %>
        <%= link_to row.value, brand: row.value %>(<%= row.count %>)
      <% else %>
        <strong><%= row.value %></strong> (<%= link_to "remove", brand: nil %>)
      <% end %>
    </li>
  </ul>
<% end %>

  def load_searching
    @search = Product.search do
      fulltext params[:search]
      facet(:brand)
      with(:brand, params[:brand]) if params[:brand].present?
    end
  end

Product model

searchable do
    text :productcode, :productname
    string :brand
  end

what am I missing?

Alexandru-Emil Lupu

unread,
Feb 5, 2015, 12:50:14 PM2/5/15
to ruby-s...@googlegroups.com, shollin...@gmail.com
Hello! 

Try : 

 with(:brand, params[:brand]) if params[:brand].present?

Thanks 
A
Reply all
Reply to author
Forward
0 new messages