Forum: Ruby on Rails active record mysql query help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F10f95926f620318a71c102f207649b7?d=identicon&s=25 Manish Shah (Guest)
on 2006-03-13 11:43
(Received via mailing list)
I'm trying to do a search function on a mysql text column.  However i'm
running into a problem that i dont know how to get around.

I want to be able to find records that match the text column in some
way.  I
know about doing wildcard searches with % characters but i need to do
this
in a backwards kind of way.  I want to find records that will match some
part (or all) of the input query string.

Example:

- in my db i have the string "textsearchfun" (note all one word) in a
text
column

- the input query is "mysqltextsearchfun" (also all one word)

- output should be the row that stored "textsearchfun"

the string "textsearchfun" matched a piece of the input query string.
The
way i think the wildcard search works is the other way around.  It tries
to
find the records where the input query string matches some or all of the
stored strings.

Anyone know how to do this?

Thanks in advance.
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-03-13 12:04
(Received via mailing list)
Manish Shah wrote:
> I want to be able to find records that match the text column in some
> way.  I know about doing wildcard searches with % characters but i need
> to do this in a backwards kind of way.  I want to find records that will
> match some part (or all) of the input query string.

Untested, but you could try:

SELECT * FROM tablename
   WHERE "#{input_query}"
     LIKE CONCAT('%', text_column, '%');

Likely to be slow as hell, but probably worth a shot...
This topic is locked and can not be replied to.