Re: Newbie question - using sql "Like ''%...." in Find proble

Kian Wright
Wed, 25 Oct 2006 03:05:24 -0000

Alex wrote:
> Hi all,
>
> I''m trying to implement a simple search box:
>
>  @items = Item.find(:all, :conditions => ["description like %?% or
text
> like %?%", @search_text, @search_text])
Try:
@items = Item.find(:all, :conditions => ["description like ? or text
  like ?", "%#{@search_text}%", "%#{@search_text}%"])

Note that putting the % operator in the beginning essentially forces a
full table scan (unless you have some sort of full text indexing
perhaps) and could result in very slow searches.