Ah, I thought it was an integer issue - good to know you figured it out. At the moment, there's no easy way to chain filters on facets. If you have any suggestions on how this could perhaps work (from a high-level syntax perspective - although patches are welcome too!) I'd love to hear them.
Cheers -- Pat On 14/07/2010, at 1:46 PM, Tainted Moo wrote: > Hello again, > > I've continued exploring and have made some progress with your > starting point. Given the following example from my previous > message... > > if params[:category_named] > @listings = @facets.for(params[:category_named].to_sym => > params[:category_named]) > > It seems that it is necessary to convert the latter :cat_named symbol > to to an integer or string (depending on if the faceted item is an > attribute or field) before it'll work. After adding that small > change, the code will return products as expected. I'm now using > something along the lines of this... > > @options = params[:category_named]||[:retailer_named] # cut additional > facets > @facets = Listing.facets(params[:search]) > if @options # checks to see if params is populated with any of the > above facets > @listings = @facets.for(:category_named.to_sym => > params[:category_named].to_i) if @options = params[:category_named] > @listings = @facets.for(:retailer_named.to_sym => > params[:retailer_named].to_s) if @options = params[:retailer_named] > # ...cut additional @listings assignments to save space > else > @listings = Listing.search params[:search], :page => params[:page] > end > > I'm sure this is very basic for most folks here, but it might help a > newbie like myself in the future so I thought it best to share. :-) > > > Anyway, my next goal is to allow chaining from one filter to another. > By that I mean after the user drills down by clicking on a facet link, > he should have the ability to apply another filter on top of the > current product set to drill even further if desired. For example, > filter listings by Bob Shoes, then filter listings by Bob Shoes which > also have a red color attribute. My plan of action is to have a series > of conditional checks to see if @options includes each possible > combination of the facets, although it does sounds a bit more > repetitive than I'd prefer---does anyone have any hints for a better > way to tackle chaining? > > TM > > > On Jul 13, 1:23 pm, Tainted Moo <[email protected]> wrote: >> Hi Pat, >> >> Thanks for the response! No problem on the response time. You clearly >> have put a lot of time and effort into TS and the community. To expect >> an immediate response would've been rather selfish of me. >> >> After rummaging through other messages in this group and on Stack >> Overflow, I managed to get things kind of working using facets.for >> without any arguments, but I didn't really understand how it worked. >> It was very much a copy & paste approach. I also was unable to get >> facet chaining (e.g., filter by category and brand at the same >> time...it'd always be one or the other at a time). As such, I've >> commented out 'my' version and have played with the code you have >> supplied to hopefully learn the proper way of doing things. >> >> Let's say I have facets defined as 'category_named' as an attribute. I >> should thus have a conditional check like this, correct? >> >> if params[:category_named] >> @listings = @facets.for(params[:category_named].to_sym => >> params[:category_named_value]) >> >> Presently this returns a Riddle::ResponseError (searchd error (status: >> 1): invalid or truncated request) after clicking one of the facet >> links. The requested parameters in such cases are generally along the >> lines of {"category_named"=>"6", "page"=>"1"}. I have noticed that >> changing ':category_named_value' to just ':category_named' works in >> the sense that my page loads w/o an error, but 0 listings are found. >> >> Is there something else I should be doing? >> >> Thanks! >> TM >> >> On Jul 6, 7:13 pm, Pat Allan <[email protected]> wrote: >> >> >> >>> Not sure where you're at with this - I realise I've been a little slow to >>> respond. >> >>> I guess as a first step, I think you'll need to actually pass the facet >>> name as a param value - so you know what to expect in the controller. ie: >> >>> @facets = Listing.facets(params[:search) >>> if params[:facet] >>> @listings = @facets.for(params[:facet].to_sym => params[:facet_value]) >>> else >>> @listings = Listing.search params[:search], :page => params[:page] >>> end >> >>> I must admit, I've not implemented facets on any of my projects, so this is >>> a little of a grey area for me. I'm sure we can get a solution figured out >>> though (if you've not done so already). >> >>> Cheers >> >>> -- >>> Pat >> >>> On 26/06/2010, at 1:22 PM, TaintedMoowrote: >> >>>> Howdy folks! >> >>>> I'm very new to Thinking Sphinx and am still getting my bearings >>>> around Rails in general. I'm presently trying to implement facets in >>>> my product search. I'm able to search normally and am also able to >>>> display the facets, but clicking on a facet link to try and drill-down >>>> and see the results via a facet filter doesn't seem to actually alter >>>> the search results. Not sure if it helps, but clicking a link in the >>>> browser returns a URL like this: <domain>/listings?category=2&page=1. >>>> As you can see, it looks kinda right, but seems to drop the search >>>> query as well. >> >>>> I've read through the facets page on the docs and while I see how one >>>> can return products via facets in the console, I'm having a real hard >>>> time actually putting the pieces together and implementing in my rails >>>> application. In isolation everything seems fine, just not in practice >>>> as a whole. I apologize for what I assume is a fairly basic >>>> question... What am I missing that would otherwise make facet links >>>> functional (while also maintaining the search query)? >> >>>> Here's a snipped portion of my model: >> >>>> belongs_to :product >>>> define_index do >>>> has product.category(:id), :as => :category, :facet => true >>>> end >> >>>> controller: >> >>>> def index >>>> @listings = Listing.search(params[:search], :with => {}, :page => >>>> params[:page]) >>>> @facets = Listing.facets(params[:search]) >> >>>> View's search btn: >>>> <% form_tag @search, :method => :get do %> >>>> <p> >>>> <%= text_field_tag :search, params[:search] %> >>>> <%= submit_tag "Search", :name => nil %> >>>> </p> >> >>>> View's facet filter: >>>> <% @facets.each do |facet, facet_options| %> >>>> <h5><%= facet %></h5> >>>> <ul> >>>> <% facet_options.each do |option, count| %> >>>> <li><%= link_to "#{option} (#{count})", >>>> :params => {facet => option, :page => 1} %></li> >>>> <% end %> >>>> </ul> >>>> <% end %> >> >>>> For the actual list of products, I'm simply iterating through and >>>> displaying each product in @listings. >> >>>> Thank you! >> >>>> -- >>>> You received this message because you are subscribed to the Google Groups >>>> "Thinking Sphinx" group. >>>> To post to this group, send email to [email protected]. >>>> To unsubscribe from this group, send email to >>>> [email protected]. >>>> For more options, visit this group >>>> athttp://groups.google.com/group/thinking-sphinx?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/thinking-sphinx?hl=en. > -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
