Active record mysql query help


#1

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.


#2

Manish S. 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…