# Live Search

**URL:** <https://www.ruby-forum.com/t/live-search/143256>\
**Category:** Rails\
**Created:** [July 16, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/live-search/143256 "2008-07-16T20:26:46Z")\
**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 16, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/live-search/143256/1 "2008-07-16T20:26:46Z")

</div>

```
    if params['search_text'].strip.length > 0

   terms = params['search_text'].split.collect do |word|
        "^#{word.downcase}"
      end

    b=[];
      terms.to_s.each_byte { |byte| (b.push(byte.chr) if

```

!b.include?(byte.chr)) if byte.chr.match(/\W+/) }

```
    b.each do |c|
      terms=terms.to_s.gsub(c) { "\\#{c}"}.to_a
    end

      @users = User.find(
        :all,
        :conditions => [
          ( ["(LOWER(email) RLIKE?)"] * terms.size ).join(" AND "),
          * terms.flatten
          ]
      )

```

Hi, I’m trying to implemented a live search that only finds data that is  
prefixed with the user input (i.e. input=\> ‘bo’ -\> output =\> ‘bob’  
‘bot’). Furthermore, I need to be able to accept a variable number of  
special characters. In the middle of my code I replaced special  
characters with ‘’, but I’m not sure how to ESCAPE ‘’ in the SQL at  
the end.

Anyway, if there’s a better way to do this, please let me know!!

Thanks!
