I''m trying to implement a basic name search on a People table with separate first_name and last_name columns. I am using the will_paginate plugin and have the following search method in the model: def self.search(search, page) paginate :page => page, :conditions => ["lower(last_name) like ? or lower(first_name) like ?", "%#{search.downcase}%", "%#{search.downcase} %"] end This works fine if the query entered is a single word like "Bob" - the last_name field is queried for "Bob" and the first_name field is queried for "Bob". However, if I enter a query like "Bob Dylan", how would I find the record(s) where first_name = "Bob" and last_name = "Dylan"? This seems to be the opposite of "full text search", unless I''m missing some of what is possible with the full text search plugins. I''m new at this - many thanks for any help. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Not tested but mine would look something like :conditions => ["LOWER(CONCAT(first_name,'' '', last_name)) like ?", "% #{search.downcase}%"] kates On Sun, 2007-08-26 at 02:50 -0700, Chris Bartlett wrote:> I''m trying to implement a basic name search on a People table with > separate first_name and last_name columns. I am using the > will_paginate plugin and have the following search method in the > model: > > def self.search(search, page) > paginate :page => page, > :conditions => ["lower(last_name) like ? or > lower(first_name) like ?", "%#{search.downcase}%", "%#{search.downcase} > %"] > end > > This works fine if the query entered is a single word like "Bob" - the > last_name field is queried for "Bob" and the first_name field is > queried for "Bob". > > However, if I enter a query like "Bob Dylan", how would I find the > record(s) where first_name = "Bob" and last_name = "Dylan"? This seems > to be the opposite of "full text search", unless I''m missing some of > what is possible with the full text search plugins. > > I''m new at this - many thanks for any help. > > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks - that is exactly what I needed. I obviously need to brush up on my SQL. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---