# Searching - weird behavior with certain letters

**URL:** <https://www.ruby-forum.com/t/searching-weird-behavior-with-certain-letters/150895>\
**Category:** Rails\
**Created:** [October 14, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/searching-weird-behavior-with-certain-letters/150895 "2008-10-14T19:45:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![infinteVerve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@infinteVerve](https://www.ruby-forum.com/u/infinteVerve)\
**Post date:** [October 14, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/searching-weird-behavior-with-certain-letters/150895/1 "2008-10-14T19:45:25Z")

</div>

I could be going about this all wrong but here goes.

I’m using a form to search my posts

The controller has:  
def searchresults  
search\_term = params[‘search’]  
@posts\_search = Post.find(:all, :conditions =\> [“title LIKE ?”,  
“%#{search\_term}%”])  
end

And in the view I have this:  
\<% form\_tag :action =\> ‘searchresults’ do %\>  
\<%= text\_field\_tag :search %\>  
\<%= submit\_tag “Search” %\>  
\<% end %\>

Most terms, even single letters return the expected results. However,  
it seems that whenever the search term contains the letters F or C, no  
results are returned. There may be other letters that do the same,  
but these are the only ones I’ve found so far. Any ideas to why this  
is happening, or how can be fixed?

Many thanks in advance.  
-Mike

---

<div class="post-metadata">

**Author:** ![infinteVerve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@infinteVerve](https://www.ruby-forum.com/u/infinteVerve)\
**Post date:** [October 14, 2008, 7:49pm UTC](https://www.ruby-forum.com/t/searching-weird-behavior-with-certain-letters/150895/2 "2008-10-14T19:49:32Z")

</div>

What does the resulting SQL look like in your log?

---

<div class="post-metadata">

**Author:** ![infinteVerve](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e19adc/32.png) [@infinteVerve](https://www.ruby-forum.com/u/infinteVerve)\
**Post date:** [October 14, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/searching-weird-behavior-with-certain-letters/150895/3 "2008-10-14T20:06:37Z")

</div>

I am so dumb…  
Of course, if there are now titles with the letter C there are no  
results.

I forgot to change :conditions =\> [“title LIKE ?”, “%#{search\_term}  
%”])  
to\>  
:conditions =\> [“post\_body LIKE ? OR title LIKE ?”, “%#{search\_term}  
%”, “%#{search\_term}%”]

Sometimes the answer is too obvious.
