# Live search

**URL:** <https://www.ruby-forum.com/t/live-search/143047>\
**Category:** Rails\
**Created:** [July 14, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/live-search/143047 "2008-07-14T19:50:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 14, 2008, 7:50pm UTC](https://www.ruby-forum.com/t/live-search/143047/1 "2008-07-14T19:50:49Z")

</div>

def get\_results  
if request.xhr?  
if params[‘search\_text’].strip.length \> 0  
terms = params[‘search\_text’].split.collect do |word|  
“%#{word.downcase}%”  
end  
@users = User.find(  
:all,  
:conditions =\> [  
( ["(LOWER(email) LIKE?)"] \* terms.size ).join(" AND "),  
\* terms.flatten  
]  
)  
end  
render :partial =\> “search”  
else  
redirect\_to\_index  
end  
end

I’m not sure how to make the algorithm more accurate.  
If I have this in my database:  
jolt  
two  
tww

and I search for: ‘t’

It brings both of them up because they have have a t in them.

How can I make sure it’s search for the exact letters in sequence,

i.e.

search: ‘t’  
=\> two  
=\> tww

search: ‘two’  
=\> two

Thanks!

results: two
