For most cases, I've got search working in Rails as follows:
## controller:
term = params[:search][:term]
@results = MyModel.find_by_contents "#{term}*"
The '*' character is appended to the search term so that searches match
anything that begins with 'term'. For the most part, this is great, but
let's say term is equal to "Title: Some subtitle". This will match anything
that has a 'title' attribute equal to "some subtitle", instead of any
attribute equal to "Title: Some subtitle", which is what I'm hoping for.
If I run my search from within a double-quotes expression, like
MyModel.find_by_contents "'\"#{term}*\"'", then it looks like I can get
matches for "Title: Some subtitle", but I can't get matches if I search for
"Titl" without the 'e', presumably because the '*' is escaped as well? I'm
not quite sure.
I want something that works in all cases, where I can include a search term
that has a special character, but still get matches when my search term
isn't equal to an entire word. I'm hoping that my situation is a typical
one, and that someone out there has already dealt with this? Thanks very
much for any advice.
Liam Morley
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk