0

Referring to my earlier stackoverflow post I'm trying to look for similarities in messages sent via the following:

SELECT id, MATCH (content) AGAINST (content) AS score FROM pms_messages WHERE sender_id = '.$sender_id.' AND MATCH (content) AGAINST (content) AND score > 1;

I see the error: #1210 - Incorrect arguments to AGAINST

I've set a FULLTEXT index on my content field. From phpmyadmin:

 Edit    Drop   fulltext_index  FULLTEXT    No  No  content 1

What am I missing?

Community
  • 1
  • 1
Paul
  • 11,671
  • 32
  • 91
  • 143

1 Answers1

2

Always read the manual when you get an error message, it's helpful most quickly:

AGAINST takes a string to search for, and an optional modifier that indicates what type of search to perform. The search string must be a literal string, not a variable or a column name.

Ref: http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html#function_match

So what you try to achieve is done wrong. Use a literal string instead of a column name.

See also 11.9.5. Full-Text RestrictionsDocs, specifically:

  • The argument to AGAINST() must be a constant string.
hakre
  • 193,403
  • 52
  • 435
  • 836
  • Should I perform a query prior to get the contents or can this be done with one query? – Paul Feb 15 '12 at 14:48
  • I can't tell you what you *should* do, however I doubt that you can do it with a single query as you need to pass it as a literal string. Probably a [stored procedure](http://dev.mysql.com/doc/refman/5.0/en/stored-routines.html) will save you network roundtrips. I mean you don't want to transfer all the texts back and forth only to get the score value, right? Another hint I can give is to google against your exact error message string. This might turn out some useful results, too (not always, but might offer some ideas). – hakre Feb 15 '12 at 14:50