Jump to content

FULLTEXT issue


chonk

Recommended Posts

I've been racking my brain all day on this. I've done some searching and have tried a few different things from the forums that don't work. Here's my issue.

 

I create a table:

 

CREATE TABLE `Builders` (

`ID` INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,

`Name` TEXT,

`BizName` TEXT,

FULLTEXT (Name,BizName)

) TYPE = MYISAM ;

 

Populate it with some data:

 

INSERT INTO Builders (Name,BizName) VALUES ('Jeffrey Yonker','Chonk Digital Design');

 

When I query using

SELECT * FROM Builders WHERE MATCH (Name,BizName) AGAINST ('Jeffrey');

I get the first table row returned.

 

However when I query using

SELECT * FROM Builders WHERE MATCH (Name,BizName) AGAINST ('Joe');

I STILL get the first table row returned;

 

Now if I add another column to the table:

INSERT INTO Builders (Name,BizName) VALUES ('Joeseph Bowers','Bowers Construction');

so that there are now 2 entries in the table and I query using

SELECT * FROM Builders WHERE MATCH (Name,BizName) AGAINST ('Jeffrey');

I get an empty set.

 

Any ideas anyone? Thanks in advance.

 

Chonk

Link to comment
Share on other sites

Hi Chonk,

 

This looks like it is a limitation of the FULLTEXT search engine - it is designed for searching and ranking results where the fields contain large chunks of text rather than the 2 or 3 words you're using. In fact, the documentation says that in these situations you may get bizarre results.

 

For a fuller description, see http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html

 

What may be more useful in this situation is to get rid of the Full Text stuff, change the Name and BizName fields to VARCHARs and use the LIKE comparator in your queries instead. Something like:

 

SELECT * FROM Builders WHERE Name LIKE '%Jeffrey%'.

 

This will return only those rows that contain the characters 'Jeffrey' anywhere in the Name field. If you want the same functionality as the FULLTEXT search, ie search across both Name and BizName, you'd have to add another OR clause to the query.

 

It looks like you can also use regular expression searches, but I have never done anything with them. Take a look here:

http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like

 

Hope this points you in the right direction.

Cheers,

Darren.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.