# Implementing search

**URL:** <https://www.ruby-forum.com/t/implementing-search/107713>\
**Category:** Rails\
**Created:** [June 25, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/implementing-search/107713 "2007-06-25T17:11:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arbirk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d26b3c/32.png) [@arbirk](https://www.ruby-forum.com/u/arbirk)\
**Post date:** [June 25, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/implementing-search/107713/1 "2007-06-25T17:11:36Z")

</div>

I am a newbie and have created a small blog-like app. Im have tried to  
implement the saerch function following this tutorial:  
[http://snippets.dzone.com/posts/show/1691](http://snippets.dzone.com/posts/show/1691)

Everything seems to work when the searchphase is empty (it finds the  
454 rows) but as soon as I start typing it returns nothing. Here is  
the controller:

def live\_search

```
@phrase = request.raw_post || request.query_string
a1 = "%"
a2 = "%"
@searchphrase = a1 + @phrase + a2
@results = Funktioner.find(:all, :conditions => [ "Description

```

LIKE ?", @searchphrase])

```
@number_match = @results.length

render(:layout => false)

```

end

The Description-column is text rich and contains the word ledelse, but  
when searched it returns:  
‘ledelse=’ not found!

One of the puzzels is where the equal sign comes from. It appears also  
in the logging og the mysql queries.

Can you help me - anyone?

---

<div class="post-metadata">

**Author:** ![arbirk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d26b3c/32.png) [@arbirk](https://www.ruby-forum.com/u/arbirk)\
**Post date:** [June 25, 2007, 5:22pm UTC](https://www.ruby-forum.com/t/implementing-search/107713/2 "2007-06-25T17:22:19Z")

</div>

What does p @phrase return if you do it prior to the query line  
p @phrase  
@results = Funktioner.find(:all, :conditions =\> [ “Description  
LIKE ?”, @searchphrase])

Also what about  
@searchphrase = “%#{@phrase}%”

arbirk wrote:

> I am a newbie and have created a small blog-like app. Im have tried to  
> implement the saerch function following this tutorial:  
> [http://snippets.dzone.com/posts/show/1691](http://snippets.dzone.com/posts/show/1691)
> 
> Everything seems to work when the searchphase is empty (it finds the  
> 454 rows) but as soon as I start typing it returns nothing. Here is  
> the controller:
> 
> def live\_search
> 
> ```
> @phrase = request.raw_post || request.query_string
> a1 = "%"
> a2 = "%"
> @searchphrase = a1 + @phrase + a2
> @results = Funktioner.find(:all, :conditions => [ "Description
> 
> ```
> 
> LIKE ?", @searchphrase])
> 
> ```
> @number_match = @results.length
> 
> render(:layout => false)
> 
> ```
> 
> end
> 
> The Description-column is text rich and contains the word ledelse, but  
> when searched it returns:  
> ‘ledelse=’ not found!
> 
> One of the puzzels is where the equal sign comes from. It appears also  
> in the logging og the mysql queries.
> 
> Can you help me - anyone?

---

<div class="post-metadata">

**Author:** ![arbirk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d26b3c/32.png) [@arbirk](https://www.ruby-forum.com/u/arbirk)\
**Post date:** [June 25, 2007, 8:18pm UTC](https://www.ruby-forum.com/t/implementing-search/107713/3 "2007-06-25T20:18:20Z")

</div>

arbirk wrote:

> ```
> @phrase = request.raw_post || request.query_string
> 
> ```
> 
> The Description-column is text rich and contains the word ledelse, but  
> when searched it returns:  
> ‘ledelse=’ not found!
> 
> One of the puzzels is where the equal sign comes from. It appears also  
> in the logging og the mysql queries.
> 
> Can you help me - anyone?

I think your problem is that later Prototypes always try to  
encode a key=value query string, which doesn’t work with  
request.raw\_post.

So add the option

:with =\> ‘phrase’

to your observe\_field options, and in your controller have

@phrase = params[:phrase]

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![arbirk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d26b3c/32.png) [@arbirk](https://www.ruby-forum.com/u/arbirk)\
**Post date:** [June 25, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/implementing-search/107713/4 "2007-06-25T20:51:26Z")

</div>

It worked like a charm!

Thanks to both of you for your quick response

Best, David
