Hello guys, Having a slight problem with acts_as_ferret, specifically using a condition. I have the following code @results = SupplierProduct.find_by_contents(params [:search], :conditions => [''area_id = ?'', @area]) and it seems the condition isn''t being applied. Does anyone have any pointers? Cheers, Alastair ------ Alastair Moore Standards compliant web development with Ruby On Rails, PHP and ASP www.kozmo.co.uk 07738 399038 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
I''ve had a look through the AAF source and can''t see why this isn''t working. It seems to accept a condition and apply it to the activerecord find but it''s simply not happening. Even if I set a condition that would normally cause an error, the error isn''t occuring so I''m a little stumped here. Would really appreciate any suggestions! Alastair --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Alastair wrote:> I''ve had a look through the AAF source and can''t see why this isn''t > working. It seems to accept a condition and apply it to the > activerecord find but it''s simply not happening. Even if I set a > condition that would normally cause an error, the error isn''t occuring > so I''m a little stumped here. Would really appreciate any suggestions! >Sorry, missed the code I''m working on - @results = SupplierProduct.find_by_contents(params[:search], :conditions => [''area_id = ?'', @area]) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Alastair, Looking at the code for find_by_contents: find_by_contents(q, options = {}, find_options = {}) The parameters are the query itself (string or Ferret query), options (hash) for ferret and find_options (hash) for AR. What you are passing is string and a single hash that is going to the ferret options instead of AR. Try this: @results = SupplierProduct.find_by_contents(params[:search], {}, {:conditions => [''area_id = ?'', @area]}) Besides, the find_options is to include other related objects (eg. {:include => :suplier_category}) and not to filter the results. You need to handle filtering of results through the ferret query or process the results yourself. Hope it helps, Adrian Madrid On 8/25/06, Alastair Moore <alastair-mb+lb5rSoAr10XsdtD+oqA@public.gmane.org> wrote:> > Hello guys, > Having a slight problem with acts_as_ferret, specifically using a > condition. I have the following code > > @results = SupplierProduct.find_by_contents(params[:search], :conditions > => [''area_id = ?'', @area]) > > and it seems the condition isn''t being applied. Does anyone have any > pointers? > > Cheers, > > Alastair > > ------ > Alastair Moore > Standards compliant web development with Ruby On Rails, PHP and ASP > www.kozmo.co.uk > 07738 399038 > > > > > >-- Adrian Esteban Madrid --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 25 Aug 2006, at 19:17, Adrian Madrid wrote:> Alastair, > > Looking at the code for find_by_contents: > > find_by_contents(q, options = {}, find_options = {}) > > The parameters are the query itself (string or Ferret query), > options (hash) for ferret and find_options (hash) for AR. What you > are passing is string and a single hash that is going to the > ferret options instead of AR. Try this: > > @results = SupplierProduct.find_by_contents(params[:search], {}, > {:conditions => [''area_id = ?'', @area]}) > > Besides, the find_options is to include other related objects (eg. > {:include => :suplier_category}) and not to filter the results. You > need to handle filtering of results through the ferret query or > process the results yourself. > > Hope it helps,Hi Adrian, Many thanks for the help. I was thinking it was a reasonable thing to do of using the activerecord "condition" to further filter a search. Is there a reason I shouldn''t use this approach? Essentially I''ve got a couple of drop down menus (for area and category), which I was going to set in the condition and then a free text search for anything more specific. Is this not the best way of going about it? Thanks again, Alastair ------ Alastair Moore Standards compliant web development with Ruby On Rails, PHP and ASP www.kozmo.co.uk 07738 399038 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Alastair, The problem with your approach is that it doesn''t work with how acts_as_ferret (AAF) works. What AAF does is first gets ids of records matching your query and then goes one by one doing ModelXyz.find n (n being the id) with the find options you sent grouping all those results into an array and returning it. So, you can try using your conditions but it might break or return an array with some empty slots. In my case I had some requirements that made me do my own find_by_contents (I named it ferret_find) based on find_by_contents. That way I learned exactly how it works and adapted it for my needs. Hope it helps, Adrian Madrid On 8/25/06, Alastair Moore <alastair-mb+lb5rSoAr10XsdtD+oqA@public.gmane.org> wrote:> > > On 25 Aug 2006, at 19:17, Adrian Madrid wrote: > > Alastair, > > Looking at the code for find_by_contents: > > find_by_contents(q, options = {}, find_options = {}) > > The parameters are the query itself (string or Ferret query), options > (hash) for ferret and find_options (hash) for AR. What you are passing is > string and a single hash that is going to the ferret options instead of AR. > Try this: > > @results = SupplierProduct.find_by_contents(params[:search], {}, > {:conditions => [''area_id = ?'', @area]}) > > Besides, the find_options is to include other related objects (eg. > {:include => :suplier_category}) and not to filter the results. You need to > handle filtering of results through the ferret query or process the results > yourself. > > Hope it helps, > > > Hi Adrian, > > Many thanks for the help. I was thinking it was a reasonable thing to do > of using the activerecord "condition" to further filter a search. Is there a > reason I shouldn''t use this approach? Essentially I''ve got a couple of drop > down menus (for area and category), which I was going to set in the > condition and then a free text search for anything more specific. Is this > not the best way of going about it? > > Thanks again, > > Alastair > > ------ > Alastair Moore > Standards compliant web development with Ruby On Rails, PHP and ASP > www.kozmo.co.uk > 07738 399038 > > > > > >-- Adrian Esteban Madrid --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 25 Aug 2006, at 21:31, Adrian Madrid wrote:> Alastair, > > The problem with your approach is that it doesn''t work with how > acts_as_ferret (AAF) works. What AAF does is first gets ids of > records matching your query and then goes one by one doing > ModelXyz.find n (n being the id) with the find options you sent > grouping all those results into an array and returning it. So, you > can try using your conditions but it might break or return an array > with some empty slots. In my case I had some requirements that made > me do my own find_by_contents (I named it ferret_find) based on > find_by_contents. That way I learned exactly how it works and > adapted it for my needs. > > Hope it helps,Hi Adrian, Thanks for the tips, I''ve gone down a "filter afterwards" route which is working nicely now. Cheers, Alastair ------ Alastair Moore Standards compliant web development with Ruby On Rails, PHP and ASP www.kozmo.co.uk 07738 399038 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Alastair, Glad to help. Sincerely, Adrian Madrid On 8/25/06, Alastair Moore <alastair-mb+lb5rSoAr10XsdtD+oqA@public.gmane.org> wrote:> > > On 25 Aug 2006, at 21:31, Adrian Madrid wrote: > > Alastair, > > > The problem with your approach is that it doesn''t work with how > acts_as_ferret (AAF) works. What AAF does is first gets ids of records > matching your query and then goes one by one doing ModelXyz.find n (n > being the id) with the find options you sent grouping all those results into > an array and returning it. So, you can try using your conditions but it > might break or return an array with some empty slots. In my case I had some > requirements that made me do my own find_by_contents (I named it > ferret_find) based on find_by_contents. That way I learned exactly how it > works and adapted it for my needs. > > > Hope it helps, > > > Hi Adrian, > > Thanks for the tips, I''ve gone down a "filter afterwards" route which is > working nicely now. > > Cheers, > > Alastair > > ------ > Alastair Moore > Standards compliant web development with Ruby On Rails, PHP and ASP > www.kozmo.co.uk > 07738 399038 > > > > > >-- Adrian Esteban Madrid --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---