# Multi-word query searching across columns

**URL:** <https://www.ruby-forum.com/t/multi-word-query-searching-across-columns/113023>\
**Category:** Rails\
**Created:** [August 26, 2007, 11:51am UTC](https://www.ruby-forum.com/t/multi-word-query-searching-across-columns/113023 "2007-08-26T11:51:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [August 26, 2007, 11:51am UTC](https://www.ruby-forum.com/t/multi-word-query-searching-across-columns/113023/1 "2007-08-26T11:51:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [August 26, 2007, 1:56pm UTC](https://www.ruby-forum.com/t/multi-word-query-searching-across-columns/113023/2 "2007-08-26T13:56:32Z")

</div>

Not tested but mine would look something like

:conditions =\> [“LOWER(CONCAT(first\_name,’ ', last\_name)) like ?”, “%  
#{search.downcase}%”]

kates

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [August 26, 2007, 10:24pm UTC](https://www.ruby-forum.com/t/multi-word-query-searching-across-columns/113023/3 "2007-08-26T22:24:01Z")

</div>

Thanks - that is exactly what I needed. I obviously need to brush up  
on my SQL.
