Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

MySQL MATCH.....AGAINST help needed


ghost's Avatar
0 0

Hey all. I am having trouble getting this query to work. I see no problem with it, but it will return 0 rows. This is the first time I have used "MATCH() AGAINST()" before. Let me set this up:

Table: stuff

Rows used (in this example): 'title' - varchar(255) 'desc' - text

Indexes: 'IdxText' - title, desc - FULLTEXT

Row Values:

1 entry: title = "Hello People" desc = "this is a test"

QUERY:

$mysql = mysql_query("SELECT * FROM stuff WHERE MATCH(title,desc) AGAINST('".$keywords."')"wink or die(mysql_error());

Or more obviously:

SELECT * FROM sources WHERE MATCH(title,desc) AGAINST('".$keywords."')

$keywords = inserted string from user

Everything that is entered in for $keywords always returns nothing. If "Hello" is inserted, it returns 0 rows. I get no errors (even through myphpadmin).

If I am seeing this right, it should return the row because it has "Hello People" in the title row and I am searching the title row (and the desc) row for 'Hello'…….no rows are returned.

If it changes anything, I am using MySQL 5.0.45. I have researched this for about half a day, non-stop. I pretty much turn to you guys as my last resort. Why is this returning no rows?


Mr_Cheese's Avatar
0 1

anything you want to MATCH has to be a FULLTEXT.

you have description set as FULLTEXT, so set your title to FULLTEXT too.

give it a quick test and believe that will be the answer to your problems.

also… does mysql_error() return anything?

let me know how you get on.


ghost's Avatar
0 0

The whole index (of both title and description) is FULLTEXT. I tried making 'title' to Text instead of VarChar(255) also and that still doesn't work.

There are absolutely 0 errors. mysql_error() does not return anything and nor does phpMyAdmin.

Any other ideas? This is extremely annoying…

EDIT: I got it. Nevermind. It was the 50% threshold problem. Thanks for trying to help, Mr. Cheese. Much appreciated.