Monday, 15 August 2011

mysql - Query part of string or text -



mysql - Query part of string or text -

using rails , mysql. not sure if has been asked, couldn't find it.

i have next records:

1. love rails 2. love django 3. code using ruby on rails

====

(1) search: "i love"

results: "i love rails", "i love django"

====

(2) search: "love"

results: "i love rails", "i love django"

====

(3) search: "ails"

results: "i love rails", "i code using ruby on rails"

====

(4) search: "code ruby"

results: "i code using ruby on rails"

====

my code is:

term = "%#{params[:term]}%" shops = shop.where("name ?", term)

it works on search (1) , (2). how can code accomplish results when doing search (3) , (4) too?

many thanks.

i think need wildcards in there (in raw sql)

like '%ails'

or more generally:

like '%substring%'

mysql ruby-on-rails

No comments:

Post a Comment